1
0

locallib.php 366 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855
  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. 'get_student_submission' => '$this->get_student_submission();',
  279. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  280. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  281. );
  282. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  283. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  284. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  285. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  286. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  287. }
  288. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  289. eval($action_iassign_limit[$this->action]);
  290. }
  291. else { // Student reaches this point
  292. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  293. // Arrive here with: "get_answer"; "view"
  294. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  295. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  296. }
  297. } // function action()
  298. /// This method prints the student submission to a specific exercise
  299. function get_student_submission () {
  300. global $DB;
  301. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  302. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  303. if (!$student || !$exercise) exit;
  304. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  305. if ($iassign_submission)
  306. print($iassign_submission->answer);
  307. die();
  308. }
  309. /// This method prints the teacher exercise
  310. function get_teacher_exercise () {
  311. global $DB, $COURSE;
  312. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  313. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  314. $fs = get_file_storage(); // Get reference to all files in Moodle data
  315. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  316. foreach ($files as $file) {
  317. if ($file->get_filename() != ".") {
  318. print($file->get_content());
  319. }
  320. }
  321. die();
  322. }
  323. /// This method receives the data from auto_eval event
  324. /// @see auto_evaluate()
  325. function post_auto_eval_result () {
  326. global $COURSE, $CFG, $USER, $DB;
  327. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  328. exit;
  329. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  330. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  331. $student = optional_param('student', -1, PARAM_INT);
  332. $grade = optional_param('grade', 0, PARAM_FLOAT);
  333. // 1: Recuperar a nota atual:
  334. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  335. // 2: Atualizar a tabela:
  336. $update_entry = new stdClass();
  337. $update_entry->id = $actual->id;
  338. $update_entry->previous_grade = $actual->grade;
  339. $update_entry->grade = $grade;
  340. // Update the iassign_submission
  341. $DB->update_record("iassign_submission", $update_entry);
  342. }
  343. /// Manage all submissions in exercises to table iassign_allsubmissions
  344. function all_submissions () {
  345. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  346. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  347. exit;
  348. print $OUTPUT->header();
  349. print '<h2>' . get_string('all_submissions_manager', 'iassign') . '</h2>';
  350. // Get list of exercises in the instance:
  351. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  352. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  353. // Get list of enrolled students:
  354. $params = array('shortname' => 'student');
  355. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  356. $context = context_course::instance($this->course->id);
  357. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  358. $students_list = $DB->get_records_sql(
  359. "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);
  360. print '<div class="list-group list-group-root">';
  361. foreach ($exercises_list as $exercise) {
  362. print '
  363. <a href="#item-'.$exercise->id.'" class="list-group-item list-group-item-action" data-toggle="collapse">
  364. <i class="fa fa-caret-right"></i> '
  365. . $exercise->name . '</a>';
  366. print '<div class="list-group collapse" id="item-'.$exercise->id.'">';
  367. foreach ($students_list as $student) {
  368. print '<a href="#item-'.$exercise->id.'-'.$student->userid.'" class="list-group-item list-group-item-action" data-toggle="collapse">
  369. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname . ' </a>';
  370. print '<div class="list-group collapse" id="item-'.$exercise->id.'-'.$student->userid.'">';
  371. print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  372. print '</div>';
  373. }
  374. print '</div>';
  375. }
  376. print '</div>';
  377. print $OUTPUT->footer();
  378. }
  379. /// This method runs activities auto evaluation in teacher area
  380. function auto_evaluate () {
  381. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  382. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  383. exit;
  384. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  385. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  386. // Get list of exercises in the instance:
  387. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  388. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  389. // Get list of enrolled students:
  390. $params = array('shortname' => 'student');
  391. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  392. $context = context_course::instance($this->course->id);
  393. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  394. $students_list = $DB->get_records_sql(
  395. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  396. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  397. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  398. print $OUTPUT->header();
  399. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  400. print '<ul style="list-style-type: none; margin: 1em;">';
  401. foreach ($exercises_list as $exercise) {
  402. $matches = [];
  403. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  404. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  405. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  406. if ($matches[0][0]) {
  407. 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>';
  408. } else {
  409. 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>';
  410. }
  411. } else {
  412. if ($matches[0][0]) {
  413. 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>';
  414. } else {
  415. 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>';
  416. }
  417. }
  418. }
  419. print '</ul>
  420. <center>
  421. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  422. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  423. <div id="evaluate_message" style="color: red"></div>
  424. <div id="evaluate_alerts"></div>
  425. <div>
  426. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  427. <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>
  428. </div>
  429. </center>'; // close "
  430. print ' </div>' + "\n";
  431. print ' <script>';
  432. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  433. print ' var submissions = [';
  434. // Get list of student id have submit for each exercise:
  435. foreach ($exercises_list as $exercise) {
  436. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  437. print '
  438. {
  439. "exerciseid": "' . $exercise->id . '",
  440. "grade": ' . $exercise->grade . ',
  441. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  442. "submited": ['; // "
  443. $params = array('iassign_statementid' => $exercise->id);
  444. $submited = $DB->get_records_sql( // Get userid and his grade
  445. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  446. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  447. foreach ($submited as $ss) {
  448. print($ss->userid . ',');
  449. }
  450. print '],';
  451. print '"allgrades": [';
  452. foreach ($submited as $ss) {
  453. print( $ss->grade . ',');
  454. }
  455. print ']
  456. },'; // close "
  457. } // foreach ($exercises_list as $exercise)
  458. print " ];\n";
  459. print '
  460. var total_submissions = 0;
  461. var selected_exercises;
  462. var count_steps;
  463. var value_by_step;
  464. var stoped = false;
  465. var time_interval = 5000;
  466. var var_interval;
  467. function add_hover_th (id_th, id_li) {
  468. $("#" + id_th).hover(function() {
  469. $("#" + id_li).css("background-color", "#d9d8d8");
  470. $(this).css("background-color", "#d9d8d8");
  471. }, function() {
  472. $("#" + id_li).css("background-color", "");
  473. $(this).css("background-color", "");
  474. });
  475. }
  476. function start_evaluation () {
  477. stoped = false;
  478. $("#progress_bar").css("display", "none");
  479. $("#evaluate_message").text("");
  480. $("#evaluate_alerts").text("");
  481. $(".added-col").remove();
  482. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  483. selected_exercises = [];
  484. var c = 0;
  485. for (var i = 0; i < exercises.length; i++) {
  486. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  487. selected_exercises[c++] = exercises[i];
  488. }
  489. }
  490. if (selected_exercises.length == 0) {
  491. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  492. return;
  493. } else {
  494. $("input:checkbox").attr("disabled", true);
  495. for (var i = 0; i < selected_exercises.length; i++) {
  496. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  497. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  498. $("#table-results tbody tr").each(function(e) {
  499. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  500. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  501. });
  502. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  503. }
  504. $("#button_start").prop("disabled", true);
  505. $("#button_stop").prop("disabled", false);
  506. $("#progress_bar").css("display", "block");
  507. }
  508. total_submissions = selected_exercises.length * students.length;
  509. count_steps = 0;
  510. value_by_step = 100/total_submissions;
  511. actual_exercise = 0;
  512. actual_student = 0;
  513. actual_submission = 0;
  514. get_original_propositions();
  515. var_interval = setInterval(verifyBreak, time_interval);
  516. } // function start_evaluation()
  517. var actual_exercise;
  518. var actual_student;
  519. var actual_submission;
  520. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  521. function run_individual_evaluation () {
  522. if (stoped) return;
  523. // Verify if student really sent his answer
  524. var found = false;
  525. for (var j = 0; j < submissions.length; j++) {
  526. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  527. for (var k = 0; k < submissions[j].submited.length; k++) {
  528. if (students[actual_student] == submissions[j].submited[k]) {
  529. found = true;
  530. break;
  531. }
  532. }
  533. break;
  534. }
  535. }
  536. if (found == false) {
  537. postResultAutoEval();
  538. } else {
  539. // If it was sent, search it...
  540. var final_url = "";
  541. 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];
  542. for (var j = 0; j < submissions.length; j++) {
  543. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  544. final_url = submissions[j].ilm;
  545. break;
  546. }
  547. }
  548. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  549. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  550. window.frames["ifrm"].location=final_url;
  551. }
  552. } // function run_individual_evaluation()
  553. var break_student = -1;
  554. var break_exercise = -1;
  555. function verifyBreak () {
  556. if (actual_student == break_student && actual_exercise == break_exercise) {
  557. postResultAutoEval(-6);
  558. break_student = -1;
  559. break_exercise = -1;
  560. return;
  561. } else {
  562. break_student = actual_student;
  563. break_exercise = actual_exercise;
  564. }
  565. }
  566. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  567. function getStudentAnswerURL () {
  568. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  569. }
  570. // This function is called by the iLM!!!
  571. function getAutoEvalOriginalData () {
  572. return original_propositions[actual_exercise];
  573. }
  574. function updateProgressBar () {
  575. if (stoped) return;
  576. var temp = (count_steps * value_by_step)|0;
  577. count_steps ++;
  578. temp = temp > 100 ? 100 : temp;
  579. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  580. if (temp >= 100) {
  581. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  582. $("#button_start").prop("disabled", false);
  583. $("#button_stop").prop("disabled", true);
  584. $("input:checkbox").attr("disabled", false);
  585. clearInterval(var_interval);
  586. }
  587. }
  588. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  589. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  590. function postResultAutoEval (grade = null) {
  591. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  592. if (grade == null) {
  593. $("#"+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>\');
  594. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  595. } else {
  596. // Verify if the re-evaluation grade is the of that one registered:
  597. var actual_value = 0;
  598. var actual_student_grade = 0;
  599. for (var k = 0; k < submissions.length; k++) {
  600. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  601. actual_value = submissions[k].grade;
  602. for (var h = 0; h < submissions[k].submited.length; h++) {
  603. if (submissions[k].submited[h] == students[actual_student]) {
  604. actual_student_grade = submissions[k].allgrades[h];
  605. break;
  606. }
  607. }
  608. break;
  609. }
  610. }
  611. // @FeedbackConvention
  612. if (grade < 0) {
  613. switch (grade) {
  614. case -1:
  615. // Test-cases are empty:
  616. $("#"+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>\');
  617. var mm = actual_exercise;
  618. $("#"+id_t).find(".details-button").click(function(e) {
  619. $(".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>\');
  620. });
  621. break;
  622. case -2:
  623. // Test-cases were manually altered by the student (fraud!):
  624. $("#"+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>\');
  625. var mm = actual_exercise;
  626. $("#"+id_t).find(".details-button").click(function(e) {
  627. $(".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>");
  628. });
  629. $.ajax({
  630. dataType: "html",
  631. 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",
  632. success: function(d) {}
  633. });
  634. break;
  635. case -5:
  636. // Execution failed:
  637. $("#"+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>\');
  638. var mm = actual_exercise;
  639. $("#"+id_t).find(".details-button").click(function(e) {
  640. $(".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>\');
  641. });
  642. break;
  643. case -6: // iLM not answering was detected in "verifyBreak()"
  644. // The iLM are not answering:
  645. $("#"+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>\');
  646. $("#"+id_t).find(".details-button").click(function(e) {
  647. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  648. });
  649. break;
  650. }
  651. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  652. } else {
  653. console.log((grade), (actual_student_grade));
  654. if ((grade) == (actual_student_grade)) {
  655. $("#"+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>\');
  656. } else { // Notas diferem:
  657. $("#"+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>\');
  658. var mm = actual_exercise;
  659. $("#"+id_t).find(".details-button").click(function(e) {
  660. $(".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>\');
  661. });
  662. // Send to the endpoint the post_auto_eval_result to verify:
  663. $.ajax({
  664. dataType: "html",
  665. 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),
  666. success: function(d) {}
  667. });
  668. }
  669. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  670. }
  671. }
  672. updateProgressBar();
  673. // Does it must continue in the same exercise or stop?
  674. if (actual_student < students.length) {
  675. actual_student ++;
  676. run_individual_evaluation();
  677. } else {
  678. actual_student = 0;
  679. // Does it go to next exercise or is it finished?
  680. if (actual_exercise < selected_exercises.length) {
  681. actual_exercise++;
  682. run_individual_evaluation();
  683. } else {
  684. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  685. }
  686. }
  687. }
  688. var original_propositions;
  689. function get_original_propositions () {
  690. original_propositions = [];
  691. var count = 0;
  692. for (var i = 0; i < exercises.length; i++) {
  693. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  694. $.ajax({
  695. dataType: "html",
  696. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  697. success: function(d) { // variable "d" has the iLM content
  698. original_propositions[count] = d; // exercise original content
  699. count ++;
  700. if (count == selected_exercises.length) {
  701. run_individual_evaluation();
  702. }
  703. }
  704. });
  705. }
  706. }
  707. }
  708. function stop_evaluation () {
  709. stoped = true;
  710. $("#button_start").prop("disabled", false);
  711. $("#button_stop").prop("disabled", true);
  712. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  713. $("input:checkbox").attr("disabled", false);
  714. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  715. clearInterval(var_interval);
  716. }
  717. var exercises = [ '; // '
  718. foreach ($exercises_list as $exercise) {
  719. print $exercise->id . ',';
  720. }
  721. print ' ];';
  722. print ' var students = [ ';
  723. foreach ($students_list as $student) {
  724. print $student->userid . ',';
  725. }
  726. print '];';
  727. print ' var ilms = [';
  728. foreach ($exercises_list as $exercise) {
  729. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  730. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  731. }
  732. print ']';
  733. print '</script>';
  734. print '
  735. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  736. <div class="modal-dialog modal-dialog-centered" role="document">
  737. <div class="modal-content">
  738. <div class="modal-header">
  739. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  740. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  741. <span aria-hidden="true">&times;</span>
  742. </button>
  743. </div>
  744. <div class="modal-body">
  745. ...
  746. </div>
  747. <div class="modal-footer">
  748. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  749. </div>
  750. </div>
  751. </div>
  752. </div>'; //
  753. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  754. print '<table id="table-results" class="table table-hover m-t-1">
  755. <thead>
  756. <tr id="cols-exercises">
  757. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  758. </tr>
  759. </thead>
  760. <tbody>'; // "
  761. foreach ($students_list as $student) {
  762. $user = $DB->get_record('user', array('id' => $student->userid));
  763. $avatar = new user_picture($user);
  764. $avatar->courseid = $COURSE->id;
  765. $avatar->link = true;
  766. print
  767. '<tr data-student="'.$student->userid.'">
  768. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  769. </tr>'; // "
  770. }
  771. print '</tbody>
  772. </table>'; // "
  773. print $OUTPUT->footer();
  774. } // function auto_evaluate()
  775. /// This method moves an iAssign activity
  776. function move_activity () {
  777. global $USER, $CFG, $DB, $COURSE;
  778. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  779. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  780. $update_entry_new_iassign = new stdClass();
  781. $update_entry_new_iassign->id = $iassign_id;
  782. $update_entry_new_iassign->iassignid = $iassign_destiny;
  783. // Update the iassign_statement
  784. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  785. // Update file context
  786. $c_i = context_module::instance($this->cm->id);
  787. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  788. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  789. $path_module = context_course::instance($COURSE->id);
  790. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  791. if ($context_file) {
  792. $id_context = $context_file->id;
  793. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  794. $fs = get_file_storage(); // Get reference to all files in Moodle data
  795. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  796. foreach ($files as $value) {
  797. if ($value->get_filename() != ".") {
  798. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  799. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  800. $updateentry = new stdClass();
  801. $updateentry->id = $iassign_id;
  802. $updateentry->file = $newfile->get_itemid();
  803. $DB->update_record("iassign_statement", $updateentry);
  804. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  805. break;
  806. }
  807. }
  808. }
  809. $this->return_home_course('moved_activity');
  810. exit;
  811. }
  812. /// This method duplicates an iAssign activity
  813. function duplicate_activity () {
  814. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  815. $id = $this->cm->id;
  816. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  817. $context = context_module::instance($this->cm->id);
  818. $contextuser = context_user::instance($USER->id);
  819. // Get the the iAssign acitivity to be duplicated
  820. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  821. // Remove the current id of activity
  822. $iassign_statement->id=0;
  823. // Get the information about current author, and add this information in author_modified field
  824. $author = $DB->get_record("user", array('id' => $USER->id));
  825. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  826. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  827. // Store the activity in the table
  828. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  829. // Duplicate activity file
  830. $fs = get_file_storage(); // Get reference to all files in Moodle data
  831. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  832. foreach ($files as $value) {
  833. if ($value->get_filename() != ".") {
  834. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  835. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  836. $updateentry = new stdClass();
  837. $updateentry->id = $id_;
  838. $updateentry->file = $newfile->get_itemid();
  839. // Update the duplicated iLM iAssign with new file id
  840. $DB->update_record("iassign_statement", $updateentry);
  841. }
  842. }
  843. }
  844. // log event --------------------------------------------------------------------------------------
  845. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  846. $this->return_home_course('duplicated_activity');
  847. exit;
  848. }
  849. // / This method gets the content from comment and register it
  850. function add_comment () {
  851. global $USER, $DB;
  852. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  853. $comment = false;
  854. if ($submission_comment)
  855. $comment = $this->write_comment_submission();
  856. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  857. if (!$id_submission) {
  858. $iassign_submission =
  859. $DB->get_record("iassign_submission",
  860. array(
  861. "iassign_statementid" => $this->activity->get_activity()->id,
  862. "userid" => $USER->id
  863. )
  864. );
  865. if ($iassign_submission) {
  866. $id_submission = $iassign_submission->id;
  867. }
  868. }
  869. echo $this->search_comment_submission($id_submission);
  870. }
  871. /// This method gets the content from the iLM and register it
  872. // It could be the "exercise template" (teacher) or an answer (student)
  873. function get_answer () {
  874. global $USER, $CFG, $DB, $OUTPUT;
  875. $id = $this->cm->id;
  876. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  877. $comment = false;
  878. if ($submission_comment)
  879. $comment = $this->write_comment_submission();
  880. // receives data of iLM using the current activity
  881. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  882. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  883. // receives data of submission of current activity
  884. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  885. // receives post and get
  886. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  887. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  888. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  889. $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)
  890. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  891. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  892. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  893. $msg = '';
  894. if ($this->activity->get_activity()->store_all_submissions == 1) {
  895. $newentry = new stdClass();
  896. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  897. $newentry->userid = $this->userid_iassign;
  898. $newentry->timecreated = time();
  899. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  900. $newentry->answer = $iLM_PARAM_ArchiveContent;
  901. $DB->insert_record("iassign_allsubmissions", $newentry);
  902. }
  903. // Feedback
  904. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  905. $str_action = "view"; // repeat
  906. if (strtolower($iassign_ilm->name) == "igeom") {
  907. }
  908. $title = get_string('evaluate_iassign', 'iassign');
  909. print $OUTPUT->header();
  910. print $OUTPUT->box_start();
  911. // Action = { view ; repeat ; viewsubmission }
  912. // * '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")
  913. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  914. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  915. $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;
  916. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  917. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  918. print '<table width=100% >';
  919. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  920. //TODO alterar aqui???
  921. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  922. // empty_answer_post = No solution was posted.
  923. if ($comment)
  924. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  925. else
  926. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  927. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  928. } else {
  929. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  930. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  931. // Correct answer!!
  932. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  933. $this->write_solution = 1; //
  934. $status = 3;
  935. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  936. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  937. // log record
  938. $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;
  939. // Trigger module viewed event.
  940. $event = \mod_iassign\event\submission_created::create(array(
  941. 'objectid' => $this->iassign->id,
  942. 'context' => $this->context,
  943. 'other' => $info
  944. ));
  945. $event->add_record_snapshot('course', $this->course);
  946. $event->trigger();
  947. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  948. // Wrong answer...: get_answer_incorrect
  949. $status = 2;
  950. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  951. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  952. // log record
  953. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  954. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  955. // Trigger module viewed event.
  956. $event = \mod_iassign\event\submission_created::create(array(
  957. 'objectid' => $this->iassign->id,
  958. 'context' => $this->context,
  959. 'other' => $info
  960. ));
  961. $event->add_record_snapshot('course', $this->course);
  962. $event->trigger();
  963. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  964. // Presents to the learner the result of the automatic evaluate?
  965. if ($this->activity->get_activity()->show_answer == 0) { // no...
  966. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  967. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  968. print '<tr>';
  969. // log record
  970. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  971. // Trigger module viewed event.
  972. $event = \mod_iassign\event\submission_created::create(array(
  973. 'objectid' => $this->iassign->id,
  974. 'context' => $this->context,
  975. 'other' => $info
  976. ));
  977. $event->add_record_snapshot('course', $this->course);
  978. $event->trigger();
  979. } else { // yes!!!
  980. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  981. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  982. print '<tr>';
  983. print $msg;
  984. }
  985. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  986. $status = 1;
  987. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  988. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  989. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  990. print '<tr>';
  991. // log record
  992. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  993. $event = \mod_iassign\event\submission_created::create(array(
  994. 'objectid' => $this->iassign->id,
  995. 'context' => $this->context,
  996. 'other' => $info
  997. ));
  998. $event->add_record_snapshot('course', $this->course);
  999. $event->trigger();
  1000. } // if ($iassign_ilm->evaluate == 1)
  1001. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1002. print '</tr></table>';
  1003. print $OUTPUT->box_end();
  1004. // add or update evaluate
  1005. if ($this->write_solution == 1) {
  1006. $timenow = time();
  1007. // new record
  1008. if (!$iassign_submission) {
  1009. $newentry = new stdClass();
  1010. $newentry->userid = $this->userid_iassign;
  1011. // $newentry->userid = $USER->id;
  1012. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1013. $newentry->timecreated = $timenow;
  1014. $newentry->timemodified = $timenow;
  1015. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1016. $newentry->grade = round($grade_student, 2);
  1017. $newentry->status = $status;
  1018. $newentry->experiment = 1;
  1019. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1020. print_error('error_insert', 'iassign');
  1021. } else {
  1022. // Trigger module viewed event.
  1023. $event = \mod_iassign\event\submission_created::create(array(
  1024. 'objectid' => $this->iassign->id,
  1025. 'context' => $this->context
  1026. ));
  1027. $event->add_record_snapshot('course', $this->course);
  1028. $event->trigger();
  1029. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1030. }
  1031. } elseif ($iassign_submission->status != 3) {
  1032. $newentry = new stdClass();
  1033. $newentry->id = $iassign_submission->id;
  1034. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1035. $newentry->userid = $iassign_submission->userid;
  1036. $newentry->timecreated = $iassign_submission->timecreated;
  1037. $newentry->timemodified = $timenow;
  1038. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1039. $newentry->grade = round($grade_student, 2);
  1040. $newentry->status = $status;
  1041. $newentry->experiment = $iassign_submission->experiment + 1;
  1042. if (!$DB->update_record("iassign_submission", $newentry)) {
  1043. print_error('error_update', 'iassign');
  1044. //D depurar...
  1045. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1046. //D $fp = fopen("teste1.txt","w");
  1047. //D fwrite($fp,$stringAux);
  1048. } else {
  1049. // Trigger module viewed event.
  1050. $event = \mod_iassign\event\submission_updated::create(array(
  1051. 'objectid' => $this->iassign->id,
  1052. 'context' => $this->context
  1053. ));
  1054. $event->add_record_snapshot('course', $this->course);
  1055. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1056. }
  1057. } else {
  1058. if ($return_get_answer == 1) {
  1059. $newentry = new stdClass();
  1060. $newentry->id = $iassign_submission->id;
  1061. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1062. $newentry->userid = $iassign_submission->userid;
  1063. $newentry->timecreated = $iassign_submission->timecreated;
  1064. $newentry->timemodified = $timenow;
  1065. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1066. $newentry->grade = round($grade_student, 2);
  1067. $newentry->status = $status;
  1068. $newentry->experiment = $iassign_submission->experiment + 1;
  1069. if (!$DB->update_record("iassign_submission", $newentry))
  1070. print_error('error_update', 'iassign');
  1071. else {
  1072. $event = \mod_iassign\event\submission_updated::create(array(
  1073. 'objectid' => $this->iassign->id,
  1074. 'context' => $this->context
  1075. ));
  1076. $event->add_record_snapshot('course', $this->course);
  1077. $event->trigger();
  1078. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1079. print $OUTPUT->box_start();
  1080. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1081. print $OUTPUT->box_end();
  1082. }
  1083. } elseif ($return_get_answer == 2) {
  1084. print $OUTPUT->box_start();
  1085. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1086. print $OUTPUT->box_end();
  1087. } else {
  1088. print $OUTPUT->box_start();
  1089. print "
  1090. <script type='text/javascript'>
  1091. //<![CDATA[
  1092. function overwrite () {
  1093. document.formEnvio.return_get_answer.value = 1;
  1094. document.formEnvio.submit();
  1095. }
  1096. function nooverwrite () {
  1097. document.formEnvio.return_get_answer.value = 2;
  1098. document.formEnvio.submit();
  1099. }
  1100. //]]>
  1101. </script>";
  1102. $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;
  1103. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1104. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1105. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1106. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1107. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1108. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1109. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1110. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1111. <input type='hidden' name='return_get_answer'/> ";
  1112. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1113. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1114. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1115. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1116. print " </form>";
  1117. print $OUTPUT->box_end();
  1118. }
  1119. }
  1120. } // if ($this->write_solution == 1)
  1121. print $OUTPUT->footer();
  1122. die();
  1123. } // function get_answer()
  1124. /// Export in file the answer of student.
  1125. function export_file_answer () {
  1126. global $DB;
  1127. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1128. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1129. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1130. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1131. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1132. $extensions = explode(",", $iassign_ilm->extension);
  1133. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1134. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1135. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1136. header("Pragma: public");
  1137. header("Expires: 0");
  1138. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1139. header("Cache-Control: private", false);
  1140. header("Content-Type: document/unknown");
  1141. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1142. set_time_limit(0);
  1143. print($iassign_submission->answer);
  1144. exit;
  1145. } // function export_file_answer()
  1146. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1147. // @calledby $this->export_package_answer()
  1148. //TODO Precisa terminar! //TODO_HTML
  1149. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1150. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1151. <head>
  1152. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1153. $str_html .= " </head>
  1154. <body>\n";
  1155. $tam = sizeof($array_iassign_name);
  1156. for ($ii=0; $ii<$tam; $ii++) {
  1157. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1158. }
  1159. $str_html .= "
  1160. </body>\n</html>";
  1161. return $str_html;
  1162. }
  1163. /// Export an package (zip) with all answer of students
  1164. // @calledby $this->action()
  1165. function export_package_answer () {
  1166. global $DB, $CFG, $OUTPUT;
  1167. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1168. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1169. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1170. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1171. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1172. $userid = optional_param('userid', NULL, PARAM_INT);
  1173. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1174. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1175. //TODO_HTML echo "username=$username<br/>"; exit;
  1176. $current_date = date('Y_m_d_H');
  1177. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1178. // If temporary directory under Moodle data does not exists => create it
  1179. if (!is_dir($diretorio)) {
  1180. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1181. // created directory with permissions to be seen by everyone
  1182. }
  1183. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1184. if (!is_writable($diretorio)) { // send a highlighted message!
  1185. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1186. exit; // just in case
  1187. }
  1188. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1189. $zip = new zip_archive(); // create ZIP
  1190. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1191. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1192. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1193. $vet_student_filename = array();
  1194. $vet_student_content = array();
  1195. foreach ($iassign_statements as $iassign_statement) {
  1196. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1197. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1198. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1199. $extensions = explode(",", $iassign_ilm->extension);
  1200. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1201. if ($iassign_submission) {
  1202. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1203. $student_content = $iassign_submission->answer;
  1204. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1205. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1206. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1207. if ($resp) {
  1208. $vet_student_filename[] = $student_filename;
  1209. $vet_student_content[] = $student_content;
  1210. }
  1211. else { // send a highlighted message!
  1212. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1213. exit; // just in case
  1214. }
  1215. }
  1216. }
  1217. $zip->close(); // close the ZIP file
  1218. if (count($vet_student_filename)>0) {
  1219. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1220. $result_tf = $vet_result[0];
  1221. $filenameZip = $vet_result[1]->filename;
  1222. }
  1223. iassign_utils::download_file($zip_filename); // download the ZIP file
  1224. exit;
  1225. } // function export_package_answer()
  1226. /// Editing status of interactive activities
  1227. function edit_status () {
  1228. global $USER, $DB, $OUTPUT;
  1229. $newentry = new stdClass();
  1230. $newentry->id = $this->iassign_submission_current;
  1231. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1232. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1233. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1234. $newentry->status = $iassign_submission->status;
  1235. $newentry->teacher = $USER->id;
  1236. if (!$DB->update_record('iassign_submission', $newentry))
  1237. print_error('error_update', 'iassign');
  1238. else {
  1239. // Trigger module viewed event.
  1240. $event = \mod_iassign\event\submission_updated::create(array(
  1241. 'objectid' => $this->iassign->id,
  1242. 'context' => $this->context
  1243. ));
  1244. $event->add_record_snapshot('course', $this->course);
  1245. $event->trigger();
  1246. $this->action = 'viewsubmission';
  1247. $this->view_iassign_current();
  1248. } // if (!$DB->update_record('iassign_submission', $newentry))
  1249. } // function edit_status()
  1250. /// Editing grade of interactive activities
  1251. function edit_grade () {
  1252. global $USER, $DB, $OUTPUT;
  1253. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1254. if ($newgrade && $newgrade >= 0) {
  1255. $newentry = new stdClass();
  1256. $newentry->id = $this->iassign_submission_current;
  1257. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1258. $newentry->teacher = $USER->id;
  1259. if (!$DB->update_record('iassign_submission', $newentry))
  1260. print_error('error_update', 'iassign');
  1261. else {
  1262. // Trigger module viewed event.
  1263. $event = \mod_iassign\event\submission_updated::create(array(
  1264. 'objectid' => $this->iassign->id,
  1265. 'context' => $this->context
  1266. ));
  1267. $event->add_record_snapshot('course', $this->course);
  1268. $event->trigger();
  1269. }
  1270. } // if ($newgrade >= 0)
  1271. $this->action = 'viewsubmission';
  1272. $this->view_iassign_current();
  1273. }
  1274. /// Add or Edit interactive activities
  1275. // @calledby $this->action()
  1276. function add_edit_iassign () {
  1277. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1278. require_once('iassign_form.php');
  1279. $id = $this->cm->id;
  1280. $iassignid = $this->iassign->id;
  1281. $param = new stdClass();
  1282. $param->action = $this->action; // oculto
  1283. $param->id = $id; // oculto
  1284. $COURSE->cm = $id;
  1285. $COURSE->iassignid = $iassignid;
  1286. $COURSE->iassign_file_id = NULL;
  1287. $context = context_module::instance($this->cm->id);
  1288. $contextuser = context_user::instance($USER->id);
  1289. $component = 'mod_iassign';
  1290. $filearea = 'exercise';
  1291. if (!empty($this->iassign_current))
  1292. $COURSE->iassign_id = $this->iassign_current;
  1293. else
  1294. $COURSE->iassign_id = 0;
  1295. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1296. if ($this->action == 'add') {
  1297. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1298. $params = array('iassignid' => $iassignid);
  1299. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1300. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1301. $total_of_activities = count($iassign_statement);
  1302. $param->iassignid = $iassignid;
  1303. $param->name = "";
  1304. $param->oldname = "";
  1305. $param->type_iassign = 3;
  1306. $param->proposition = "";
  1307. $author = $DB->get_record("user", array("id" => $USER->id));
  1308. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1309. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1310. $param->author = $param->author_name;
  1311. $param->author_modified = $param->author_modified_name;
  1312. $COURSE->iassign_list = array();
  1313. $param->iassign_list = array();
  1314. if ($iassign_statement) {
  1315. foreach ($iassign_statement as $iassign) {
  1316. $iassignid = $iassign->id;
  1317. $param->iassign_list[$iassignid] = 0;
  1318. $COURSE->iassign_list[$iassignid] = new stdClass();
  1319. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1320. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1321. $COURSE->iassign_list[$iassignid]->enable = 1;
  1322. } // foreach ($iassign_statement as $iassign)
  1323. }
  1324. $param->iassign_ilmid = 0;
  1325. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1326. $param->file = 0;
  1327. $param->fileold = 0;
  1328. $param->filename = "";
  1329. $param->grade = $iassign_data->grade;
  1330. $param->timemodified = time();
  1331. $param->timecreated = time();
  1332. $param->timeavailable = $iassign_data->timeavailable;
  1333. $param->timedue = $iassign_data->timedue;
  1334. $param->preventlate = $iassign_data->preventlate;
  1335. $param->test = $iassign_data->test;
  1336. $param->special_param1 = 0;
  1337. $param->visible = 1;
  1338. $param->max_experiment = $iassign_data->max_experiment;
  1339. $param->dependency = 0;
  1340. $param->automatic_evaluate = 1;
  1341. $param->show_answer = 1;
  1342. } // if ($this->action == 'add')
  1343. elseif ($this->action == 'edit') {
  1344. $COURSE->iassign_list = array();
  1345. $this_activity = $this->activity->get_activity();
  1346. if ($this_activity != null) {
  1347. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1348. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1349. $param->iassign_id = $iassign_statement_current->id; // oculto
  1350. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1351. $param->name = $iassign_statement_current->name;
  1352. $param->oldname = $iassign_statement_current->name;
  1353. $param->type_iassign = $iassign_statement_current->type_iassign;
  1354. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1355. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1356. //2019 $param->proposition = $iassign_statement_current->proposition;
  1357. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1358. $param->author_name = $iassign_statement_current->author_name; // oculto
  1359. $param->author = $iassign_statement_current->author_name;
  1360. $author = $DB->get_record("user", array('id' => $USER->id));
  1361. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1362. $param->author_modified = $param->author_modified_name;
  1363. $dependency = explode(';', $iassign_statement_current->dependency);
  1364. $param->iassign_list = array();
  1365. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1366. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1367. $array_dependency = array();
  1368. $subdependency = "";
  1369. $sub_subdependency = "";
  1370. // dependent on this exercise
  1371. if ($iassign_statement_dependency) {
  1372. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1373. // to whom this exercise depends
  1374. foreach ($inter as $tmp)
  1375. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1376. $list_dependency = $subdependency . $sub_subdependency;
  1377. $array_dependency = explode(";", $list_dependency);
  1378. }
  1379. // Get all activity with the same iLM - iassignid
  1380. $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";
  1381. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1382. $total_of_activities = count($all_others_iassign_statement) + 1;
  1383. $inter = array();
  1384. if ($all_others_iassign_statement) {
  1385. foreach ($all_others_iassign_statement as $iassign)
  1386. if (in_array($iassign->id, $dependency))
  1387. $inter[] = $iassign->id;
  1388. }
  1389. if ($all_others_iassign_statement) {
  1390. foreach ($all_others_iassign_statement as $iassign) {
  1391. $iassignid = $iassign->id;
  1392. $COURSE->iassign_list[$iassignid] = new stdClass();
  1393. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1394. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1395. if (in_array($iassignid, $dependency))
  1396. $param->iassign_list[$iassignid] = 1;
  1397. else
  1398. $param->iassign_list[$iassignid] = 0;
  1399. if (in_array($iassignid, $array_dependency))
  1400. $COURSE->iassign_list[$iassignid]->enable = 0;
  1401. else
  1402. $COURSE->iassign_list[$iassignid]->enable = 1;
  1403. } // foreach ($all_others_iassign_statement as $iassign)
  1404. }
  1405. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1406. $param->fileold = 0;
  1407. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1408. $param->filename = '';
  1409. $param->grade = $iassign_statement_current->grade;
  1410. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1411. $param->timeavailable = $iassign_statement_current->timeavailable;
  1412. $param->timedue = $iassign_statement_current->timedue;
  1413. $param->preventlate = $iassign_statement_current->preventlate;
  1414. $param->test = $iassign_statement_current->test;
  1415. $param->special_param1 = $iassign_statement_current->special_param1;
  1416. $param->position = $iassign_statement_current->position; // oculto
  1417. $param->visible = $iassign_statement_current->visible;
  1418. $param->max_experiment = $iassign_statement_current->max_experiment;
  1419. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1420. $param->show_answer = $iassign_statement_current->show_answer;
  1421. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1422. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1423. if ($files) {
  1424. foreach ($files as $file) {
  1425. if ($file->get_filename() != '.') {
  1426. $param->filename = $file->get_filename();
  1427. $param->file = $file->get_id();
  1428. $param->fileold = $file->get_id();
  1429. $COURSE->iassign_file_id = $file->get_id();
  1430. }
  1431. }
  1432. }
  1433. //TODO //MOOC2014 -- inicio
  1434. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1435. //D if ($iassign_ilm_configs) {
  1436. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1437. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1438. //D } //MOOC2014 -- fim
  1439. } // if ($this_activity != null)
  1440. } // elseif ($this->action == 'edit')
  1441. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1442. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1443. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1444. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1445. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1446. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1447. $param->position = $total_of_activities;
  1448. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1449. $mform->set_data($param);
  1450. if ($mform->is_cancelled()) {
  1451. $this->return_home_course('iassign_cancel');
  1452. exit;
  1453. }
  1454. else { // if ($mform->is_cancelled())
  1455. $result = $mform->get_data();
  1456. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1457. if ($result) {
  1458. $result->context = $context;
  1459. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1460. $result->grade = 0;
  1461. if ($result->type_iassign == 1) {
  1462. $result->automatic_evaluate = 0;
  1463. $result->show_answer = 0;
  1464. }
  1465. elseif ($result->automatic_evaluate == 0)
  1466. $result->show_answer = 0;
  1467. // $_POST['iassign_list']
  1468. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1469. if ($result->iassign_list) {
  1470. foreach ($result->iassign_list as $key => $value)
  1471. $result->dependency .= $key . ';';
  1472. }
  1473. else
  1474. $result->dependency = 0;
  1475. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1476. //TODO Then get it directly from the form data $_POST!
  1477. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1478. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1479. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1480. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1481. if ($this->action == 'add') {
  1482. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1483. if ($iassign_statement_name) {
  1484. $this->return_home_course('error_iassign_name');
  1485. die();
  1486. }
  1487. // Really insert the new iActivity in table '*_iassign_statement'
  1488. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1489. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1490. // Trigger module viewed event.
  1491. $event = \mod_iassign\event\iassign_created::create(array(
  1492. 'objectid' => $iassignid,
  1493. 'context' => $context
  1494. ));
  1495. $event->add_record_snapshot('course', $this->course);
  1496. $event->trigger();
  1497. $this->return_home_course('iassign_add');
  1498. } // if ($this->action == 'add')
  1499. elseif ($this->action == 'edit') {
  1500. $iassignid = $this->activity->update_iassign($result);
  1501. $this->activity->update_calendar($iassignid, $result->oldname);
  1502. // Trigger module viewed event.
  1503. $event = \mod_iassign\event\iassign_updated::create(array(
  1504. 'objectid' => $iassignid,
  1505. 'context' => $context
  1506. ));
  1507. $event->add_record_snapshot('course', $this->course);
  1508. $event->trigger();
  1509. $this->return_home_course('iassign_update');
  1510. } // elseif ($this->action == 'edit')
  1511. die();
  1512. } // if ($result)
  1513. } // else if ($mform->is_cancelled())
  1514. print $OUTPUT->header();
  1515. $mform->display();
  1516. print $OUTPUT->footer();
  1517. die();
  1518. } // function add_edit_iassign()
  1519. /// Search for dependencies
  1520. function search_dependency ($search_iassing_id, $iassign_statement) {
  1521. global $DB, $OUTPUT;
  1522. $dependency = "";
  1523. if ($iassign_statement)
  1524. foreach ($iassign_statement as $iassign) {
  1525. $inter_dependency = explode(';', $iassign->dependency);
  1526. if (in_array($search_iassing_id, $inter_dependency)) {
  1527. $dependency .= $iassign->id . ";";
  1528. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1529. } // if (in_array($search_iassing_id, $inter_dependency))
  1530. } // foreach ($iassign_statement as $iassign)
  1531. return $dependency;
  1532. }
  1533. /// Search for "sub"dependency
  1534. function search_sub_dependency ($search_iassing_id) {
  1535. global $DB, $OUTPUT;
  1536. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1537. $dependency = "";
  1538. if ($iassign_statement) {
  1539. $inter_dependency = explode(';', $iassign_statement->dependency);
  1540. foreach ($inter_dependency as $tmp) {
  1541. if ($tmp != 0)
  1542. $dependency .= $tmp . ";";
  1543. $dependency .= $this->search_sub_dependency($tmp);
  1544. } // foreach ($inter_dependency as $tmp)
  1545. } // if ($iassign_statement)
  1546. return $dependency;
  1547. }
  1548. // Warning message
  1549. static function warning_message_iassign ($strcode) {
  1550. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1551. }
  1552. /// Update grade of iAssign
  1553. // Called always any iAssign activity is created
  1554. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1555. static function update_grade_iassign ($iassignid) {
  1556. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1557. require_once($CFG->libdir . '/gradelib.php');
  1558. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1559. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1560. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1561. // Each iAssign item is associated with one item on the "gradebook"
  1562. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1563. //$sum_grade = 0;
  1564. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1565. //foreach($grade as $tmp) {
  1566. // $sum_grade += $tmp->grade;
  1567. // }
  1568. //1 Solution 1
  1569. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1570. //1 $sum_grade = 0; //1
  1571. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1572. //2 Solution 2
  1573. $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
  1574. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1575. if (key($array_sum_grade))
  1576. $sum_grade = key($array_sum_grade); //2
  1577. else
  1578. $sum_grade = 0; //2
  1579. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1580. $grades = NULL;
  1581. $params = array('itemname' => $grade_iassign->name);
  1582. $params['iteminstance'] = $iassignid;
  1583. $params['gradetype'] = GRADE_TYPE_VALUE;
  1584. //2016 if ($sum_grade != 0) {
  1585. $params['grademax'] = $sum_grade;
  1586. $params['rawgrademax'] = $sum_grade;
  1587. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1588. $params['grademin'] = 0;
  1589. // @calls /lib/gradelib.php: call to grade_item->insert()
  1590. //TODO: is there any error here in Moodle version 3.0?
  1591. //TODO: Incorrect property 'grademax' found when inserting grade object
  1592. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1593. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1594. }
  1595. /// Update grade of student
  1596. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1597. global $CFG, $DB, $OUTPUT;
  1598. require_once($CFG->libdir . '/gradelib.php');
  1599. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1600. // Review all the student submission for this iAssign activity
  1601. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1602. $total_grade = 0;
  1603. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1604. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1605. if ($iassign_submission)
  1606. $total_grade += $iassign_submission->grade;
  1607. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1608. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1609. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1610. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1611. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1612. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1613. $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
  1614. if (key($array_sum_grade))
  1615. $sum_grade = key($array_sum_grade); //2
  1616. else
  1617. $sum_grade = 0; //2
  1618. $grades['userid'] = $userid;
  1619. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1620. $params = array('itemname' => $grade_iassign->name);
  1621. $params['iteminstance'] = $iassignid;
  1622. $params['gradetype'] = GRADE_TYPE_VALUE;
  1623. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1624. $params['grademax'] = $sum_grade;
  1625. $params['rawgrademax'] = $sum_grade;
  1626. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1627. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1628. }
  1629. /// Display caption of icons
  1630. function view_legend_icons () {
  1631. global $USER, $CFG, $DB, $OUTPUT;
  1632. $id = $this->cm->id;
  1633. if ($this->action == 'print')
  1634. print '<table border=1 width=100%><tr>';
  1635. else
  1636. print '<table width=100%><tr>';
  1637. print '<td >';
  1638. if ($this->action != 'print')
  1639. print $OUTPUT->help_icon('legend', 'iassign');
  1640. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1641. // $imagetext = '');
  1642. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1643. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1644. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1645. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1646. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1647. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1648. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1649. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1650. print '</td>' . "\n";
  1651. if ($this->action != 'print') {
  1652. $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>";
  1653. $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>";
  1654. $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>";
  1655. $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>";
  1656. $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>";
  1657. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1658. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1659. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1660. print '<td width=15% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  1661. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1662. } // if ($this->action != 'print')
  1663. print '</tr></table>' . "\n";
  1664. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1665. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1666. $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>";
  1667. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1668. print '</tr></table>' . "\n";
  1669. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1670. else
  1671. print '</td></tr></table>' . "\n";
  1672. } // function view_legend_icons()
  1673. /// Display activity current
  1674. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1675. function view_iassign_current () {
  1676. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1677. $id = $this->cm->id;
  1678. $iassignid = $this->iassign->id;
  1679. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1680. $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
  1681. // 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 ...
  1682. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1683. if (!$iassign_statement_activity_item) {
  1684. print $OUTPUT->header();
  1685. \core\notification::error(get_string('activity_not_found', 'iassign'));
  1686. print $OUTPUT->footer();
  1687. exit;
  1688. }
  1689. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1690. $ilm_name = '';
  1691. if ($ilm->ilm)
  1692. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1693. // 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
  1694. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1695. // log record
  1696. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1697. //Trigger module viewed event.
  1698. $event = \mod_iassign\event\submission_viewed::create(array(
  1699. 'objectid' => $iassign->id,
  1700. 'context' => $this->context,
  1701. 'other' => $info
  1702. ));
  1703. $event->add_record_snapshot('course', $this->course);
  1704. $event->trigger();
  1705. // Search of iLM data used in the current activity
  1706. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1707. // Add actual activity to navbar:
  1708. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1709. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1710. print $OUTPUT->header();
  1711. if ($this->action == 'viewsubmission') {
  1712. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1713. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1714. else
  1715. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1716. } else {
  1717. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1718. }
  1719. if ($iassign_submission)
  1720. $this->update_comment($iassign_submission->id);
  1721. $file = $iassign_statement_activity_item->file;
  1722. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1723. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1724. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1725. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1726. $this->bottonPost = 0; // hide submit button
  1727. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1728. $this->view_iassign = false; // disable visualization of activity
  1729. $repeat = "";
  1730. $last_iassign = "";
  1731. $student_answer = "";
  1732. $comment = "";
  1733. // *** Teacher access (view learner's submission)
  1734. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1735. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1736. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1737. // ---> access teacher for test
  1738. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1739. $this->bottonPost = 1;
  1740. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1741. $this->activity->view_dates();
  1742. $USER->iassignEdit = $this->bottonPost;
  1743. $this->activity->show_info_iassign();
  1744. if ($iassign_submission) {
  1745. //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;
  1746. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1747. } else {
  1748. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1749. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1750. }
  1751. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1752. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1753. // Prepare tags to present the iLM
  1754. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1755. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1756. // *** (end) Teacher access (view the activity)
  1757. // *** Teacher access (view learner's submission to the activity)
  1758. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1759. // It is teacher or 'nonediting teacher' that can evaluate
  1760. // ----> area teacher evaluate
  1761. $row = optional_param('row', 0, PARAM_INT);
  1762. $column = optional_param('column', 0, PARAM_INT);
  1763. $link_next = iassign_icons::insert('right_disable');
  1764. $link_previous = iassign_icons::insert('left_disable');
  1765. $link_up = iassign_icons::insert('up_disable');
  1766. $link_down = iassign_icons::insert('down_disable');
  1767. // next_activity
  1768. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1769. $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);
  1770. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1771. }
  1772. // previous_activity
  1773. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1774. $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);
  1775. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1776. }
  1777. // previous_student
  1778. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1779. $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);
  1780. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1781. }
  1782. // next_student
  1783. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1784. $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);
  1785. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1786. }
  1787. if ($iassign_submission) {
  1788. $student_answer = $iassign_submission->answer;
  1789. }
  1790. $last_iassign = get_string('last_iassign', 'iassign');
  1791. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1792. // Messages related to due date (and user role)
  1793. $this->activity->view_dates();
  1794. print $OUTPUT->box_start();
  1795. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1796. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1797. print $OUTPUT->user_picture($user_data);
  1798. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1799. print '</td>' . "\n";
  1800. print '<td width=20% align=right>' . "\n";
  1801. print '<table width=50 cellpadding="0">';
  1802. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1803. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1804. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1805. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1806. print '</table>' . "\n";
  1807. print '</td></tr></table>' . "\n";
  1808. print $OUTPUT->box_end();
  1809. print $OUTPUT->box_start();
  1810. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1811. print '<td width=60% valign="top">' . "\n";
  1812. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1813. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1814. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1815. $resp = get_string('yes');
  1816. else
  1817. $resp = get_string('no');
  1818. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1819. if ($iassign_statement_activity_item->show_answer == 1)
  1820. $resp = get_string('yes');
  1821. else
  1822. $resp = get_string('no');
  1823. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1824. print '</td>';
  1825. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1826. print '<td width=40% valign="top" align="left">';
  1827. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1828. // check status of solution sent by the student
  1829. if ($iassign_submission) {
  1830. switch ($iassign_submission->status) {
  1831. case 3 :
  1832. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1833. break;
  1834. case 2 :
  1835. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1836. break;
  1837. case 1 :
  1838. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1839. break;
  1840. default :
  1841. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1842. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1843. } // switch ($iassign_submission->status)
  1844. }
  1845. else { // if ($iassign_submission)
  1846. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1847. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1848. }
  1849. // update_status
  1850. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1851. $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);
  1852. print " <script type='text/javascript'>
  1853. //<![CDATA[
  1854. function overwriteStatus (newstatus) {
  1855. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1856. document.formEditStatus.return_status.value=newstatus;
  1857. document.formEditStatus.submit();
  1858. }
  1859. else
  1860. document.formEditStatus.return_status.value=-1;
  1861. }
  1862. //]]>
  1863. </script>";
  1864. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1865. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1866. 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";
  1867. print " <input type='hidden' name='return_status'>\n";
  1868. print "</form>\n";
  1869. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1870. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1871. $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);
  1872. print "
  1873. <script type='text/javascript'>
  1874. //<![CDATA[
  1875. function overwriteGrade (newgrade,maxgrade) {
  1876. if (newgrade<0 || newgrade>maxgrade) {
  1877. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1878. document.formEditGrade.return_grade.value=-1;
  1879. document.formEditGrade.submit();
  1880. }
  1881. else {
  1882. document.formEditGrade.return_grade.value=newgrade;
  1883. document.formEditGrade.submit();
  1884. }
  1885. }
  1886. //]]>
  1887. </script>";
  1888. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1889. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1890. print " <input type='text' name='grade' size='6'>";
  1891. print " <input type='hidden' name='return_grade'> ";
  1892. 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";
  1893. print "</form>";
  1894. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1895. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1896. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1897. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1898. if ($teacher)
  1899. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1900. } // if ($iassign_submission->experiment > 0)
  1901. print '</td>';
  1902. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1903. print '</tr></table>';
  1904. print $OUTPUT->box_end();
  1905. $USER->iassignEdit = $this->bottonPost;
  1906. if ($iassign_submission && $allow_resubmission) {
  1907. // Put the iLM to
  1908. print $OUTPUT->box_start();
  1909. print '<p><strong>' . $last_iassign . '</strong></p>';
  1910. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1911. $enderecoPOST = "";
  1912. // Prepare tags to present the iLM
  1913. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1914. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1915. print $OUTPUT->box_end();
  1916. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1917. // ATTENTION: exception used by iGeom (exercise with "script")
  1918. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1919. if (substr($ilm_name, 0, 5)=="igeom") {
  1920. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1921. $loadTeacherActivity = true;
  1922. }
  1923. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1924. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1925. // Prepare tags to present the iLM
  1926. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1927. }
  1928. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1929. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1930. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1931. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1932. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1933. // *** (end) Teacher access (view learner's submission to the activity)
  1934. // *** Student access (view the activity)
  1935. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1936. // It could be the learner (he could send or resend the activity)
  1937. // ---> access student
  1938. $time_now = time();
  1939. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1940. // activity of type example - not submit button for submission
  1941. $this->view_iassign = true;
  1942. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1943. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1944. // activity of type test - iLM automatic evaluator - submit button for submission
  1945. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1946. $this->bottonPost = 1;
  1947. $this->view_iassign = true;
  1948. } else
  1949. $this->view_iassign = false;
  1950. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1951. // activity of type exercise (learner can send his answer, if yet open...)
  1952. $this->view_iassign = true;
  1953. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1954. $this->view_iassign = false;
  1955. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1956. $this->bottonPost = 1; // allow the submit button
  1957. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1958. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1959. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1960. if (!$iassign_submission) {
  1961. $str_iassign_submission_id = '';
  1962. $str_iassign_submission_answer = '';
  1963. }
  1964. else {
  1965. $str_iassign_submission_id = $iassign_submission->id;
  1966. $str_iassign_submission_answer = $iassign_submission->answer;
  1967. }
  1968. if ($this->action != 'repeat') {
  1969. $repeat = "<a href='view.php?action=repeat&id="
  1970. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1971. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1972. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1973. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1974. }
  1975. $this->bottonPost = 1;
  1976. $this->write_solution = 1; // can register his submission
  1977. $student_answer = $str_iassign_submission_answer;
  1978. }
  1979. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1980. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1981. $last_iassign = get_string('last_iassign', 'iassign');
  1982. if ($iassign_submission) {
  1983. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1984. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1985. $student_answer = $iassign_submission->answer;
  1986. } else {
  1987. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1988. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1989. }
  1990. }
  1991. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1992. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1993. $this->bottonPost = 1;
  1994. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1995. } else {
  1996. $last_iassign = get_string('last_iassign', 'iassign');
  1997. if ($iassign_submission) {
  1998. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1999. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2000. $student_answer = $iassign_submission->answer;
  2001. } else {
  2002. // Symbol of "redo activity"
  2003. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2004. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2005. }
  2006. }
  2007. } // elseif ($iassign_statement_activity_item->test == 1)
  2008. elseif ($iassign_statement_activity_item->test == 0)
  2009. $this->view_iassign = false;
  2010. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2011. if ($iassign_submission)
  2012. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2013. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2014. else
  2015. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2016. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2017. $this->activity->view_dates();
  2018. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2019. print $OUTPUT->box_start();
  2020. print '<table width=100% border=0 valign="top">' . "\n";
  2021. print '<tr><td width=60% valign="top">' . "\n";
  2022. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2023. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2024. $flag_dependency = true;
  2025. if ($iassign_statement_activity_item->type_iassign == 3) {
  2026. if ($iassign_statement_activity_item->dependency == 0) {
  2027. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2028. } else {
  2029. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2030. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2031. foreach ($dependencys as $dependency) {
  2032. if ($dependency) {
  2033. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2034. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2035. if ($dependencysubmissions) {
  2036. if ($dependencysubmissions->status == 3)
  2037. $icon = iassign_icons::insert('correct');
  2038. elseif ($dependencysubmissions->status == 2) {
  2039. $icon = iassign_icons::insert('incorrect');
  2040. $flag_dependency = false;
  2041. } elseif ($dependencysubmissions->status == 1) {
  2042. $icon = iassign_icons::insert('post');
  2043. $flag_dependency = false;
  2044. } elseif ($dependencysubmissions->status == 0) {
  2045. $icon = iassign_icons::insert('not_post');
  2046. $flag_dependency = false;
  2047. }
  2048. } else {
  2049. $icon = iassign_icons::insert('not_post');
  2050. $flag_dependency = false;
  2051. } // if ($dependencysubmissions)
  2052. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2053. } // if ($dependency)
  2054. } // foreach ($dependencys as $dependency)
  2055. } // if ($iassign_statement_activity_item->dependency == 0)
  2056. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2057. if ($flag_dependency == false) {
  2058. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2059. $this->view_iassign = false;
  2060. print '</tr></table>' . "\n";
  2061. }
  2062. else {
  2063. $this->view_iassign = true;
  2064. print '</td>' . "\n";
  2065. } // if ($flag_dependency == false)
  2066. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2067. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2068. // receiver=1 - message to teacher
  2069. // receiver=2 - message to student
  2070. if ($iassign_submission) {
  2071. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2072. if ($verify_message)
  2073. $comment = iassign_icons::insert('comment_unread');
  2074. }
  2075. print '<td width=40% valign="top" align="left">';
  2076. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2077. if ($iassign_statement_activity_item->show_answer == 1) {
  2078. // check status of solution sent by the student
  2079. if ($iassign_submission) {
  2080. switch ($iassign_submission->status) {
  2081. case 3 :
  2082. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2083. break;
  2084. case 2 :
  2085. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2086. break;
  2087. case 1 :
  2088. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2089. break;
  2090. default :
  2091. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2092. $repeat = "";
  2093. $last_iassign = "";
  2094. } // switch ($iassign_submission->status)
  2095. } else {
  2096. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2097. $repeat = "";
  2098. $last_iassign = "";
  2099. }
  2100. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2101. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2102. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2103. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2104. if ($iassign_statement_activity_item->max_experiment == 0)
  2105. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2106. else {
  2107. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2108. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2109. $repeat = "";
  2110. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2111. $this->bottonPost = 0;
  2112. $this->write_solution = 0;
  2113. }
  2114. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2115. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2116. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2117. if ($teacher)
  2118. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2119. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2120. } // if ($iassign_statement_activity_item->show_answer==1)
  2121. else {
  2122. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2123. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2124. $repeat = "";
  2125. $last_iassign = "";
  2126. } elseif ($iassign_submission->status == 1) {
  2127. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2128. }
  2129. }
  2130. print '</td>';
  2131. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2132. print '</tr></table>' . "\n";
  2133. // Presents the iLM
  2134. print '<table width=100% border=0 valign="top">' . "\n";
  2135. print '<td width=80% align="left">';
  2136. 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\".
  2137. print '<td width=20% align="rigth">';
  2138. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2139. print $repeat; // symbol of "redo activity"
  2140. print '</td></tr></table>' . "\n";
  2141. //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)'
  2142. $output = '';
  2143. if (!$iassign_ilm) {
  2144. $iassign_ilm = new stdClass();
  2145. $iassign_ilm->file_jar = "";
  2146. }
  2147. $output .= $OUTPUT->box_start();
  2148. $USER->iassignEdit = $this->bottonPost;
  2149. // ---
  2150. // Presents the iLM
  2151. // Prepare tags to present the iLM
  2152. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2153. $student_answer = ""; //?
  2154. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2155. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2156. $student_answer = "";
  2157. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2158. } else {
  2159. // When student is redoing his activity
  2160. // ATTENTION: exception used by iGeom (exercise with "script")
  2161. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2162. if (substr($ilm_name, 0, 5)=="igeom") {
  2163. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2164. $loadTeacherActivity = true;
  2165. }
  2166. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2167. }
  2168. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2169. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2170. //1 $history_comment = '';
  2171. //1 if ($iassign_submission) {
  2172. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2173. //1 }
  2174. //1 if (!empty($history_comment)) {
  2175. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2176. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2177. //1 $output .= $history_comment;
  2178. //1 $output .= "</table>\n";
  2179. //1 }
  2180. //1 $output .= "</form></center>\n";
  2181. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2182. //1 }
  2183. $output .= $OUTPUT->box_end();
  2184. print $output;
  2185. } // if ($this->view_iassign)
  2186. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2187. } // if ($this->view_iassign)
  2188. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2189. else
  2190. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2191. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2192. print '<table width=100% border=0 valign="top">' . "\n";
  2193. print '<tr><td width=60% valign="top">' . "\n";
  2194. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2195. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2196. print '</tr></table>' . "\n";
  2197. $student_answer = "";
  2198. $enderecoPOST = "";
  2199. // Prepare tags to present the iLM
  2200. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2201. print $output;
  2202. }
  2203. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2204. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2205. 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
  2206. // Put a block with area to sent/answer comments
  2207. $output = '';
  2208. $history_comment = '';
  2209. $row = optional_param('row', 0, PARAM_INT);
  2210. $column = optional_param('column', 0, PARAM_INT);
  2211. if ($iassign_submission) {
  2212. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2213. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2214. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2215. }
  2216. else {
  2217. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2218. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2219. }
  2220. $output .= $OUTPUT->box_start();
  2221. //if (!empty($history_comment)) {
  2222. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2223. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2224. $output .= "</table>";
  2225. print " <script type='text/javascript'>
  2226. //<![CDATA[
  2227. function submit_comment(url) {
  2228. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2229. var formData = new FormData();
  2230. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2231. var request = new XMLHttpRequest();
  2232. request.open('POST', url);
  2233. document.getElementById('comments_history').innerHTML = '';
  2234. request.onload = function (e) {
  2235. if (request.readyState === 4) {
  2236. if (request.status === 200) {
  2237. document.getElementById('comments_history').innerHTML = request.responseText;
  2238. document.getElementById('check-message-success').style.visibility = 'visible';
  2239. setTimeout(function(){
  2240. document.getElementById('check-message-success').style.visibility = 'hidden';
  2241. }, 3000);
  2242. }
  2243. }
  2244. };
  2245. document.formEnvioComment.submission_comment.value = '';
  2246. request.send(formData);
  2247. }
  2248. //]]>
  2249. </script>";
  2250. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2251. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2252. $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";
  2253. $output .= "</form> </center>\n";
  2254. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2255. // }
  2256. $output .= $OUTPUT->box_end();
  2257. print $output;
  2258. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2259. // final block 'studant'
  2260. print $OUTPUT->footer();
  2261. die();
  2262. } // function view_iassign_current()
  2263. /// Export the data from performance report into CSV file format
  2264. function export_csv () {
  2265. global $USER, $CFG, $DB, $OUTPUT;
  2266. $str = "";
  2267. $fields = "student_id, student_name";
  2268. // Finding all iassign activities for the iassign:
  2269. $id = $this->cm->id;
  2270. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2271. $c = 1;
  2272. foreach ($iassign_list as $iassign) {
  2273. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2274. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2275. $c ++;
  2276. }
  2277. // Finding enrolled students:
  2278. $params = array('shortname' => 'student');
  2279. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2280. $context = context_course::instance($this->course->id);
  2281. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2282. $students = $DB->get_records_sql(
  2283. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2284. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2285. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2286. foreach ($students as $student) {
  2287. $str .= $student->userid . ',';
  2288. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2289. foreach ($iassign_list as $iassign) {
  2290. $str .= ',' . $iassign->id . ',';
  2291. $str .= '"' . $iassign->name . '",';
  2292. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2293. if ($student_submissions) {
  2294. $str .= $student_submissions->experiment . ',';
  2295. $str .= $student_submissions->grade . ',';
  2296. switch ($student_submissions->status) {
  2297. case 3:
  2298. $str .= '"correct",';
  2299. break;
  2300. case 2:
  2301. $str .= '"incorrect",';
  2302. break;
  2303. case 1:
  2304. $str .= '"post",';
  2305. break;
  2306. case 0:
  2307. $str .= '"not_post",';
  2308. break;
  2309. }
  2310. } else {
  2311. $str .= ',,"not_post",';
  2312. }
  2313. $str .= $iassign->iassign_ilmid . ',';
  2314. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2315. $str .= '"' . $ilm_activity->name . '"';
  2316. }
  2317. $str .= "\n";
  2318. }
  2319. $str = $fields . "\n" . $str;
  2320. header("Content-type: text/csv");
  2321. header("Content-disposition: attachment; filename=report.csv");
  2322. header("Pragma: no-cache");
  2323. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2324. header('Content-Length: ' . strlen($str));
  2325. header('Connection: close');
  2326. print $str;
  2327. flush();
  2328. } // function export_csv()
  2329. /// Display report of performance
  2330. function report () {
  2331. global $USER, $CFG, $DB, $OUTPUT;
  2332. $id = $this->cm->id;
  2333. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2334. if ($this->action != 'print') {
  2335. $title = get_string('report', 'iassign');
  2336. print $OUTPUT->header();
  2337. } // if ($this->action != 'print')
  2338. print $OUTPUT->box_start();
  2339. $this->view_legend_icons();
  2340. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2341. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2342. print $OUTPUT->box_end();
  2343. if ($this->action == 'print')
  2344. print '<table border=1 width="100%">' . "\n";
  2345. else
  2346. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2347. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2348. // $num = array();
  2349. $i = 1;
  2350. $num = array();
  2351. foreach ($iassign_list as $iassign) {
  2352. $test_exercise = "";
  2353. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2354. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2355. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2356. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2357. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2358. $num[$i] = new stdClass();
  2359. $num[$i]->name = $iassign->name;
  2360. $num[$i]->id = $i;
  2361. $num[$i]->iassignid = $iassign->id;
  2362. print ' <tr >' . "\n";
  2363. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2364. print "<td class=\"cell c0 actvity\">";
  2365. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2366. print ' </tr>' . "\n";
  2367. $i ++;
  2368. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2369. } // foreach ($iassign_list as $iassign)
  2370. print "</table>";
  2371. print "<p></p>";
  2372. if ($this->action == 'print')
  2373. print '<table border=1 width="100%">' . "\n";
  2374. else
  2375. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2376. $context = context_course::instance($this->course->id);
  2377. if ($i > 1) {
  2378. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2379. $params = array('shortname' => 'student');
  2380. $role = $DB->get_record_sql(
  2381. "SELECT s.id, s.shortname FROM {role} s " .
  2382. " WHERE s.shortname = :shortname", $params);
  2383. // $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");
  2384. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2385. $students = $DB->get_records_sql(
  2386. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2387. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2388. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2389. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2390. for ($j = 1; $j < $i; $j ++) {
  2391. $sum_iassign_correct[$j] = 0;
  2392. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2393. }
  2394. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2395. $sum_iassign = $j - 1;
  2396. print '</tr>' . "\n";
  2397. $total = 0;
  2398. $sum_student = 0;
  2399. $comment = iassign_icons::insert('comment_read');
  2400. $sum_comment = 0;
  2401. $sum_correct_iassign = array();
  2402. $sum_correct_student = array();
  2403. $USER->matrix_iassign = array();
  2404. if ($students) {
  2405. $w = 0;
  2406. foreach ($students as $tmp) {
  2407. $users_array[$w] = $tmp;
  2408. $w ++;
  2409. }
  2410. for ($x = 0; $x < $w; $x ++) {
  2411. print '<tr>' . "\n";
  2412. $sum_student ++;
  2413. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2414. print ' <td >' . $name . '</td>' . "\n";
  2415. $total_student = 0;
  2416. $tentativas = 0;
  2417. for ($j = 1; $j < $i; $j ++) {
  2418. $sum_comment = 0;
  2419. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2420. print ' <td valign="bottom" align="center">' . "\n";
  2421. if ($student_submissions) {
  2422. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2423. $tentativas = $student_submissions->experiment;
  2424. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2425. $params = array('iassign_submissionid' => $student_submissions->id);
  2426. $student_submissions_comment = $DB->get_record_sql(
  2427. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2428. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2429. if ($student_submissions_comment)
  2430. foreach ($student_submissions_comment as $tmp)
  2431. $sum_comment = $tmp;
  2432. // informations to previous activities
  2433. if ($j - 1 < 1 || $j == $i)
  2434. $iassign_previous = "-1";
  2435. else
  2436. $iassign_previous = $num[$j - 1]->iassignid;
  2437. if ($x - 1 < 0 || $x == $w)
  2438. $user_previous = "-1";
  2439. else
  2440. $user_previous = $users_array[$x - 1]->userid;
  2441. // next
  2442. if ($i - 1 > $j)
  2443. $iassign_next = $num[$j + 1]->iassignid;
  2444. else
  2445. $iassign_next = "-1";
  2446. if ($w - 1 > $x)
  2447. $user_next = $users_array[$x + 1]->userid;
  2448. else
  2449. $user_next = "-1";
  2450. $position = "&row= $x&column=$j";
  2451. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2452. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2453. $url .= $position;
  2454. // receiver=1 - message to teacher
  2455. // receiver=2 - message to student
  2456. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2457. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2458. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2459. $verify_message = $DB->get_record_sql(
  2460. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2461. "WHERE iassign_submissionid = :iassign_submissionid " .
  2462. " AND return_status= :return_status " .
  2463. " AND receiver= :receiver", $params);
  2464. if ($verify_message)
  2465. foreach ($verify_message as $tmp)
  2466. $sum_verify_message = $tmp;
  2467. if ($sum_verify_message > 0)
  2468. $comment = iassign_icons::insert('comment_unread');
  2469. else
  2470. $comment = iassign_icons::insert('comment_read');
  2471. if ($student_submissions->status == 3) {
  2472. $sum_iassign_correct[$j] ++;
  2473. $total_student ++;
  2474. $feedback = iassign_icons::insert('correct');
  2475. }
  2476. elseif ($student_submissions->status == 2) {
  2477. $feedback = iassign_icons::insert('incorrect');
  2478. }
  2479. elseif ($student_submissions->status == 1) {
  2480. $feedback = iassign_icons::insert('post');
  2481. }
  2482. elseif ($student_submissions->status == 0) {
  2483. $feedback = iassign_icons::insert('not_post');
  2484. }
  2485. if ($this->action != 'print') {
  2486. print '<table><tr>';
  2487. if ($tentativas > 0)
  2488. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2489. else
  2490. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2491. print '<td> &nbsp; </td>';
  2492. print '</tr>' . "\n";
  2493. if ($sum_comment > 0 && $sum_verify_message > 0)
  2494. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2495. else if ($sum_comment > 0)
  2496. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2497. print '</table>' . "\n";
  2498. }
  2499. if ($this->action == 'print')
  2500. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2501. } // if ($student_submissions)
  2502. else { // if ($student_submissions)
  2503. // informations to browse previous activities
  2504. if ($j - 1 < 1 || $j == $i)
  2505. $iassign_previous = "-1";
  2506. else
  2507. $iassign_previous = $num[$j - 1]->iassignid;
  2508. if ($x - 1 < 0 || $x == $w)
  2509. $user_previous = "-1";
  2510. else
  2511. $user_previous = $users_array[$x - 1]->userid;
  2512. // next
  2513. if ($i - 1 > $j)
  2514. $iassign_next = $num[$j + 1]->iassignid;
  2515. else
  2516. $iassign_next = "-1";
  2517. if ($w - 1 > $x)
  2518. $user_next = $users_array[$x + 1]->userid;
  2519. else
  2520. $user_next = "-1";
  2521. $position = "&row= $x&column=$j";
  2522. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2523. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2524. $url .= $position;
  2525. $feedback = iassign_icons::insert('not_post');
  2526. if ($this->action == 'print')
  2527. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2528. else {
  2529. print '<table><tr>';
  2530. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2531. print '<td> &nbsp; </td>';
  2532. print '</tr><tr>' . "\n";
  2533. print '<td> &nbsp;</td>';
  2534. if ($sum_comment > 0)
  2535. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2536. else
  2537. print '<td> &nbsp;</td>';
  2538. print '</tr></table>';
  2539. }
  2540. } // else if ($student_submissions)
  2541. $USER->matrix_iassign[$x][$j] = new stdClass();
  2542. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2543. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2544. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2545. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2546. if ($student_submissions)
  2547. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2548. else
  2549. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2550. print '</td>' . "\n";
  2551. } // for ($j=1; $j<$i; $j++)
  2552. $total = $total + $total_student;
  2553. $porcentagem = ($total_student / ($j - 1)) * 100;
  2554. if ($tentativas != 0 && $tentativas != null) {
  2555. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2556. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2557. }
  2558. else {
  2559. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2560. }
  2561. print '</tr>' . "\n";
  2562. $sum_correct_student[$sum_student] = new stdClass();
  2563. $sum_correct_student[$sum_student]->name = $name;
  2564. $sum_correct_student[$sum_student]->sum = $total_student;
  2565. } // for ($x = 0; $x < $w; $x ++)
  2566. for ($i = 1; $i < $j; $i ++) {
  2567. if (is_null($sum_iassign_correct[$i]))
  2568. $sum_iassign_correct[$i] = 0;
  2569. $sum_correct_iassign[$i] = new stdClass();
  2570. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2571. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2572. }
  2573. // print '</tr></table>' . "\n";
  2574. }
  2575. } // if ($i>1)
  2576. else {
  2577. print_string('no_activity', 'iassign');
  2578. }
  2579. print "</table>\n";
  2580. if ($this->action != 'print')
  2581. print $OUTPUT->footer();
  2582. die();
  2583. } // function report()
  2584. /// Display graphics of performance
  2585. function stats () {
  2586. global $USER, $CFG, $DB, $OUTPUT;
  2587. $id = $this->cm->id;
  2588. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2589. if ($this->action != 'printstats')
  2590. $title = get_string('graphic', 'iassign');
  2591. $num = array();
  2592. $sum_correct_iassign = array();
  2593. $sum_correct_student = array();
  2594. $sum_student = 0;
  2595. $i = 1;
  2596. foreach ($iassign_list as $iassign) {
  2597. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2598. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2599. $sum_iassign_correct[$i] = 0;
  2600. $num[$i] = new stdClass();
  2601. $num[$i]->name = $iassign->name;
  2602. $num[$i]->id = $i;
  2603. $num[$i]->iassignid = $iassign->id;
  2604. $i ++;
  2605. } // if ($iassign->type_iassign == 3)
  2606. } // foreach ($iassign_list as $iassign)
  2607. $sum_iassign = $i - 1;
  2608. $context = context_course::instance($this->course->id);
  2609. if ($i > 1) {
  2610. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2611. $params = array('shortname' => 'student');
  2612. $role = $DB->get_record_sql(
  2613. "SELECT s.id, s.shortname FROM {role} s " .
  2614. " WHERE s.shortname = :shortname", $params);
  2615. // $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");
  2616. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2617. $students = $DB->get_records_sql(
  2618. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2619. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2620. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2621. $total = 0;
  2622. $sum_student = 0;
  2623. $j = 0;
  2624. $sum_correct_iassign = array();
  2625. $sum_correct_student = array();
  2626. $sum_experiment = array();
  2627. if ($students) {
  2628. foreach ($students as $users) {
  2629. $sum_student ++;
  2630. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2631. // rows
  2632. $total_student = 0;
  2633. for ($j = 1; $j < $i; $j ++) {
  2634. $total_experiment = 0;
  2635. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2636. if ($student_submissions) {
  2637. if ($student_submissions->status == 3) {
  2638. $sum_iassign_correct[$j] ++;
  2639. $total_student ++;
  2640. } // if ($student_submissions->status == 3)
  2641. $total_experiment += $student_submissions->experiment;
  2642. }
  2643. $sum_experiment[$j] = $total_experiment;
  2644. } // for ($j=1; $j<$i; $j++)
  2645. $total = $total + $total_student;
  2646. $sum_correct_student[$sum_student] = new stdClass();
  2647. $sum_correct_student[$sum_student]->name = $name;
  2648. $sum_correct_student[$sum_student]->sum = $total_student;
  2649. } // foreach ($students as $users)
  2650. }
  2651. for ($i = 1; $i < $j; $i ++) {
  2652. if (is_null($sum_iassign_correct[$i]))
  2653. $sum_iassign_correct[$i] = 0;
  2654. $sum_correct_iassign[$i] = new stdClass();
  2655. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2656. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2657. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2658. } // for ($i = 1; $i < $j; $i++)
  2659. } // if ($i > 1)
  2660. if ($this->action != 'printstats') {
  2661. $title = get_string('graphic', 'iassign');
  2662. print $OUTPUT->header();
  2663. $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>";
  2664. $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>";
  2665. print '<table width=100%><tr>';
  2666. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2667. print '<td width=15% align="right">' . $link_report . '</td>';
  2668. print '</td></tr></table>' . "\n";
  2669. print "<br><br>";
  2670. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2671. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2672. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2673. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2674. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2675. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2676. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2677. print '</tr>' . "\n";
  2678. $sum_correct = 0;
  2679. if ($sum_correct_iassign) {
  2680. foreach ($sum_correct_iassign as $iassign) {
  2681. if (is_null($iassign->experiment))
  2682. $iassign->experiment = 0;
  2683. $bar = "";
  2684. $sum = $iassign->sum;
  2685. $percent = ($sum / $sum_student) * 100;
  2686. $text = number_format($percent, 1) . '%';
  2687. $sum_correct += $sum;
  2688. if ($sum > 0) {
  2689. for ($i = 1; $i < $percent * 2; $i ++)
  2690. $bar .= iassign_icons::insert('hbar_blue');
  2691. $bar .= iassign_icons::insert('hbar_blue_r');
  2692. } // if ($sum > 0)
  2693. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2694. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2695. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2696. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2697. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2698. print '</tr>' . "\n";
  2699. } // foreach ($sum_correct_iassign as $iassign)
  2700. }
  2701. print "</table>";
  2702. print "<br><br>";
  2703. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2704. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2705. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2706. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2707. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2708. print '</tr>' . "\n";
  2709. $sum_correct = 0;
  2710. foreach ($sum_correct_student as $student) {
  2711. $bar = "";
  2712. $sum = $student->sum;
  2713. $percent = ($sum / $sum_iassign) * 100;
  2714. $text = number_format($percent, 1) . '%';
  2715. $sum_correct += $sum;
  2716. if ($sum > 0) {
  2717. for ($i = 1; $i < $percent * 2; $i ++)
  2718. $bar .= iassign_icons::insert('hbar_blue');
  2719. $bar .= iassign_icons::insert('hbar_blue_r');
  2720. } // if ($sum > 0)
  2721. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2722. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2723. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2724. print '</tr>' . "\n";
  2725. } // foreach ($sum_correct_student as $student)
  2726. print "</table>\n";
  2727. print "<br><br>\n";
  2728. $var = 0;
  2729. $cv = 0;
  2730. $dv = 0;
  2731. $avg = 0;
  2732. if ($sum_correct_student) {
  2733. $avg = $sum_correct / $sum_student;
  2734. if ($avg > 0) {
  2735. foreach ($sum_correct_student as $student)
  2736. $var += pow($student->sum - $avg, 2);
  2737. $var = $var / $sum_student;
  2738. $dv = sqrt($var);
  2739. $cv = ($dv / $avg) * 100;
  2740. }
  2741. }
  2742. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2743. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2744. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2745. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2746. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2747. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2748. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2749. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2750. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2751. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2752. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2753. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2754. print "</table>\n";
  2755. print $OUTPUT->footer();
  2756. } else {
  2757. print "<STYLE TYPE='text/css'>
  2758. <!--
  2759. .boldtable {
  2760. font-family:sans-serif;
  2761. font-size:10pt;
  2762. }
  2763. -->
  2764. </STYLE>\n";
  2765. print '<table border=1 width=100%>' . "\n";
  2766. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2767. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2768. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2769. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2770. print '</tr>' . "\n";
  2771. $sum_correct = 0;
  2772. foreach ($sum_correct_iassign as $iassign) {
  2773. $bar = "";
  2774. $sum = $iassign->sum;
  2775. $percent = ($sum / $sum_student) * 100;
  2776. $text = number_format($percent, 1) . '%';
  2777. $sum_correct += $sum;
  2778. if ($sum > 0) {
  2779. for ($i = 1; $i < $percent * 2; $i ++)
  2780. $bar .= iassign_icons::insert('hbar_blue');
  2781. $bar .= iassign_icons::insert('hbar_blue_r');
  2782. } // if ($sum > 0)
  2783. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2784. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2785. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2786. print '</tr>' . "\n";
  2787. } // foreach ($sum_correct_iassign as $iassign)
  2788. print "</table>";
  2789. print "<br><br>";
  2790. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2791. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2792. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2793. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2794. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2795. print '</tr>' . "\n";
  2796. $sum_correct = 0;
  2797. foreach ($sum_correct_student as $student) {
  2798. $bar = "";
  2799. $sum = $student->sum;
  2800. $percent = ($sum / $sum_iassign) * 100;
  2801. $text = number_format($percent, 1) . '%';
  2802. $sum_correct += $sum;
  2803. if ($sum > 0) {
  2804. for ($i = 1; $i < $percent * 2; $i ++)
  2805. $bar .= iassign_icons::insert('hbar_blue');
  2806. $bar .= iassign_icons::insert('hbar_blue_r');
  2807. } // if ($sum > 0)
  2808. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2809. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2810. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2811. print '</tr>' . "\n";
  2812. } // foreach ($sum_correct_student as $student)
  2813. print "</table>\n";
  2814. print "<br/><br/>\n";
  2815. $var = 0;
  2816. $cv = 0;
  2817. $dv = 0;
  2818. $avg = 0;
  2819. if ($sum_correct_student) {
  2820. $avg = $sum_correct / $sum_student;
  2821. if ($avg > 0) {
  2822. foreach ($sum_correct_student as $student)
  2823. $var += pow($student->sum - $avg, 2);
  2824. $var = $var / $sum_student;
  2825. $dv = sqrt($var);
  2826. $cv = ($dv / $avg) * 100;
  2827. }
  2828. }
  2829. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2830. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2831. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2832. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2833. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2834. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2835. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2836. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2837. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2838. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2839. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2840. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2841. print "</table>\n";
  2842. } // if ($this->action != 'printstats')
  2843. die();
  2844. }
  2845. /// Display graphics of performance for students
  2846. function stats_students () {
  2847. global $USER, $CFG, $DB, $OUTPUT;
  2848. $id = $this->cm->id;
  2849. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2850. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2851. $title = get_string('results', 'iassign');
  2852. $sum_correct = 0;
  2853. $sum_incorrect = 0;
  2854. $sum_post = 0;
  2855. $sum_nopost = 0;
  2856. $sum_iassign = count($iassign_statement_list);
  2857. $bar_nopost = "";
  2858. $bar_correct = "";
  2859. $bar_incorrect = "";
  2860. $bar_post = "";
  2861. $text_nopost = "";
  2862. $text_correct = "";
  2863. $text_incorrect = "";
  2864. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2865. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2866. if ($iassign_submission) {
  2867. if ($iassign_submission->status == 3)
  2868. $sum_correct ++;
  2869. elseif ($iassign_submission->status == 2)
  2870. $sum_incorrect ++;
  2871. elseif ($iassign_submission->status == 1)
  2872. $sum_post ++;
  2873. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2874. $sum_nopost ++;
  2875. } // if ($iassign_submission)
  2876. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2877. if ($sum_iassign > 0) {
  2878. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2879. $text_correct = number_format($percent_correct, 1) . '%';
  2880. }
  2881. if ($sum_correct > 0) {
  2882. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2883. $bar_correct .= iassign_icons::insert('hbar_green');
  2884. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2885. } // if ($sum_correct > 0)
  2886. if ($sum_iassign > 0) {
  2887. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2888. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2889. }
  2890. if ($sum_incorrect > 0) {
  2891. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2892. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2893. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2894. } // if ($sum_incorrect > 0)
  2895. if ($sum_iassign > 0) {
  2896. $percent_post = ($sum_post / $sum_iassign) * 100;
  2897. $text_post = number_format($percent_post, 1) . '%';
  2898. }
  2899. if ($sum_post > 0) {
  2900. for ($i = 1; $i < $percent_post * 2; $i ++)
  2901. $bar_post .= iassign_icons::insert('hbar_blue');
  2902. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2903. } // if ($sum_post > 0)
  2904. if ($sum_iassign > 0) {
  2905. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2906. $text_nopost = number_format($percent_nopost, 1) . '%';
  2907. }
  2908. if ($sum_nopost > 0) {
  2909. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2910. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2911. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2912. } // if ($sum_nopost > 0)
  2913. print $OUTPUT->header();
  2914. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2915. print '<table width=100%><tr>';
  2916. print '<td align="right">' . $link_return . '</td>' . "\n";
  2917. print '</td></tr></table>' . "\n";
  2918. print "<br/><br/>\n";
  2919. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2920. print '<tr><th colspan=3 class="header c1">' . "\n";
  2921. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2922. // $imagetext = '');
  2923. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2924. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2925. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2926. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2927. print '</tr>' . "\n";
  2928. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2929. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2930. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2931. print '</tr>' . "\n";
  2932. if ($sum_post) {
  2933. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2934. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2935. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2936. print '</tr>' . "\n";
  2937. } // if ($sum_post)
  2938. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2939. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2940. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2941. print '</tr>' . "\n";
  2942. print "</table>";
  2943. print "<br><br>";
  2944. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2945. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2946. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2947. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2948. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2949. $sum_grade = 0;
  2950. $sum_grade_student = 0;
  2951. $avg = 0;
  2952. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2953. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2954. if (!$iassign_submission) {
  2955. $iassign_submission = new stdClass();
  2956. $iassign_submission->grade = 0;
  2957. }
  2958. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2959. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2960. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2961. print '</tr>' . "\n";
  2962. $sum_grade += $iassign_statement_activity_item->grade;
  2963. $sum_grade_student += $iassign_submission->grade;
  2964. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2965. if ($sum_grade > 0)
  2966. $avg = $sum_grade_student / $sum_grade * 100;
  2967. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2968. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2969. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2970. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2971. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2972. print "</table>";
  2973. print $OUTPUT->footer();
  2974. die();
  2975. } // function stats_students()
  2976. /// Display page of iAssign's activity
  2977. function view_iassigns () {
  2978. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2979. $id = $this->cm->id;
  2980. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2981. $notice = optional_param('notice', '', PARAM_TEXT);
  2982. if (strpos($notice, 'error'))
  2983. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2984. else if ($notice != '')
  2985. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2986. print $OUTPUT->box_start();
  2987. print '<table width=100% border=0><tr>' . "\n";
  2988. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2989. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2990. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2991. $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>";
  2992. $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>";
  2993. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2994. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2995. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2996. // Has capability to see "report": teacher or up
  2997. print '<td width=10% align="left">' . "\n";
  2998. print $link_help;
  2999. print '</td>' . "\n";
  3000. print '<td width=10% align="left">' . "\n";
  3001. print $link_report;
  3002. print '</td>' . "\n";
  3003. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3004. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3005. print '<td width=15% align="left">' . "\n";
  3006. print $link_add;
  3007. print "</td>\n";
  3008. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3009. //print '</tr></table>' . "\n";
  3010. print '<div style="float: right;">';
  3011. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3012. if ($iassign_list) {
  3013. print '<td align="right">' . "\n";
  3014. // $USER->iassignEdit == 0 view 'Turn editing off'
  3015. // $USER->iassignEdit == 1 view 'Turn editing on'
  3016. if (!isset($USER->iassignEdit))
  3017. $USER->iassignEdit = 0;
  3018. if ($USER->iassignEdit == 0) {
  3019. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3020. $botton = 1;
  3021. } // if ($USER->iassignEdit == 0)
  3022. elseif ($USER->iassignEdit == 1) {
  3023. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3024. $botton = 0;
  3025. } // elseif ($USER->iassignEdit == 1)
  3026. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3027. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3028. print " <input type=submit value='$bottonEdit_message'/>\n";
  3029. print "</form>\n";
  3030. print "</td>\n";
  3031. } // if ($iassign_list)
  3032. }
  3033. print '</tr></table>' . "\n";
  3034. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3035. // $this->view_legend_icons();
  3036. print $OUTPUT->box_end();
  3037. $iassign_array_exercise = array();
  3038. $i_exercise = 0;
  3039. $iassign_array_test = array();
  3040. $i_test = 0;
  3041. $iassign_array_example = array();
  3042. $i_example = 0;
  3043. $iassign_array_general = array();
  3044. $i_general = 0;
  3045. if ($iassign_list) {
  3046. if ($this->iassign->activity_group == 0) {
  3047. foreach ($iassign_list as $iassign) {
  3048. $iassign_array_general[$i_general] = $iassign;
  3049. $i_general ++;
  3050. }
  3051. } // if ($this->iassign->activity_group == 0)
  3052. else {
  3053. foreach ($iassign_list as $iassign) {
  3054. if ($iassign->type_iassign == 3) {
  3055. $iassign_array_exercise[$i_exercise] = $iassign;
  3056. $i_exercise ++;
  3057. } // if ($iassign->type_iassign == 3)
  3058. if ($iassign->type_iassign == 2) {
  3059. $iassign_array_test[$i_test] = $iassign;
  3060. $i_test ++;
  3061. } // if ($iassign->type_iassign == 2)
  3062. if ($iassign->type_iassign == 1) {
  3063. $iassign_array_example[$i_example] = $iassign;
  3064. $i_example ++;
  3065. } // if ($iassign->type_iassign == 1)
  3066. }
  3067. }
  3068. if ($iassign_array_exercise) {
  3069. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3070. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3071. }
  3072. if ($iassign_array_test) {
  3073. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3074. $this->show_iassign($title, $iassign_array_test, $i_test);
  3075. }
  3076. if ($iassign_array_example) {
  3077. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3078. $this->show_iassign($title, $iassign_array_example, $i_example);
  3079. }
  3080. if ($iassign_array_general) {
  3081. $title = "";
  3082. $this->show_iassign($title, $iassign_array_general, $i_general);
  3083. }
  3084. } else { // if ($iassign_list)
  3085. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3086. }
  3087. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3088. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3089. print $OUTPUT->box_start();
  3090. print '<table width=100% border=0><tr>' . "\n";
  3091. print '<td width=10% align="left">' . "\n";
  3092. print $link_report;
  3093. print '</td>' . "\n";
  3094. print '</tr></table>' . "\n";
  3095. print $OUTPUT->box_end();
  3096. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3097. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3098. print $OUTPUT->box_start();
  3099. print '<table width=100% border=0><tr>' . "\n";
  3100. print '<td align="left">' . "\n";
  3101. print $link_add;
  3102. print '</td>' . "\n";
  3103. print '</tr></table>' . "\n";
  3104. print $OUTPUT->box_end();
  3105. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3106. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3107. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3108. $this->view_legend_icons();
  3109. } // function view_iassigns()
  3110. /// Display all iAssigns
  3111. function show_iassign ($title, $iassign_array, $i) {
  3112. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3113. $id = $this->cm->id;
  3114. print $OUTPUT->box_start();
  3115. print " <script type='text/javascript'>
  3116. //<![CDATA[
  3117. function validate_move () {
  3118. var radios = document.getElementsByName('iassign_destiny');
  3119. var formValid = false;
  3120. //alert('aqui validate_move()');
  3121. var i = 0;
  3122. while (!formValid && i < radios.length) {
  3123. if (radios[i].checked) formValid = true;
  3124. i++;
  3125. }
  3126. if (!formValid) {
  3127. document.getElementById('move_dest').classList.add('alert-danger');
  3128. }
  3129. return formValid;
  3130. }
  3131. var modal;
  3132. function load_move(id_ias) {
  3133. document.form_move_activity.iassign_current.value = id_ias;
  3134. modal.style.display = 'block';
  3135. var radios = document.getElementsByName('iassign_destiny');
  3136. var i = 0;
  3137. while (i < radios.length) {
  3138. radios[i].checked = false;
  3139. i++;
  3140. }
  3141. document.getElementById('move_dest').classList.remove('alert-danger');
  3142. }
  3143. function load_modal_elements() {
  3144. modal = document.getElementById('myModal');
  3145. var span = document.getElementById('close_modal');
  3146. span.onclick = function() {
  3147. modal.style.display = 'none';
  3148. }
  3149. window.onclick = function(event) {
  3150. if (event.target == modal) {
  3151. modal.style.display = 'none';
  3152. }
  3153. }
  3154. }
  3155. window.onload = load_modal_elements;
  3156. //]]>
  3157. </script>\n";
  3158. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3159. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3160. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3161. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3162. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3163. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3164. <input type='hidden' name='iassign_current' value='' />";
  3165. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3166. $section = $course_sections[0];
  3167. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3168. for ($k = 0; $k < count($ids_sections); $k++) {
  3169. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3170. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3171. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3172. if ($c_cm) {
  3173. if ($ccm->instance == $c_cm->instance) {
  3174. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3175. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3176. }
  3177. else {
  3178. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3179. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3180. }
  3181. }
  3182. }
  3183. $radio_buttons .= "</ul>";
  3184. }
  3185. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3186. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3187. </form>
  3188. </div></div> </div></div>\n";
  3189. print " <style>.modal {
  3190. display: none;
  3191. position: fixed;
  3192. z-index: 1;
  3193. left: 0;
  3194. top: 0;
  3195. width: 100%;
  3196. height: 100%;
  3197. overflow: scroll;
  3198. background-color: rgb(0,0,0);
  3199. background-color: rgba(0,0,0,0.4);
  3200. }
  3201. .modal-content {
  3202. background-color: #fefefe;
  3203. margin: 15% auto;
  3204. padding: 10px 10px;
  3205. border: 1px solid #888;
  3206. width: 50%;
  3207. }
  3208. #close_modal {
  3209. color: #aaa;
  3210. float: right;
  3211. font-size: 28px;
  3212. font-weight: bold;
  3213. margin-top: -15px;
  3214. margin-right: -3px;
  3215. }
  3216. #close_modal:hover,
  3217. #close_modal:focus {
  3218. color: black;
  3219. text-decoration: none;
  3220. cursor: pointer;
  3221. }
  3222. #modal_title {
  3223. min-height: 3rem;
  3224. color: initial;
  3225. background: initial;
  3226. font-size: 1.5rem;
  3227. line-height: 1.5;
  3228. padding: 15px;
  3229. border-bottom: 1px solid #e5e5e5;
  3230. }
  3231. .input_move {
  3232. width: 90%;
  3233. padding: 2px;
  3234. }
  3235. .input_move:hover {
  3236. background: #eff0ef;
  3237. }
  3238. </style>";
  3239. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3240. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3241. for ($j = 0; $j < $i; $j ++) {
  3242. $iassign_current = $iassign_array[$j]->id;
  3243. // receiver=1 - message to teacher
  3244. // receiver=2 - message to student
  3245. $sum_comment = 0;
  3246. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3247. foreach ($iassign_submissions as $iassign_submission) {
  3248. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3249. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3250. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3251. if ($verify_message)
  3252. foreach ($verify_message as $tmp)
  3253. $sum_comment += $tmp;
  3254. } // foreach ($iassign_submissions as $iassign_submission)
  3255. if ($sum_comment == 0)
  3256. $comment_unread = "";
  3257. else {
  3258. $comment_unread_message = get_string('comment_unread', 'iassign');
  3259. if ($sum_comment == 1)
  3260. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3261. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3262. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3263. }
  3264. if ($j == $i - 1)
  3265. $iassign_down = $iassign_array[$j]->id;
  3266. else
  3267. $iassign_down = $iassign_array[$j + 1]->id;
  3268. if ($j > 0)
  3269. $iassign_up = $iassign_array[$j - 1]->id;
  3270. else
  3271. $iassign_up = $iassign_array[$j]->id;
  3272. if ($iassign_array[$j]->visible == 0)
  3273. $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>";
  3274. else
  3275. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3276. $links .= $comment_unread;
  3277. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3278. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3279. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3280. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3281. if ($j==0) // first activity
  3282. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3283. else
  3284. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3285. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3286. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3287. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3288. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3289. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3290. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3291. if (count($iassign_array) > 1) {
  3292. if ($j == 0)
  3293. $links .= $link_down;
  3294. elseif ($j == $i - 1)
  3295. $links .= $link_up;
  3296. else
  3297. $links .= $link_up . $link_down;
  3298. } // if (count($iassign_array) > 1)
  3299. $links .= $link_edit . $link_delete;
  3300. if ($iassign_array[$j]->visible == 0)
  3301. $links .= $link_visible_show;
  3302. else
  3303. $links .= $link_visible_hide;
  3304. $links .= $link_duplicate_activity . $link_move_activity;
  3305. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3306. print '<p>' . $links . '</p>' . "\n";
  3307. }
  3308. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3309. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3310. print '<table width=100% ><tr>' . "\n";
  3311. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3312. print '</tr></table>' . "\n";
  3313. for ($j = 0; $j < $i; $j ++) {
  3314. $icon_status = "";
  3315. $icon_comment = "";
  3316. if ($iassign_array[$j]->visible == 1) {
  3317. $iassign_current = $iassign_array[$j]->id;
  3318. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3319. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3320. $icon_status = "";
  3321. $icon_comment = "";
  3322. if ($iassign_submission) {
  3323. // receiver=1 - message to teacher
  3324. // receiver=2 - message to student
  3325. // $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");
  3326. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3327. $verify_message = $DB->get_record_sql(
  3328. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3329. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3330. if ($verify_message)
  3331. foreach ($verify_message as $tmp)
  3332. $sum_comment = $tmp;
  3333. if ($sum_comment > 0) {
  3334. $comment_unread_message = get_string('comment_unread', 'iassign');
  3335. if ($sum_comment == 1)
  3336. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3337. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3338. }
  3339. // $icon_comment = iassign_icons::insert('comment_unread');
  3340. if ($iassign_array[$j]->type_iassign == 3) {
  3341. if ($iassign_array[$j]->show_answer == 1) {
  3342. if ($iassign_submission->status == 3)
  3343. $icon_status = iassign_icons::insert('correct');
  3344. elseif ($iassign_submission->status == 2)
  3345. $icon_status = iassign_icons::insert('incorrect');
  3346. elseif ($iassign_submission->status == 1)
  3347. $icon_status = iassign_icons::insert('post');
  3348. elseif ($iassign_submission->status == 0)
  3349. $icon_status = iassign_icons::insert('not_post');
  3350. } // if ($iassign_array[$j]->show_answer==1)
  3351. else {
  3352. if ($iassign_submission->status == 0)
  3353. $icon_status = iassign_icons::insert('not_post');
  3354. else
  3355. $icon_status = iassign_icons::insert('post');
  3356. }
  3357. } // if ($iassign_array[$j]->type_iassign == 3)
  3358. } // if ($iassign_submission)
  3359. elseif ($iassign_array[$j]->type_iassign == 3) {
  3360. $icon_status = iassign_icons::insert('not_post');
  3361. } // if ($iassign_array[$j]->type_iassign == 3)
  3362. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3363. } // if ($iassign_array[$j]->visible == 1)
  3364. } // for ($j = 0; $j < $i; $j++)
  3365. } else if (isguestuser()) {
  3366. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3367. print '<table width=100% ><tr>' . "\n";
  3368. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3369. print '</tr></table>' . "\n";
  3370. for ($j = 0; $j < $i; $j ++) {
  3371. $icon_status = "";
  3372. $icon_comment = "";
  3373. if ($iassign_array[$j]->visible == 1) {
  3374. $iassign_current = $iassign_array[$j]->id;
  3375. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3376. print '<p>' . $links . '</p>' . "\n";
  3377. } // if ($iassign_array[$j]->visible == 1)
  3378. }
  3379. }
  3380. print $OUTPUT->box_end();
  3381. } // function show_iassign($title, $iassign_array, $i)
  3382. /// Show message of return
  3383. function return_home_course ($message) {
  3384. //D global $DB, $OUTPUT;
  3385. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3386. //D echo $OUTPUT->box_start();
  3387. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3388. //D echo '<tr><td align="left"><strong>' . "\n";
  3389. //D print_string($message, 'iassign');
  3390. //D echo '</strong></td>' . "\n";
  3391. //D echo '<td width=20% align="right">' . "\n";
  3392. //D echo $link_return;
  3393. //D echo '</td></tr></table>' . "\n";
  3394. //D echo $OUTPUT->box_end();
  3395. //D // echo $OUTPUT->footer();
  3396. redirect(new moodle_url($this->return . '&notice=' . $message));
  3397. exit;
  3398. }
  3399. /// Search comment of activity
  3400. function search_comment_submission ($iassign_submissionid) {
  3401. global $USER, $DB, $OUTPUT, $COURSE;
  3402. // $context = context_course::instance($COURSE->id);
  3403. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3404. $colorEdit2 = "#d2e5fc";
  3405. $has_capability = 0;
  3406. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3407. $text = "";
  3408. if ($comments) {
  3409. $even = 1;
  3410. foreach ($comments as $tmp) {
  3411. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3412. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3413. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3414. // $text .= $tmp->comment . "</td></tr>";
  3415. //} else {
  3416. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3417. $avatar = new user_picture($user_data);
  3418. $avatar->courseid = $COURSE->id;
  3419. $avatar->link = true;
  3420. $user_picture = $OUTPUT->render($avatar);
  3421. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3422. if ($even) {
  3423. $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";
  3424. $even = 0;
  3425. } else {
  3426. $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";
  3427. $even = 1;
  3428. }
  3429. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3430. } // foreach ($comments as $tmp)
  3431. }
  3432. return $text;
  3433. }
  3434. /// Update comment of activity
  3435. function update_comment ($iassign_submissionid) {
  3436. global $USER, $DB, $OUTPUT;
  3437. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3438. $receiver = 1; // student message to teacher
  3439. else
  3440. $receiver = 2; // teacher message to student
  3441. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3442. if ($verify_message) {
  3443. foreach ($verify_message as $message) {
  3444. if ($message->receiver == $receiver) {
  3445. $newentry = new stdClass();
  3446. $newentry->id = $message->id;
  3447. $newentry->return_status = 1;
  3448. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3449. print_error('error_update', 'iassign');
  3450. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3451. } // if ($message->receiver == $receiver)
  3452. // Trigger module viewed event.
  3453. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3454. 'objectid' => $this->iassign->id,
  3455. 'context' => $this->context
  3456. ));
  3457. $event->add_record_snapshot('course', $this->course);
  3458. $event->trigger();
  3459. } // foreach ($verify_message as $message)
  3460. }
  3461. }
  3462. /// Record comment of activity
  3463. function write_comment_submission () {
  3464. global $USER, $CFG, $DB;
  3465. $id = $this->cm->id;
  3466. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3467. $row = optional_param('row', 0, PARAM_INT);
  3468. $column = optional_param('column', 0, PARAM_INT);
  3469. $sum_comment = 0;
  3470. $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);
  3471. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3472. $str1 = trim($submission_comment);
  3473. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3474. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3475. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3476. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3477. $receiver = 1; // student message to teacher
  3478. $this->action = 'view';
  3479. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3480. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3481. } else {
  3482. $receiver = 2; // teacher message to student
  3483. $this->action = 'viewsubmission';
  3484. //D $tousers = array(); //MOOC 2016
  3485. //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
  3486. }
  3487. //MOOC 2016: foi p/ 15 linhas acima:
  3488. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3489. // verificar se existe uma submissão para o exercício e aluno informados
  3490. if (!$iassign_submission) {
  3491. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3492. }
  3493. if (!$iassign_submission) {
  3494. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3495. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3496. $this->iassign_submission_current = $id_submission;
  3497. } else {
  3498. $id_submission = $iassign_submission->id;
  3499. } // if (!$iassign_submission)
  3500. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3501. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3502. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3503. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3504. $comments = $DB->get_record_sql(
  3505. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3506. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3507. if ($comments)
  3508. foreach ($comments as $tmp)
  3509. $sum_comment = $tmp;
  3510. if ($sum_comment == 0) {
  3511. $newentry = new stdClass();
  3512. $newentry->iassign_submissionid = $id_submission;
  3513. $newentry->comment_authorid = $USER->id;
  3514. $newentry->timecreated = time();
  3515. $newentry->comment = $submission_comment;
  3516. $newentry->receiver = $receiver;
  3517. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3518. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3519. //T $eventdata = new stdClass();
  3520. //T $eventdata->component = 'mod_iassign'; //your component name
  3521. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3522. //T $eventdata->userfrom = $USER;
  3523. //T $eventdata->userto = $touser;
  3524. //T $eventdata->subject = "Teste de Subject";
  3525. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3526. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3527. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3528. //T $eventdata->smallmessage = "Teste de Mensagem";
  3529. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3530. //T // alteracao tulio faria
  3531. //T //message_send($eventdata);
  3532. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3533. // Trigger module viewed event.
  3534. $event = \mod_iassign\event\submission_comment_created::create(array(
  3535. 'objectid' => $this->iassign->id,
  3536. 'context' => $this->context
  3537. ));
  3538. $event->add_record_snapshot('course', $this->course);
  3539. $event->trigger();
  3540. }
  3541. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3542. // if ($this->action=='viewsubmission') {
  3543. // echo $OUTPUT->header();
  3544. // $this->return_last('confirm_add_comment', $link_return);
  3545. // die;
  3546. // }
  3547. return true;
  3548. } // function write_comment_submission()
  3549. /// Writes a new submission
  3550. // The first student answer is under 'function get_answer()'
  3551. function new_submission ($iassignid, $id_user, $receiver) {
  3552. global $USER, $DB, $OUTPUT;
  3553. $newentry = new stdClass();
  3554. $newentry->iassign_statementid = $iassignid;
  3555. $newentry->userid = $id_user;
  3556. $newentry->timecreated = time();
  3557. $newentry->timemodified = time();
  3558. $newentry->answer = 0; // student only submit message
  3559. if ($receiver == 2) // teacher message to student (write id teacher)
  3560. $newentry->teacher = $USER->id;
  3561. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3562. return_home_course('error_insert_submissions');
  3563. else {
  3564. // Trigger module view event
  3565. $event = \mod_iassign\event\submission_created::create(array(
  3566. 'objectid' => $this->iassign->id,
  3567. 'context' => $this->context
  3568. ));
  3569. $event->add_record_snapshot('course', $this->course);
  3570. $event->trigger();
  3571. }
  3572. return $newentry->id;
  3573. }
  3574. /// Return to a specific address of page
  3575. function return_last ($message, $link_return) {
  3576. global $DB, $OUTPUT;
  3577. print $OUTPUT->box_start();
  3578. print '<table width=100% border=0 valign="top">' . "\n";
  3579. print '<tr><td align="left"><strong>' . "\n";
  3580. print_string($message, 'iassign');
  3581. print '</strong></td>' . "\n";
  3582. print '<td width=20% align="right">' . "\n";
  3583. print $link_return;
  3584. print '</td></tr></table>' . "\n";
  3585. print $OUTPUT->box_end();
  3586. print $OUTPUT->footer();
  3587. die();
  3588. } // function return_last($message, $link_return)
  3589. } // class iassign
  3590. /// Class for manage activities
  3591. class activity {
  3592. var $activity;
  3593. /// Constructor of class.
  3594. // @param int $id Id of activity
  3595. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3596. //D public function activity($id) { self::__construct($id); }
  3597. function __construct ($id) {
  3598. global $DB;
  3599. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3600. if (empty($this->activity))
  3601. $this->activity = null;
  3602. }
  3603. /// Get an activity
  3604. // @return NULL
  3605. function get_activity () {
  3606. if ($this->activity != null)
  3607. return $this->activity;
  3608. else
  3609. return null;
  3610. }
  3611. /// Delete interactive activities
  3612. function delete ($return) {
  3613. global $USER, $CFG, $DB, $OUTPUT;
  3614. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3615. $output = $OUTPUT->header();
  3616. $output .= $OUTPUT->box_start();
  3617. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3618. if ($iassign_submission_currents) {
  3619. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3620. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3621. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3622. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3623. $output .= $OUTPUT->box_end();
  3624. $output .= $OUTPUT->footer();
  3625. print $output;
  3626. die();
  3627. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3628. } // if ($iassign_submission_currents)
  3629. else
  3630. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3631. $output .= '<table width=50% border=0>';
  3632. $output .= '<tr valign="top"><td>';
  3633. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3634. $output .= '</td><td>';
  3635. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3636. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3637. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3638. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3639. $output .= "</form>\n";
  3640. $output .= '</td><td>';
  3641. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3642. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3643. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3644. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3645. $output .= "</form>\n";
  3646. $output .= '</td></tr></table>' . "\n";
  3647. $output .= $OUTPUT->box_end();
  3648. $output .= $OUTPUT->footer();
  3649. print $output;
  3650. } // function delete($return)
  3651. /// Function for confirm the delete of activity
  3652. // @param String $return Url of return
  3653. // @param Object $iassign Object content an activity
  3654. function deleteyes ($return, $iassign) {
  3655. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3656. $msg = '';
  3657. if (!empty($this->activity->id)) {
  3658. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3659. if ($iassign_submission_currents) {
  3660. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3661. foreach ($iassign_submission_currents as $iassign_submission)
  3662. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3663. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3664. } // if ($iassign_submission_currents)
  3665. }
  3666. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3667. // Remove all files associated to this activity:
  3668. $fs = get_file_storage();
  3669. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  3670. $this->delete_calendar($this->activity->id);
  3671. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3672. iassign::update_grade_iassign($this->activity->iassignid);
  3673. if ($delete_iassign_current) {
  3674. $iassign->return_home_course('confirm_delete_iassign');
  3675. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3676. } else {
  3677. $iassign->return_home_course('error_confirm_delete_iassign');
  3678. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3679. }
  3680. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3681. }
  3682. }
  3683. /// Changes position of activities (between those inside a group of interactive activities)
  3684. // @param $move_action = must be "up" or "down"
  3685. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3686. function move_iassign ($move_action, $target, $return) {
  3687. global $DB, $OUTPUT;
  3688. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3689. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3690. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3691. if ($move_action=="firstdown") {
  3692. $final_position_source = 2;
  3693. $final_position_target = 1;
  3694. }
  3695. else
  3696. if ($move_action=="down") {
  3697. $final_position_target = $this->activity->position;
  3698. $final_position_source = $final_position_target + 1;
  3699. }
  3700. else
  3701. if ($move_action=="up") {
  3702. $final_position_target = $this->activity->position;
  3703. $final_position_source = $final_position_target - 1;
  3704. }
  3705. else { // error:
  3706. print_error('error_update_move_iassign', 'iassign');
  3707. exit;
  3708. }
  3709. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3710. $newentry->id = $this->activity->id; // ID of the "source activity"
  3711. $newentry->position = $final_position_source;
  3712. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3713. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3714. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3715. print_error('error_update_move_iassign', 'iassign');
  3716. }
  3717. else { // first update performed successfully
  3718. $newentry->id = $iassign_target->id;
  3719. $newentry->position = $final_position_target;
  3720. if (!$DB->update_record('iassign_statement', $newentry))
  3721. print_error('error_update_move_iassign', 'iassign');
  3722. }
  3723. redirect($return);
  3724. }
  3725. /// Enable or disable the display of interactive activities
  3726. function visible_iassign ($return) {
  3727. global $DB;
  3728. $newentry = new stdClass();
  3729. $newentry->id = $this->activity->id;
  3730. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3731. if (!$DB->update_record('iassign_statement', $newentry))
  3732. print_error('error_update_visible_iassign', 'iassign');
  3733. redirect($return);
  3734. }
  3735. /// Add news interactive activities (register in table 'iassign_statement')
  3736. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3737. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3738. function new_iassign ($param) {
  3739. global $DB;
  3740. $newentry = new stdClass();
  3741. $newentry->iassignid = $param->iassignid;
  3742. $newentry->name = $param->name;
  3743. $newentry->type_iassign = $param->type_iassign;
  3744. $newentry->store_all_submissions = $param->store_all_submissions;
  3745. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3746. $proposition = $param->proposition;
  3747. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3748. else $proposition_text = $proposition;
  3749. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3750. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3751. //TODO Then get it directly from the form data $_POST!
  3752. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3753. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3754. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3755. $newentry->author_name = $param->author_name;
  3756. $newentry->author_modified_name = $param->author_modified_name;
  3757. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3758. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3759. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3760. $newentry->grade = $param->grade;
  3761. $newentry->timemodified = time();
  3762. $newentry->timecreated = time();
  3763. if ($param->type_iassign == 1) {
  3764. $newentry->timedue = 0;
  3765. $newentry->timeavailable = 0;
  3766. } // if ($param->type_iassign == 1)
  3767. else {
  3768. $newentry->timedue = $param->timedue;
  3769. $newentry->timeavailable = $param->timeavailable;
  3770. }
  3771. $newentry->preventlate = $param->preventlate;
  3772. $newentry->test = $param->test;
  3773. $newentry->special_param1 = $param->special_param1;
  3774. $newentry->visible = $param->visible;
  3775. $newentry->position = $param->position;
  3776. $newentry->max_experiment = $param->max_experiment;
  3777. $newentry->dependency = $param->dependency;
  3778. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3779. $newentry->show_answer = $param->show_answer;
  3780. $id = $DB->insert_record("iassign_statement", $newentry);
  3781. if ($id) {
  3782. $component = 'mod_iassign';
  3783. $filearea = 'exercise';
  3784. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3785. $file = $fs->get_file_by_id($param->file);
  3786. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3787. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  3788. //$itemid = $id;
  3789. // File already inserted in other context!
  3790. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3791. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3792. $updateentry = new stdClass();
  3793. $updateentry->id = $id;
  3794. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3795. $updateentry->file = $newfile->get_itemid();
  3796. if (!$DB->update_record("iassign_statement", $updateentry))
  3797. print_error('error_add', 'iassign');
  3798. if ($param->type_iassign == 3)
  3799. iassign::update_grade_iassign($param->iassignid);
  3800. //TODO iLM_HTML5 :: //MOOC2014
  3801. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3802. //D if ($iassign_ilm_configs) {
  3803. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3804. //D if ($iassign_ilm_config->param_type != 'static') {
  3805. //D $newentry = new stdClass();
  3806. //D $newentry->iassign_statementid = $id;
  3807. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3808. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3809. //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});
  3810. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3811. //D print_error('error_add_param', 'iassign');
  3812. //D }
  3813. //D }
  3814. //D }
  3815. // log event --------------------------------------------------------------------------------------
  3816. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3817. // log event --------------------------------------------------------------------------------------
  3818. return $id;
  3819. }
  3820. else
  3821. print_error('error_add', 'iassign');
  3822. } // function new_iassign($param)
  3823. /// Add the calendar entries for this iassign
  3824. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3825. // @return bool
  3826. static function add_calendar ($iassignid) {
  3827. global $DB, $CFG;
  3828. require_once($CFG->dirroot . '/calendar/lib.php');
  3829. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3830. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3831. $event = new stdClass();
  3832. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3833. $event->description = $iassign_statement_activity_item->name;
  3834. $event->courseid = $iassign->course;
  3835. $event->groupid = 0;
  3836. $event->userid = 0;
  3837. $event->modulename = 'iassign';
  3838. $event->instance = $iassign->id;
  3839. $event->eventtype = 'due';
  3840. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3841. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3842. calendar_event::create($event);
  3843. }
  3844. /// Update the calendar entries for this iassign
  3845. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3846. // @return bool
  3847. function update_calendar ($iassignid, $olddescription) {
  3848. global $DB, $CFG;
  3849. require_once($CFG->dirroot . '/calendar/lib.php');
  3850. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3851. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3852. $event = new stdClass();
  3853. $event->id = 0;
  3854. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3855. if ($events) {
  3856. foreach ($events as $value) {
  3857. if ($value->description == $olddescription) {
  3858. $event->id = $value->id;
  3859. }
  3860. }
  3861. }
  3862. if ($event->id != 0) {
  3863. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3864. $event->description = $iassign_statement_activity_item->name;
  3865. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3866. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3867. $calendarevent = calendar_event::load($event->id);
  3868. $calendarevent->update($event);
  3869. } else
  3870. $this->add_calendar($iassignid);
  3871. }
  3872. /// Update the calendar entries for this iassign
  3873. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3874. // @return bool
  3875. function delete_calendar ($iassignid) {
  3876. global $DB, $CFG;
  3877. require_once($CFG->dirroot . '/calendar/lib.php');
  3878. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3879. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3880. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3881. if ($events) {
  3882. foreach ($events as $value) {
  3883. if ($value->description == $iassign_statement_activity_item->name) {
  3884. $DB->delete_records('event', array('id' => $value->id));
  3885. }
  3886. }
  3887. }
  3888. }
  3889. /// Update interactive activities
  3890. function update_iassign ($param) {
  3891. global $DB;
  3892. $component = 'mod_iassign';
  3893. $filearea = 'exercise';
  3894. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3895. $file = $fs->get_file_by_id($param->file);
  3896. $fileold = $fs->get_file_by_id($param->fileold);
  3897. if ($param->file != $param->fileold) {
  3898. if ($fileold) {
  3899. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3900. foreach ($fileoldarea as $value) {
  3901. $value->delete();
  3902. }
  3903. }
  3904. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3905. $itemid = $file->get_itemid() + $param->iassign_id;
  3906. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3907. $param->file = $newfile->get_itemid();
  3908. } else
  3909. $param->file = $file->get_itemid();
  3910. } else {
  3911. $param->file = $file->get_itemid();
  3912. }
  3913. $newentry = new stdClass();
  3914. $newentry->id = $param->iassign_id;
  3915. $newentry->name = $param->name;
  3916. $newentry->type_iassign = $param->type_iassign;
  3917. $newentry->store_all_submissions = $param->store_all_submissions;
  3918. //2019 $newentry->proposition = $param->proposition;
  3919. $proposition = $param->proposition;
  3920. if (is_array($proposition))
  3921. $proposition_text = $proposition['text'];
  3922. else
  3923. $proposition_text = $proposition;
  3924. $newentry->proposition = $proposition_text;
  3925. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3926. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3927. $newentry->grade = $param->grade;
  3928. $newentry->author_modified_name = $param->author_modified_name;
  3929. $newentry->timemodified = time();
  3930. if ($param->type_iassign == 1) {
  3931. $newentry->timedue = 0;
  3932. $newentry->timeavailable = 0;
  3933. } // if ($param->type_iassign == 1)
  3934. else {
  3935. $newentry->timedue = $param->timedue;
  3936. $newentry->timeavailable = $param->timeavailable;
  3937. }
  3938. $newentry->preventlate = $param->preventlate;
  3939. $newentry->test = $param->test;
  3940. $newentry->special_param1 = $param->special_param1;
  3941. $newentry->visible = $param->visible;
  3942. $newentry->max_experiment = $param->max_experiment;
  3943. $newentry->dependency = $param->dependency;
  3944. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3945. $newentry->show_answer = $param->show_answer;
  3946. if (!$DB->update_record("iassign_statement", $newentry))
  3947. print_error('error_update', 'iassign');
  3948. if ($param->type_iassign == 3) {
  3949. iassign::update_grade_iassign($param->iassignid);
  3950. }
  3951. //$id = $newentry->id; // MOOC 2016 --- inicio
  3952. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3953. //if ($iassign_activity_item_configs) {
  3954. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3955. // $newentry = new stdClass();
  3956. // $newentry->id = $iassign_activity_item_config->id;
  3957. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3958. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3959. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3960. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3961. // print_error('error_edit_param', 'iassign');
  3962. // }
  3963. // } // MOOC 2016 --- final
  3964. // log event --------------------------------------------------------------------------------------
  3965. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3966. // log event --------------------------------------------------------------------------------------
  3967. return $newentry->id;
  3968. // if ($param->type_iassign==3)
  3969. // $this->update_grade_iassign($param->iassignid);
  3970. } // function update_iassign($param)
  3971. /// Show information of activity
  3972. function show_info_iassign () {
  3973. global $DB, $OUTPUT;
  3974. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3975. if ($this->activity->type_iassign == 3) {
  3976. if ($this->activity->dependency == 0) {
  3977. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3978. } else {
  3979. $dependencys = explode(';', $this->activity->dependency);
  3980. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3981. foreach ($dependencys as $dependency) {
  3982. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3983. if ($dependencyiassign)
  3984. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3985. } // foreach ($dependencys as $dependency)
  3986. } // if ($iassign_statement_activity_item->dependency == 0)
  3987. if ($this->activity->max_experiment == 0)
  3988. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3989. else
  3990. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3991. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3992. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3993. print $OUTPUT->box($output);
  3994. } // function show_info_iassign()
  3995. /// Shows date of opening and closing activities
  3996. function view_dates () {
  3997. global $USER, $CFG, $DB, $OUTPUT;
  3998. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3999. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4000. $status_iassign = "";
  4001. $status_iassign1 = "";
  4002. $status_iassign2 = "";
  4003. if ($this->activity->type_iassign == 1) // activity of type example
  4004. $type_iassign = get_string('example_iassign', 'iassign');
  4005. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4006. $type_iassign = get_string('test_iassign', 'iassign');
  4007. if ($this->activity->timeavailable > time()) {
  4008. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4009. } elseif ($this->activity->timedue < time()) {
  4010. $status_iassign = get_string('last_timedue', 'iassign');
  4011. }
  4012. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4013. $type_iassign = get_string('exercise_iassign', 'iassign');
  4014. if ($this->activity->timeavailable > time()) {
  4015. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4016. } elseif ($this->activity->timedue < time()) { // after delivery
  4017. $status_iassign = get_string('last_timedue', 'iassign');
  4018. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4019. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4020. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4021. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4022. if ($this->activity->test == 1) // allowed to test after of deadline
  4023. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4024. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4025. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4026. } // elseif ($iassign_statement_activity_item->test == 0)
  4027. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4028. } // elseif ($iassign_statement_activity_item->timedue < time())
  4029. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4030. $output = '<table width=100% >' . "\n";
  4031. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4032. $output .= '<tr>' . "\n";
  4033. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4034. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4035. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4036. // leo $output .= '<td width=80%>' . $type_iassign;
  4037. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4038. // $output .= '</td>' . "\n";
  4039. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4040. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4041. $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>";
  4042. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4043. } else {
  4044. $link_next = "";
  4045. $link_previous = "";
  4046. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4047. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4048. // previous_activity
  4049. if ($iassign_previous) {
  4050. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4051. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4052. } // next_activity
  4053. if ($iassign_next) {
  4054. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4055. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4056. }
  4057. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4058. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4059. $output .= '</tr></table>' . "\n";
  4060. $output .= '<table width=100% >' . "\n";
  4061. if ($this->activity->type_iassign > 1) {
  4062. if ($this->activity->timeavailable)
  4063. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4064. if ($this->activity->timedue)
  4065. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4066. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4067. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4068. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4069. $output .= '</table>' . "\n";
  4070. print $OUTPUT->box($output);
  4071. } // function view_dates()
  4072. } // class activity
  4073. /// Class to manage Interactive Learning Module (iLM)
  4074. class ilm {
  4075. var $ilm;
  4076. /// Constructor of class
  4077. // @param int $id Id of iLM
  4078. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4079. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4080. function __construct ($id) {
  4081. global $DB;
  4082. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4083. if (empty($this->ilm))
  4084. $this->ilm = null;
  4085. }
  4086. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4087. // @calledby view_iassign_current()
  4088. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4089. global $USER, $CFG, $DB;
  4090. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4091. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4092. $typec = strtolower($iassign_ilm->type);
  4093. require_once 'ilm_handlers/' . $typec . '.php';
  4094. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4095. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4096. return $retorno;
  4097. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4098. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4099. // @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);
  4100. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4101. // @param Object $file File in use in activity
  4102. // @return int Return the id of log
  4103. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4104. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4105. $newentry = new stdClass();
  4106. $newentry->iassign_statementid = $iassign_activity_itemid;
  4107. $newentry->userid = $USER->id;
  4108. $newentry->file = $content_or_id_from_ilm_security;
  4109. $newentry->timecreated = time();
  4110. $newentry->view = 1;
  4111. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4112. if (!$id_iLM_security) {
  4113. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4114. } // from (!$DB->insert_record("iassign_security", $newentry))
  4115. return $id_iLM_security;
  4116. }
  4117. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4118. // @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);
  4119. // @param int $userid
  4120. // @param int $iassign_activity_itemid Id of iassign statement
  4121. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4122. global $DB;
  4123. // 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")
  4124. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4125. }
  4126. } // class ilm
  4127. /// Class to manage settings of iLM.
  4128. class ilm_settings {
  4129. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4130. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4131. // @param int $ilm_id Id of iLM
  4132. // @param array $options An array with options for create dynamic tag html APPLET
  4133. // @return string Return with a tag html APPLET created
  4134. static function build_ilm_tags ($ilm_id, $options = array()) {
  4135. global $DB;
  4136. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4137. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4138. $typec = strtolower($iassign_ilm->type);
  4139. require_once 'ilm_handlers/' . $typec . '.php';
  4140. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4141. return $retorno;
  4142. } // static function build_ilm_tags($ilm_id, $options = array())
  4143. /// Function for get modified date of iLM file
  4144. // @param string $file_jar String with Ids of iLM files
  4145. // @return string Return with the filenames and modified date
  4146. static function applet_filetime ($file_jar) {
  4147. $filetime = "";
  4148. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4149. $files_jar = explode(",", $file_jar);
  4150. foreach ($files_jar as $one_file) {
  4151. $file = $fs->get_file_by_id($one_file);
  4152. if ($file)
  4153. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4154. }
  4155. return $filetime;
  4156. }
  4157. /// Function for verify an default applet
  4158. // @param String $file_jar String containing an list de ids of applet files
  4159. // @return boolean Return true or fale if applet is default
  4160. static function applet_default ($file_jar) {
  4161. $is_default = true;
  4162. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4163. $files_jar = explode(",", $file_jar);
  4164. foreach ($files_jar as $one_file) {
  4165. $file = $fs->get_file_by_id($one_file);
  4166. if ($file)
  4167. $is_default &= ($file->get_itemid() == 0);
  4168. }
  4169. return $is_default;
  4170. }
  4171. /// Function for get form variables for add, edit, or copy iLM
  4172. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4173. // @see settings_form.php
  4174. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4175. // @param int $ilm_id Id of iLM
  4176. // @param string $action String with the action
  4177. // @return object Return an object with forms variables
  4178. static function add_edit_copy_ilm ($ilm_id, $action) {
  4179. global $USER, $DB, $CFG;
  4180. require_once('settings_form.php'); // put the form
  4181. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4182. $param = new stdClass();
  4183. $param->action = $action;
  4184. $param->ilm_id = $ilm_id;
  4185. $CFG->action_ilm = $action;
  4186. $CFG->ilm_id = $ilm_id;
  4187. if ($action == 'add') {
  4188. $param->title = get_string('add_ilm', 'iassign');
  4189. $param->name = "";
  4190. $param->version = "";
  4191. $param->url = "";
  4192. $param->description = "";
  4193. $param->extension = "";
  4194. $param->author = $USER->id;
  4195. $param->file_jar = "";
  4196. $param->file_jar_static = "";
  4197. $param->file_class = "";
  4198. $param->width = 800;
  4199. $param->height = 600;
  4200. $param->enable = 0; // 0 - hide / 1 - show
  4201. $param->timecreated = time();
  4202. $param->timemodified = time();
  4203. $param->evaluate = 0;
  4204. $param->parent = 0;
  4205. }
  4206. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4207. if ($iassign_ilm) {
  4208. $description = json_decode($iassign_ilm->description);
  4209. $param->title = get_string('edit_ilm', 'iassign');
  4210. $param->id = $iassign_ilm->id;
  4211. $param->name_ilm = $iassign_ilm->name;
  4212. $param->name = $iassign_ilm->name;
  4213. $param->version = $iassign_ilm->version;
  4214. $param->ilm_type = $iassign_ilm->type;
  4215. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4216. $param->url = $iassign_ilm->url;
  4217. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4218. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4219. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4220. if (!isset($description->{current_language()})) {
  4221. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4222. else
  4223. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4224. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4225. }
  4226. else
  4227. $param->description = $description->{current_language()};
  4228. $param->description_lang = $iassign_ilm->description;
  4229. $param->extension = $iassign_ilm->extension;
  4230. $param->author = $iassign_ilm->author;
  4231. $param->file_jar = $iassign_ilm->file_jar;
  4232. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4233. $param->file_class = $iassign_ilm->file_class;
  4234. $param->width = $iassign_ilm->width;
  4235. $param->height = $iassign_ilm->height;
  4236. $param->enable = $iassign_ilm->enable;
  4237. $param->timecreated = $iassign_ilm->timecreated;
  4238. $param->timemodified = time();
  4239. $param->evaluate = $iassign_ilm->evaluate;
  4240. $param->parent = $iassign_ilm->parent;
  4241. }
  4242. }
  4243. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4244. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4245. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4246. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4247. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4248. // echo "Sem dados<br/>"; exit;
  4249. return;
  4250. }
  4251. $description = json_decode($iassign_ilm->description);
  4252. if ($iassign_ilm) {
  4253. if ($iassign_ilm->parent == 0)
  4254. $iassign_ilm->parent = $ilm_id;
  4255. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4256. $param->title = get_string('new_version_ilm', 'iassign');
  4257. $param->name_ilm = $iassign_ilm->name;
  4258. $param->name = $iassign_ilm->name;
  4259. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4260. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4261. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4262. $param->ilm_type = $iassign_ilm->type;
  4263. $param->url = $iassign_ilm->url;
  4264. $param->description = $description->{current_language()};
  4265. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4266. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4267. $param->extension = $iassign_ilm->extension;
  4268. $param->author = $USER->id;
  4269. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4270. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4271. $param->file_jar_static = '';
  4272. $param->file_class = $iassign_ilm->file_class;
  4273. $param->width = $iassign_ilm->width;
  4274. $param->height = $iassign_ilm->height;
  4275. $param->enable = 0;
  4276. $param->timecreated = time();
  4277. $param->timemodified = time();
  4278. $param->evaluate = $iassign_ilm->evaluate;
  4279. $param->parent = $iassign_ilm->parent;
  4280. }
  4281. }
  4282. elseif ($action == 'copy') {
  4283. $description = json_decode($iassign_ilm->description);
  4284. if ($iassign_ilm) {
  4285. if ($iassign_ilm->parent == 0)
  4286. $iassign_ilm->parent = $ilm_id;
  4287. $param->title = get_string('copy_ilm', 'iassign');
  4288. $param->id = $iassign_ilm->id;
  4289. $param->name_ilm = $iassign_ilm->name;
  4290. $param->name = $iassign_ilm->name;
  4291. $param->version = "";
  4292. $param->ilm_type = $iassign_ilm->type;
  4293. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4294. $param->url = $iassign_ilm->url;
  4295. $param->description = $description->{current_language()};
  4296. $param->description_lang = $iassign_ilm->description;
  4297. $param->extension = $iassign_ilm->extension;
  4298. $param->author = $USER->id;
  4299. $param->file_jar = '';
  4300. $param->file_jar_static = '';
  4301. $param->file_class = $iassign_ilm->file_class;
  4302. $param->width = $iassign_ilm->width;
  4303. $param->height = $iassign_ilm->height;
  4304. $param->enable = 0;
  4305. $param->timecreated = time();
  4306. $param->timemodified = time();
  4307. $param->evaluate = $iassign_ilm->evaluate;
  4308. $param->parent = $iassign_ilm->parent;
  4309. }
  4310. }
  4311. return $param;
  4312. } // static function add_edit_copy_ilm($ilm_id, $action)
  4313. /// Function for save iLM file in moodledata
  4314. // @param int $itemid Itemid of file save in draft (upload file)
  4315. // @param int $ilm_id Id of iLM
  4316. // @return string Return an string with ids of iLM files
  4317. static function new_file_ilm ($itemid, $iassign_ilm) {
  4318. global $CFG, $USER, $DB;
  4319. $return = null;
  4320. $file_jar = array();
  4321. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4322. $contextuser = context_user::instance($USER->id);
  4323. $contextsystem = context_system::instance();
  4324. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4325. if ($files_ilm) {
  4326. foreach ($files_ilm as $value) {
  4327. // CHECK IF file is HTML type
  4328. if ($iassign_ilm->type == 1) {
  4329. // Check if the file extension is ZIP
  4330. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4331. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4332. if ((strtolower($ext) == 'zip')) {
  4333. // Coping...:
  4334. $destination = 'ilm_debug/' . $value->get_filename();
  4335. $value->copy_content_to($destination);
  4336. // Extracting content...:
  4337. $zip = new ZipArchive();
  4338. $extracted = './ilm';
  4339. $dir = "";
  4340. if ($zip->open($destination) === TRUE) {
  4341. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4342. if (is_dir($dir)) {
  4343. $i = 1;
  4344. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4345. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4346. $i ++;
  4347. }
  4348. $name = $previous . "_" . $i;
  4349. $dir = './ilm/' . $name . "/";
  4350. $j = 0;
  4351. while ($item_name = $zip->getNameIndex($j)) {
  4352. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4353. $j++;
  4354. }
  4355. $zip->close();
  4356. }
  4357. $zip->open($destination);
  4358. $zip->extractTo($extracted);
  4359. $zip->close();
  4360. // After the extraction, remove it from DEBUG
  4361. unlink($destination);
  4362. } else { // Error trying to open destination...
  4363. // After the extraction error, also remove it from DEBUG
  4364. unlink($destination);
  4365. print_error('error_add_ilm_zip', 'iassign');
  4366. }
  4367. return $dir;
  4368. }
  4369. } // if ($iassign_ilm->type == 1)
  4370. if ($value->get_filename() != '.') {
  4371. $file_ilm = array(
  4372. 'userid' => $USER->id,
  4373. 'contextid' => $contextsystem->id,
  4374. 'component' => 'mod_iassign',
  4375. 'filearea' => 'ilm',
  4376. 'itemid' => rand(1, 999999999),
  4377. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4378. 'filename' => $value->get_filename());
  4379. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4380. array_push($file_jar, $file_ilm->get_id());
  4381. }
  4382. }
  4383. if (!empty($file_jar)) {
  4384. $return = implode(",", $file_jar);
  4385. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4386. foreach ($old_file_jar as $value) {
  4387. $file = $fs->get_file_by_id($value);
  4388. if ($file)
  4389. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4390. }
  4391. }
  4392. }
  4393. else // if ($files_ilm)
  4394. $return = $iassign_ilm->file_jar;
  4395. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4396. return $return;
  4397. } // static function new_file_ilm($itemid, $iassign_ilm)
  4398. /// Function for save in database an new iLM
  4399. // @param object $param An object with iLM params
  4400. static function new_ilm ($itemid) {
  4401. global $CFG, $USER, $OUTPUT;
  4402. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4403. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4404. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4405. }
  4406. $pathtemp = $CFG->dataroot . '/temp/';
  4407. $contextuser = context_user::instance($USER->id);
  4408. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4409. $zip = new zip_packer();
  4410. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4411. foreach ($files as $file) {
  4412. if (!$file->is_directory())
  4413. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4414. }
  4415. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4416. // Verifica se o pacote possui o XML
  4417. if (!$application_xml) {
  4418. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4419. return;
  4420. } else {
  4421. $missing = "";
  4422. if (!isset($application_xml->name)) {
  4423. $missing .= "name";
  4424. }
  4425. if (!isset($application_xml->version)) {
  4426. $missing .= ", version";
  4427. }
  4428. if (!isset($application_xml->type)) {
  4429. $missing .= ", type";
  4430. }
  4431. if (!isset($application_xml->extension)) {
  4432. $missing .= ", extension";
  4433. }
  4434. if (!isset($application_xml->file_jar)) {
  4435. $missing .= ", file_jar";
  4436. }
  4437. if (!isset($application_xml->file_class)) {
  4438. $missing .= ", file_class";
  4439. }
  4440. if (!isset($application_xml->width)) {
  4441. $missing .= ", width";
  4442. }
  4443. if (!isset($application_xml->height)) {
  4444. $missing .= ", height";
  4445. }
  4446. if (!isset($application_xml->evaluate)) {
  4447. $missing .= ", evaluate";
  4448. }
  4449. if (strlen($missing) > 2) {
  4450. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4451. return;
  4452. }
  4453. }
  4454. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4455. $typec = strtolower($application_xml->type);
  4456. require_once 'ilm_handlers/' . $typec . '.php';
  4457. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4458. return $retorno;
  4459. } // static function new_ilm($itemid)
  4460. /// Function for save in database an iLM edit
  4461. // @param object $param An object with iLM params
  4462. static function edit_ilm ($param, $itemid) {
  4463. // Descobrir o tipo de iLM:
  4464. global $DB, $USER, $CFG;
  4465. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4466. $pathtemp = $CFG->dataroot . '/temp/';
  4467. $contextuser = context_user::instance($USER->id);
  4468. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4469. $zip = new zip_packer();
  4470. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4471. $files_extract = null;
  4472. foreach ($files as $file) {
  4473. if (!$file->is_directory())
  4474. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4475. }
  4476. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4477. $typec = strtolower($iassign_t->type);
  4478. require_once 'ilm_handlers/' . $typec . '.php';
  4479. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4480. }
  4481. /// Function for register the new iLM (in database and in the directory)
  4482. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4483. // @param object $param An object with iLM params
  4484. static function copy_new_version_ilm ($param) {
  4485. global $DB, $CFG, $USER;
  4486. $itemid = $param->file;
  4487. $pathtemp = $CFG->dataroot . '/temp/';
  4488. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4489. //D echo "pathtemp=$pathtemp<br/>";
  4490. $contextuser = context_user::instance($USER->id);
  4491. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4492. $zip = new zip_packer();
  4493. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4494. $files_extract = null;
  4495. foreach ($files as $file) {
  4496. if (!$file->is_directory())
  4497. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4498. }
  4499. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4500. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4501. $typec = strtolower($iassign_t->type);
  4502. require_once 'ilm_handlers/' . $typec . '.php';
  4503. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4504. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4505. } // static function copy_new_version_ilm($param)
  4506. //VER::
  4507. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4508. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4509. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4510. /// Function for change visibility of iLM
  4511. // @param int $ilm_id Id of iLM
  4512. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4513. static function visible_ilm ($ilm_id, $status) {
  4514. global $DB;
  4515. if ($status == 0)
  4516. $visible = 1;
  4517. else
  4518. $visible = 0;
  4519. $newentry = new stdClass();
  4520. $newentry->id = $ilm_id;
  4521. $newentry->enable = $visible;
  4522. if (!$DB->update_record("iassign_ilm", $newentry))
  4523. error(get_string('error_edit_ilm', 'iassign'));
  4524. }
  4525. /// Function for confirm change default iLM
  4526. // @param int $ilm_id Id of iLM
  4527. // @param int $ilm_parent Id of parent iLM
  4528. // @return string Return with an string for create default page confirmation
  4529. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4530. global $OUTPUT, $DB;
  4531. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4532. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4533. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4534. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4535. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4536. return $return;
  4537. }
  4538. /// Function for change the default iLM
  4539. // @see settings_ilm.php
  4540. // @param int $ilm_id Id of iLM
  4541. // @return int Return Id of default iLM
  4542. static function default_ilm ($ilm_id) {
  4543. global $DB;
  4544. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4545. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4546. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4547. $iassign_ilm_default->id = $iassign_ilm->id;
  4548. $iassign_ilm_default->parent = 0;
  4549. $iassign_ilm->parent = $iassign_ilm_default->id;
  4550. $iassign_ilm->id = 0;
  4551. $iassign_ilm_default->enable = 1;
  4552. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4553. print_error('error_edit_ilm', 'iassign');
  4554. }
  4555. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4556. if (!$inserted) {
  4557. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4558. print_error($msg_error);
  4559. //xx print_error('error_add_ilm', 'iassign');
  4560. }
  4561. return $iassign_ilm_default->id;
  4562. } // static function default_ilm ($ilm_id)
  4563. /// Function for confirm delete iLM
  4564. // @param int $ilm_id Id of iLM
  4565. // @param int $ilm_parent Id of parent iLM
  4566. // @return string Return with an string for create delete page confirmation
  4567. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4568. global $OUTPUT, $DB;
  4569. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4570. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4571. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4572. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4573. }
  4574. /// Function for delete directory where the iLM is allocated.
  4575. // @param string $dirPath
  4576. // @throws InvalidArgumentException
  4577. public static function delete_dir ($dirPath) {
  4578. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4579. $dirPath .= '/';
  4580. }
  4581. $files = glob($dirPath . '*', GLOB_MARK);
  4582. foreach ($files as $file) {
  4583. if (is_dir($file)) {
  4584. ilm_settings::delete_dir($file);
  4585. } else {
  4586. unlink($file);
  4587. }
  4588. }
  4589. rmdir($dirPath);
  4590. }
  4591. /// Function for delete iLM
  4592. // @param int $ilm_id Id of iLM
  4593. // @return int Return Id of parent iLM
  4594. static function delete_ilm ($ilm_id) {
  4595. global $DB;
  4596. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4597. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4598. $typec = strtolower($iassign_ilm->type);
  4599. require_once 'ilm_handlers/' . $typec . '.php';
  4600. $retorno = $typec::delete_ilm($ilm_id);
  4601. return $retorno;
  4602. }
  4603. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4604. // @param int $ilm_id Id of iLM
  4605. static function export_ilm ($ilm_id) {
  4606. global $DB;
  4607. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4608. if (!$iassign_ilm) return; // security debug...
  4609. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4610. $typec = strtolower($iassign_ilm->type);
  4611. if (!$typec) $typec = "html5"; // security debug...
  4612. require_once 'ilm_handlers/' . $typec . '.php';
  4613. $typec::export_ilm($ilm_id);
  4614. } // static function export_ilm($ilm_id)
  4615. //TODO iLM_HTML5 :: //MOOC 2016
  4616. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4617. // @param int $ilm_id Id of iLM
  4618. static function export_update_ilm ($ilm_id) {
  4619. global $DB, $CFG;
  4620. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4621. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4622. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4623. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4624. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4625. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4626. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4627. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4628. $upgrade_descriptor .= '</upgrade>' . "\n";
  4629. file_put_contents($xml_filename, $upgrade_descriptor);
  4630. header("Pragma: public");
  4631. header("Expires: 0");
  4632. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4633. header("Cache-Control: private", false);
  4634. header('Content-Type: application/xml; charset=utf-8');
  4635. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4636. header("Content-Length: " . @filesize($xml_filename));
  4637. set_time_limit(0);
  4638. @readfile("$xml_filename") || die("File not found.");
  4639. unlink($xml_filename);
  4640. exit;
  4641. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4642. /// Function for save iLM from XML descriptor
  4643. // @param array $application_xml Data of XML descriptor
  4644. // @param array $files_extract Filenames of extract files
  4645. // @return array Return an array content id of JAR files
  4646. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4647. global $CFG, $USER;
  4648. // Tratamento diferenciado se for do tipo HTML5:
  4649. $source = "";
  4650. $diretorio = "";
  4651. if (strtolower($application_xml->type) == 'html5') {
  4652. $i = 0;
  4653. foreach ($files_extract as $key => $value) {
  4654. $file = $CFG->dataroot . '/temp/' . $key;
  4655. // Verifica se já existe a pasta no diretório dos iLM:
  4656. if ($i == 0) {
  4657. $source = $file;
  4658. if (file_exists("ilm/" . basename($file))) {
  4659. $j = 1;
  4660. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4661. $j ++;
  4662. }
  4663. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4664. // mkdir($diretorio, 0777, true);
  4665. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4666. }
  4667. else {
  4668. $diretorio = 'ilm/' . basename($file);
  4669. // mkdir($diretorio, 0777, true);
  4670. mkdir($diretorio, 0755, true);
  4671. }
  4672. break;
  4673. }
  4674. $i ++;
  4675. }
  4676. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4677. if ($item->isDir()) {
  4678. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4679. }
  4680. else {
  4681. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4682. }
  4683. }
  4684. ilm_settings::delete_dir($source);
  4685. return "./" . $diretorio;
  4686. }
  4687. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4688. $file_jar = array();
  4689. $files_ilm = explode(",", $application_xml->file_jar);
  4690. $contextsystem = context_system::instance();
  4691. foreach ($files_ilm as $value) {
  4692. $file_ilm = array(
  4693. 'userid' => $USER->id,
  4694. 'contextid' => $contextsystem->id,
  4695. 'component' => 'mod_iassign',
  4696. 'filearea' => 'ilm',
  4697. 'itemid' => rand(1, 999999999),
  4698. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4699. 'filename' => $value);
  4700. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4701. array_push($file_jar, $file_ilm->get_id());
  4702. }
  4703. foreach ($files_extract as $key => $value) {
  4704. $file = $CFG->dataroot . '/temp/' . $key;
  4705. if (file_exists($file))
  4706. unlink($file);
  4707. }
  4708. return $file_jar;
  4709. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4710. /// Function for import the iLM from an package
  4711. // @param int $itemid Itemid of zip file
  4712. static function import_ilm ($itemid) {
  4713. global $CFG, $USER, $OUTPUT;
  4714. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4715. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4716. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4717. }
  4718. $pathtemp = $CFG->dataroot . '/temp/';
  4719. $contextuser = context_user::instance($USER->id);
  4720. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4721. $zip = new zip_packer();
  4722. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4723. foreach ($files as $file) {
  4724. if (!$file->is_directory())
  4725. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4726. }
  4727. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4728. // Verifica se o pacote possui o XML
  4729. if (!$application_xml) {
  4730. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4731. return;
  4732. } else {
  4733. $missing = "";
  4734. if (!isset($application_xml->name)) {
  4735. $missing .= "name";
  4736. }
  4737. if (!isset($application_xml->version)) {
  4738. $missing .= ", version";
  4739. }
  4740. if (!isset($application_xml->type)) {
  4741. $missing .= ", type";
  4742. }
  4743. if (!isset($application_xml->extension)) {
  4744. $missing .= ", extension";
  4745. }
  4746. if (!isset($application_xml->file_jar)) {
  4747. $missing .= ", file_jar";
  4748. }
  4749. if (!isset($application_xml->file_class)) {
  4750. $missing .= ", file_class";
  4751. }
  4752. if (!isset($application_xml->width)) {
  4753. $missing .= ", width";
  4754. }
  4755. if (!isset($application_xml->height)) {
  4756. $missing .= ", height";
  4757. }
  4758. if (!isset($application_xml->evaluate)) {
  4759. $missing .= ", evaluate";
  4760. }
  4761. if (strlen($missing) > 2) {
  4762. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4763. return;
  4764. }
  4765. }
  4766. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4767. $typec = strtolower($application_xml->type);
  4768. require_once 'ilm_handlers/' . $typec . '.php';
  4769. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4770. } // static function import_ilm($itemid)
  4771. /// Function for list iLM defaults
  4772. // @return string Return an string with a table of iLM
  4773. static function list_ilm () {
  4774. global $DB, $OUTPUT;
  4775. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4776. $str = '';
  4777. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4778. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4779. if ($iassign_ilm) {
  4780. foreach ($iassign_ilm as $ilm) {
  4781. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4782. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4783. $str .= '<tr><td>';
  4784. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4785. $str .= '<tr>';
  4786. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4787. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4788. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4789. $str .= '</tr>';
  4790. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4791. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4792. $str .= '</table>';
  4793. $str .= '</td></tr>';
  4794. }
  4795. }
  4796. $str .= '</table>';
  4797. return $str;
  4798. }
  4799. /// Function for download and install an upgrade of an iLM
  4800. // @param int $ilm_id Id of iLM
  4801. static function upgrade_ilm ($ilm_id) {
  4802. global $DB, $CFG, $USER;
  4803. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4804. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4805. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4806. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4807. if (!$result)
  4808. print_error('error_upgrade_ilm', 'iassign');
  4809. else {
  4810. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4811. $extension = explode(".", $zip_filename);
  4812. if ($extension[count($extension) - 1] != 'ipz') {
  4813. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4814. die;
  4815. }
  4816. $zip = new zip_packer();
  4817. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4818. $contextuser = context_user::instance($USER->id);
  4819. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4820. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4821. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4822. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4823. if (file_exists($zip_filename))
  4824. unlink($zip_filename);
  4825. if (empty($file_jar)) {
  4826. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4827. print_error($msg_error);
  4828. //xx print_error('error_add_ilm', 'iassign');
  4829. }
  4830. else {
  4831. $newentry = new stdClass();
  4832. $newentry->name = (String) $application_xml->name;
  4833. $newentry->version = (String) $application_xml->version;
  4834. $newentry->url = (String) $application_xml->url;
  4835. $newentry->description = $description_str;
  4836. $newentry->extension = strtolower((String) $application_xml->extension);
  4837. $newentry->file_jar = implode(",", $file_jar);
  4838. $newentry->file_class = (String) $application_xml->file_class;
  4839. $newentry->width = (String) $application_xml->width;
  4840. $newentry->height = (String) $application_xml->height;
  4841. $newentry->enable = 0;
  4842. $newentry->timemodified = time();
  4843. $newentry->author = $USER->id;
  4844. $newentry->timecreated = time();
  4845. $newentry->evaluate = (String) $application_xml->evaluate;
  4846. $newentry->parent = $ilm_id;
  4847. }
  4848. }
  4849. return $iassign_ilm->id;
  4850. } // static function upgrade_ilm($ilm_id)
  4851. //MOOC2014 -- inicio
  4852. //TODO: REVIEW
  4853. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4854. // static function move_iassign($ilm_id)
  4855. //MOOC2014 -- final
  4856. /// Function for list iLM versions with all informations
  4857. // @return string Return an string with a table of iLM
  4858. static function view_ilm ($ilmid, $from) {
  4859. global $DB;
  4860. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4861. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4862. $typec = strtolower($iassign_ilm->type);
  4863. require_once 'ilm_handlers/' . $typec . '.php';
  4864. $retorno = $typec::view_ilm($ilmid, $from);
  4865. return $retorno;
  4866. }
  4867. /// Function for get form variables for add, edit, or copy iLM params
  4868. // @param int $ilm_param_id Id of iLM param
  4869. // @param string $action String with the action
  4870. // @return object Return an object with forms variables
  4871. static function add_edit_copy_param ($ilm_param_id, $action) {
  4872. global $DB;
  4873. require_once('params_form.php');
  4874. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4875. $param = new stdClass();
  4876. $param->action = $action;
  4877. $param->ilm_param_id = $ilm_param_id;
  4878. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4879. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4880. $type = $iassign_ilm_config->param_type;
  4881. if ($action == 'add') {
  4882. $param->title = get_string('add_ilm', 'iassign');
  4883. $param->iassign_ilmid = $ilm_param_id;
  4884. $param->param_name = "";
  4885. $param->param_value = "";
  4886. $param->description = "";
  4887. $param->visible = 1;
  4888. }
  4889. elseif ($action == 'edit') {
  4890. if ($iassign_ilm_config) {
  4891. $param->title = get_string('edit_ilm', 'iassign');
  4892. $param->id = $iassign_ilm_config->id;
  4893. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4894. $param->param_type = $type; //MOOC2014
  4895. $param->param_name = $iassign_ilm_config->param_name;
  4896. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4897. $param->param_value = $iassign_ilm_config->param_value;
  4898. else //MOOC2014
  4899. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4900. $param->param_value = $iassign_ilm_config->param_value;
  4901. $param->description = $iassign_ilm_config->description;
  4902. $param->visible = $iassign_ilm_config->visible;
  4903. }
  4904. }
  4905. elseif ($action == 'copy') {
  4906. if ($iassign_ilm_config) {
  4907. $param->title = get_string('copy_ilm', 'iassign');
  4908. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4909. $param->param_type = $type; //MOOC2014
  4910. $param->param_name = $iassign_ilm_config->param_name;
  4911. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4912. $param->param_value = $iassign_ilm_config->param_value;
  4913. else //MOOC2014
  4914. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4915. $param->description = $iassign_ilm_config->description;
  4916. $param->visible = $iassign_ilm_config->visible;
  4917. }
  4918. }
  4919. return $param;
  4920. } // static function add_edit_copy_param($ilm_param_id, $action)
  4921. /// Function for change visibility of iLM param
  4922. // @param int $ilm_param_id Id of iLM param
  4923. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4924. static function visible_param ($ilm_param_id, $status) {
  4925. global $DB, $CFG;
  4926. if ($status == 0)
  4927. $visible = 1;
  4928. else
  4929. $visible = 0;
  4930. $newentry = new stdClass();
  4931. $newentry->id = $ilm_param_id;
  4932. $newentry->visible = $visible;
  4933. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4934. error(get_string('error_edit_param', 'iassign'));
  4935. }
  4936. /// Function for save in database an new iLM param
  4937. // @param object $param An object with iLM params
  4938. static function add_param ($param) {
  4939. global $DB;
  4940. $newentry = new stdClass();
  4941. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4942. //MOOC2014 $newentry->param_name = $param->param_name;
  4943. $newentry->param_type = $param->param_type; //MOOC2014
  4944. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4945. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4946. $newentry->param_value = $param->param_value;
  4947. else //MOOC2014
  4948. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4949. $newentry->description = $param->description;
  4950. $newentry->visible = $param->visible;
  4951. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4952. if (!$newentry->id) {
  4953. print_error('error_add_param', 'iassign');
  4954. }
  4955. }
  4956. /// Function for save in database a iLM param edit
  4957. // @param object $param An object with iLM params
  4958. static function edit_param ($param) {
  4959. global $DB;
  4960. $updentry = new stdClass();
  4961. $updentry->id = $param->id;
  4962. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4963. $updentry->param_type = $param->param_type; //MOOC2014
  4964. // $updentry->param_name = $param->param_name;
  4965. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4966. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4967. $updentry->param_value = $param->param_value;
  4968. else //MOOC2014
  4969. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4970. $updentry->description = $param->description;
  4971. $updentry->visible = $param->visible;
  4972. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4973. error(get_string('error_edit_param', 'iassign'));
  4974. }
  4975. }
  4976. /// Function for save in database a iLM param copy
  4977. // @param object $param An object with iLM params
  4978. static function copy_param ($param) {
  4979. global $DB;
  4980. $newentry = new stdClass();
  4981. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4982. //$newentry->param_name = $param->param_name;
  4983. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4984. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4985. $newentry->param_value = $param->param_value;
  4986. else //MOOC2014
  4987. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4988. $newentry->description = $param->description;
  4989. $newentry->visible = $param->visible;
  4990. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4991. if (!$newentry->id) {
  4992. print_error('error_add_param', 'iassign');
  4993. }
  4994. }
  4995. /// Function for delete iLM param of database
  4996. // @param int $param_id Id of iLM param
  4997. static function delete_param ($param_id) {
  4998. global $DB;
  4999. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5000. print_error('error_delete_param', 'iassign');
  5001. }
  5002. }
  5003. } // class ilm_settings
  5004. /// Class for manage iLM files (editor).
  5005. class ilm_manager {
  5006. var $id; // course id
  5007. var $url;
  5008. var $from;
  5009. /// Constructor for the base ilm_manager class
  5010. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5011. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5012. function __construct ($id, $url, $from) {
  5013. $this->id = $id; // course id
  5014. $this->url = $url;
  5015. $this->from = $from;
  5016. }
  5017. /// Function to get iAssign content file in Moodle data (exercise)
  5018. // @calledby x function preview_ilm($iassign_ilm) :
  5019. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5020. function get_file_ilm () {
  5021. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5022. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5023. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5024. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5025. $md_file = $fs->get_file_by_id($fileid);
  5026. $ilm_content_file = $md_file->get_content();
  5027. return $ilm_content_file;
  5028. }
  5029. /// Function for creating a new file from the iLM online editor
  5030. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5031. function ilm_editor_new () {
  5032. global $CFG, $DB, $OUTPUT, $PAGE;
  5033. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5034. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5035. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5036. $context = context_course::instance($this->id);
  5037. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5038. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5039. if (!$iassign) {
  5040. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5041. die();
  5042. }
  5043. $temp = explode(",", $iassign->extension);
  5044. $extension = $temp[0]; // default extension for this iLM
  5045. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5046. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5047. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5048. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5049. if ($stringArchiveContent != NULL) {
  5050. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5051. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5052. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5053. $filename = optional_param('filename', NULL, PARAM_RAW);
  5054. //Leo $filename = iassign_utils::format_filename($filename); //
  5055. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5056. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5057. //2019/02 $arrayfilename = explode(".", $filename);
  5058. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5059. //2019/02 $count_dots = count($arrayfilename);
  5060. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5061. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5062. //2019/02 if ($last_name != $extension)
  5063. //2019/02 $filename = $filename . '.' . $extension;
  5064. //2019/02 }
  5065. //2019/02 else { // no extension...
  5066. //2019/02 $filename = $filename . '.' . $extension;
  5067. //2019/02 }
  5068. // Store the name of recent created file
  5069. $_SESSION['file_name'] = $filename;
  5070. //$this->write_file_iassign($string, $filename);
  5071. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5072. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5073. die();
  5074. }
  5075. else { // if ($stringArchiveContent != NULL)
  5076. // iLM On-line editor
  5077. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5078. $str_get_iLM = "window.frames.iLM";
  5079. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5080. }
  5081. else { // otherwise it is JAR named 'iLM'
  5082. $str_get_iLM = "document.iLM";
  5083. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5084. }
  5085. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5086. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5087. $files_array = '';
  5088. foreach ($files as $value) {
  5089. if ($value->get_filename() != ".")
  5090. $files_array .= "'" . $value->get_filename() . "',";
  5091. }
  5092. $files_array .= "''";
  5093. $file = null;
  5094. $ia_content = "";
  5095. $filename = "";
  5096. $error_files_exists = get_string('error_file_exists', 'iassign');
  5097. $output = "<script type='text/javascript'>
  5098. //<![CDATA[
  5099. //D alert('locallib.php: ilm_editor_new');
  5100. function submit_iLM_Answer () {
  5101. var docFormOnLineEditor = document.formEnvio;
  5102. var resposta_exerc = new Array(3);
  5103. var valor_resposta = new Array(3);
  5104. var sessao = new Array(3);
  5105. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5106. resposta_exerc[0] = doc_iLM.getAnswer();
  5107. valor_resposta[0] = doc_iLM.getEvaluation();
  5108. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5109. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5110. var files = new Array(" . $files_array . ");
  5111. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5112. if (docFormOnLineEditor.filename.value=='') {
  5113. // ERROR: the file name is empty
  5114. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5115. return false;
  5116. }
  5117. // }
  5118. for (i=0; i<files.length; i++) {
  5119. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5120. alert('" . $error_files_exists . "');
  5121. return false;
  5122. }
  5123. }
  5124. docFormOnLineEditor.submit();
  5125. return true;
  5126. }
  5127. //]]>
  5128. </script>\n";
  5129. $output .= "
  5130. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5131. $output .= $OUTPUT->box_start();
  5132. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5133. $output .= "
  5134. <table width='100%' cellpadding='20'>
  5135. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5136. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5137. </tr>
  5138. </table>\n";
  5139. $output .= $OUTPUT->box_end();
  5140. $output .= "<center>\n";
  5141. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5142. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5143. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5144. $output .= $output_ilm;
  5145. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5146. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5147. </center>
  5148. </form>\n";
  5149. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5150. $PAGE->navbar->add($title);
  5151. $PAGE->set_title($title);
  5152. $PAGE->set_heading($title); // insert title above the navigation bar
  5153. print $OUTPUT->header();
  5154. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5155. print $output;
  5156. print $OUTPUT->footer();
  5157. }
  5158. die();
  5159. } // function ilm_editor_new()
  5160. /// Function for editing an file in online editor
  5161. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5162. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5163. global $CFG, $DB, $OUTPUT, $PAGE;
  5164. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5165. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5166. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5167. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5168. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5169. // If iLM is not registered, error!
  5170. if (!$iassign) {
  5171. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5172. die;
  5173. }
  5174. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5175. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5176. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5177. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5178. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5179. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5180. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5181. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5182. if ($stringArchiveContent != NULL) {
  5183. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5184. die();
  5185. } else { // if ($stringArchiveContent != NULL)
  5186. $end_file = '';
  5187. if ($content_file) {
  5188. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5189. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5190. }
  5191. $temp = explode(",", $iassign->extension);
  5192. $extension = $temp[0]; // default extension for this iLM
  5193. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5194. $str_get_iLM = "window.frames.iLM";
  5195. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5196. } else { // otherwise it is JAR named 'iLM'
  5197. $str_get_iLM = "document.iLM";
  5198. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5199. }
  5200. $output = "<script type='text/javascript'>
  5201. //<![CDATA[
  5202. function submit_iLM_Answer () {
  5203. var docFormEditor = document.formEnvio;
  5204. var activityAnswer; // to get activity answer (text)
  5205. var activityValue; // to get activity answer value (float)
  5206. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5207. //activityAnswer = doc_iLM.getAnswer();
  5208. //activityValue = doc_iLM.getEvaluation();
  5209. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5210. activityValue = " . $str_get_iLM . ".getEvaluation();
  5211. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5212. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5213. docFormEditor.submit();
  5214. return true;
  5215. }
  5216. //]]>
  5217. </script>\n";
  5218. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5219. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5220. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5221. // return true;
  5222. // }
  5223. $output .= "
  5224. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5225. $output .= $OUTPUT->box_start();
  5226. $output .= "
  5227. <table width='100%' cellpadding='20'>
  5228. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5229. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5230. <input type='hidden' name='filename' value='$filename'/></td>
  5231. <td>
  5232. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5233. </tr>
  5234. </table>\n";
  5235. $output .= $OUTPUT->box_end();
  5236. $output .= " <center>\n";
  5237. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5238. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5239. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5240. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5241. </center>
  5242. </form>\n";
  5243. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5244. $PAGE->navbar->add($title);
  5245. $PAGE->set_title($title);
  5246. $PAGE->set_heading($title); // insert title above the navigation bar
  5247. print $OUTPUT->header();
  5248. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5249. print $output;
  5250. print $OUTPUT->footer();
  5251. } // else if ($stringArchiveContent != NULL)
  5252. die();
  5253. } // function ilm_editor_update()
  5254. /// Function for write iAssign file in Moodle data (exercise)
  5255. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5256. // @param string $stringArchiveContent Content of iassign file
  5257. // @param string $filename Filename of iassign file
  5258. function write_file_iassign ($stringArchiveContent, $filename) {
  5259. global $USER;
  5260. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5261. $context = context_course::instance($this->id);
  5262. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5263. $dirid = $this->get_dir_ilm('dirid');
  5264. $dir = $fs->get_file_by_id($dirid);
  5265. $fileinfo = array('contextid' => $context->id, // ID of course
  5266. 'component' => 'mod_iassign', // usually = table name
  5267. 'filearea' => 'activity', // usually = table name
  5268. 'itemid' => 0, // usually = ID of row in table
  5269. 'filepath' => '/', // any path beginning and ending whith '/'
  5270. 'userid' => $USER->id,
  5271. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5272. 'filename' => $filename); // any filename
  5273. // Create file containing text. '$stringArchiveContent'
  5274. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5275. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5276. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5277. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5278. // 'Activité interactive enregistrée avec succès sous le nom:';
  5279. // 'Atividade interativa gravada com sucesso sob o nome:'
  5280. $output = "
  5281. <script type='text/javascript'>
  5282. //<![CDATA[
  5283. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5284. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5285. //]]>
  5286. </script>";
  5287. print $output;
  5288. die();
  5289. }
  5290. /// Function for write iAssign file in Moodle data (exercise)
  5291. // @param string $stringArchiveContent Content of iassign file
  5292. // @param string $filename Filename of iassign file
  5293. // @param int $itemid Itemid of iassign file
  5294. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5295. global $OUTPUT, $USER;
  5296. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5297. $context = context_course::instance($this->id);
  5298. $dirid = $this->get_dir_ilm('dirid');
  5299. if ($stringArchiveContent != (-1)) {
  5300. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5301. $file = $fs->get_file_by_id($fileid);
  5302. if (!$file) {
  5303. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5304. die;
  5305. }
  5306. $fileinfo = array('contextid' => $context->id, // ID of context
  5307. 'component' => 'mod_iassign', // usually = table name
  5308. 'filearea' => 'activity', // usually = table name
  5309. 'itemid' => 0, // usually = ID of row in table
  5310. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5311. 'userid' => $USER->id,
  5312. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5313. 'license' => 'allrightsreserved', // allrightsreserved
  5314. 'timecreated' => $file->get_timecreated(),
  5315. 'filename' => $file->get_filename()); // any filename
  5316. $file->delete();
  5317. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5318. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5319. }
  5320. $output = "<script type='text/javascript'>
  5321. //<![CDATA[
  5322. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5323. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5324. //]]>
  5325. </script>";
  5326. print $output;
  5327. die();
  5328. }
  5329. /// Function for create an tag for iAssign filter
  5330. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5331. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5332. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5333. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5334. // @param int $fileid Id of file
  5335. // @return string Return an string with an tag of iassign filter
  5336. function tag_ilm ($fileid) {
  5337. global $DB;
  5338. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5339. $width = '600';
  5340. $height = '400';
  5341. $file = $fs->get_file_by_id($fileid);
  5342. $filetype = explode(".", $file->get_filename());
  5343. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5344. foreach ($iassign_ilm as $value) {
  5345. $extensions = explode(",", $value->extension);
  5346. if (in_array($filetype[1], $extensions)) {
  5347. $width = $value->width;
  5348. $height = $value->height;
  5349. }
  5350. }
  5351. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5352. }
  5353. /// Function for delete iAssign file in Moodle data (exercise)
  5354. function delete_file_ilm () {
  5355. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5356. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5357. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5358. $file = $fs->get_file_by_id($fileid);
  5359. if ($file)
  5360. $file->delete();
  5361. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5362. die();
  5363. }
  5364. /// Function for delete selected iAssign file in Moodle data (exercise)
  5365. function delete_selected_ilm () {
  5366. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5367. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5368. $context = context_course::instance($this->id);
  5369. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5370. $dirid = $this->get_dir_ilm('dirid');
  5371. foreach ($files_id as $file_id) {
  5372. $file = $fs->get_file_by_id($file_id);
  5373. if ($file) {
  5374. if (!$file->is_directory())
  5375. $file->delete();
  5376. else {
  5377. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5378. foreach ($files_delete as $value)
  5379. $value->delete();
  5380. $file->delete();
  5381. }
  5382. }
  5383. }
  5384. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5385. die();
  5386. }
  5387. /// Function for duplicate iAssign file from "online" edition
  5388. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5389. function duplicate_file_ilm () {
  5390. global $USER, $COURSE;
  5391. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5392. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5393. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5394. $filename = optional_param('filename', NULL, PARAM_RAW);
  5395. $file = $fs->get_file_by_id($fileid);
  5396. $context = context_course::instance($this->id);
  5397. $fileinfo = array(
  5398. 'contextid' => $context->id, // ID of context
  5399. 'component' => 'mod_iassign', // usually = table name
  5400. 'filearea' => 'activity', // usually = table name
  5401. 'itemid' => 0, // usually = ID of row in table
  5402. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5403. 'userid' => $USER->id,
  5404. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5405. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5406. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5407. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5408. die();
  5409. }
  5410. /// Function for rename iAssign file
  5411. function rename_file_ilm () {
  5412. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5413. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5414. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5415. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5416. $file = $fs->get_file_by_id($fileid);
  5417. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5418. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5419. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5420. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5421. die();
  5422. }
  5423. /// Function for get iassign file for iassign form
  5424. function add_ilm () {
  5425. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5426. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5427. $output = "
  5428. <script type='text/javascript'>
  5429. //<![CDATA[
  5430. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5431. iassign_file_link.innerHTML = '$filename';
  5432. window.opener.document.forms['mform1'].file.value='$fileid';
  5433. window.opener.document.forms['mform1'].filename.value='$filename';
  5434. window.close();
  5435. //]]>
  5436. </script>";
  5437. print $output;
  5438. die();
  5439. }
  5440. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5441. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5442. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5443. function preview_ilm ($courseid, $iassign_ilm) {
  5444. global $OUTPUT, $CFG, $USER;
  5445. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5446. $title = get_string('modulename', 'iassign'); // iAssign
  5447. print $OUTPUT->header();
  5448. print $OUTPUT->box_start();
  5449. $javascript = "
  5450. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5451. <script type='text/javascript'>
  5452. //<![CDATA[
  5453. function submit_close () {
  5454. window.opener.location.reload();
  5455. window.close();
  5456. }
  5457. //]]>
  5458. </script>\n";
  5459. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5460. // to the complete "applet" tag
  5461. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5462. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5463. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5464. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5465. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5466. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5467. if ($ilm_name != "ivprog") {
  5468. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5469. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5470. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5471. } else {
  5472. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5473. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5474. $timecreated = time();
  5475. $token = md5($timecreated);
  5476. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5477. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5478. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5479. $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)
  5480. }
  5481. $html = "
  5482. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5483. <table border='1'>
  5484. <tr><td>
  5485. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5486. <!-- iLM calls : end -->
  5487. </td></tr>
  5488. </table>
  5489. <table>
  5490. <tr>
  5491. <td align='center'>
  5492. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5493. </td></tr>
  5494. </table>
  5495. </form>\n";
  5496. print $javascript . $html;
  5497. print $OUTPUT->box_end();
  5498. //NAO echo format_string($html); // Moodle 3.X
  5499. die();
  5500. } // function preview_ilm($courseid, $iassign_ilm)
  5501. //r_ function preview_ilm ($iassign_ilm)
  5502. //r_ /// Function for preview iassign file from iassign filter.
  5503. //r_ function preview_ilm() {
  5504. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5505. //r_ $tag_filter = $this->tag_ilm($fileid);
  5506. //r_ $javascript = "<script type='text/javascript'>
  5507. //r_ //<![CDATA[
  5508. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5509. //r_ //]]>
  5510. //r_ </script>";
  5511. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5512. //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>
  5513. //r_ </table></form></body></html>";
  5514. //r_ echo $javascript . format_text($html);
  5515. //r_ die;
  5516. //r_ }
  5517. /// Function for export an package (zip) of iassign files
  5518. function export_files_ilm () {
  5519. global $CFG;
  5520. $context = context_course::instance($this->id);
  5521. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5522. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5523. $zip = new zip_archive();
  5524. $zip->open($zip_filename);
  5525. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5526. foreach ($files_id as $file_id) {
  5527. $file = $fs->get_file_by_id($file_id);
  5528. if (!$file->is_directory())
  5529. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5530. else {
  5531. $zip->add_directory($file->get_filepath());
  5532. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5533. foreach ($files_zip as $value) {
  5534. if (!$value->is_directory())
  5535. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5536. else
  5537. $zip->add_directory($value->get_filepath());
  5538. }
  5539. }
  5540. }
  5541. $zip->close();
  5542. header("Pragma: public");
  5543. header("Expires: 0");
  5544. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5545. header("Cache-Control: private", false);
  5546. header("Content-Type: application/zip");
  5547. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5548. header("Content-Transfer-Encoding: binary");
  5549. header("Content-Length: " . @filesize($zip_filename));
  5550. set_time_limit(0);
  5551. @readfile("$zip_filename") || die("File not found.");
  5552. unlink($zip_filename);
  5553. exit;
  5554. }
  5555. /// Function of execute a command in button editor tinymce
  5556. // @param int $fileid Id of file
  5557. function tinymce_ilm ($fileid) {
  5558. $tag_filter = $this->tag_ilm($fileid);
  5559. $output = "<script type='text/javascript'>
  5560. //<![CDATA[
  5561. var tag_filter = '$tag_filter';
  5562. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5563. // all right, insert it
  5564. } else {
  5565. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5566. }
  5567. // window.close();
  5568. //]]>
  5569. </script>\n";
  5570. print $output;
  5571. die();
  5572. }
  5573. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5574. /// Function to add content to the Editor Window
  5575. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5576. // @param int $fileid Id of file
  5577. function editor_ilm ($fileid, $editor) {
  5578. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5579. $output1 = "<script type='text/javascript'>
  5580. //<![CDATA[
  5581. var tag_filter = '$tag_filter';\n";
  5582. if ($editor == 'atto') {
  5583. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5584. } elseif ($editor == 'tinyMCE') {
  5585. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5586. } else
  5587. $output2 = "";
  5588. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5589. window.close();
  5590. //]]>
  5591. </script>\n";
  5592. //D var_dump($output);
  5593. print $output1 . $output2 . $output3;
  5594. die();
  5595. }
  5596. /// Function to add content to the Atto Editor Window
  5597. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5598. // @param int $fileid Id of file
  5599. function atto_ilm ($fileid) {
  5600. global $CFG, $DB;
  5601. $tag_filter = $this->tag_ilm($fileid);
  5602. $output = "<script type='text/javascript'>
  5603. //<![CDATA[
  5604. var tag_filter = '$tag_filter';
  5605. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5606. // all right, insert iLM tag to this editor
  5607. } else {
  5608. // error trying to insert
  5609. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5610. }
  5611. //window.close();
  5612. //]]>
  5613. </script>\n";
  5614. print $output;
  5615. die();
  5616. }
  5617. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5618. // @param string $key Key for return information
  5619. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5620. function get_dir_ilm ($key) {
  5621. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5622. $context = context_course::instance($this->id);
  5623. $dirid = optional_param('dirid', 0, PARAM_INT);
  5624. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5625. if ($dirid == 0) {
  5626. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5627. $dirid = $dir->get_id();
  5628. }
  5629. else {
  5630. $dir = $fs->get_file_by_id($dirid);
  5631. $dir_base = $dir->get_filepath();
  5632. }
  5633. $dir_parent = $dir->get_parent_directory();
  5634. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5635. return $data[$key];
  5636. }
  5637. /// Function for create an new dir
  5638. function new_dir_ilm () {
  5639. global $USER;
  5640. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5641. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5642. $dir_base = $this->get_dir_ilm('dir_base');
  5643. $context = context_course::instance($this->id);
  5644. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5645. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5646. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5647. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5648. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5649. }
  5650. /// Function for delete an dir
  5651. function delete_dir_ilm () { //
  5652. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5653. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5654. $context = context_course::instance($this->id);
  5655. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5656. $dir_parent = $this->get_dir_ilm('dir_parent');
  5657. if ($dir) {
  5658. if ($dir->is_directory()) {
  5659. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5660. foreach ($files_delete as $value)
  5661. $value->delete();
  5662. $dir->delete();
  5663. }
  5664. }
  5665. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5666. die();
  5667. }
  5668. /// Function for rename an dir
  5669. function rename_dir_ilm () {
  5670. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5671. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5672. $context = context_course::instance($this->id);
  5673. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5674. $dir_parent = $this->get_dir_ilm('dir_parent');
  5675. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5676. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5677. if ($dir->is_directory()) {
  5678. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5679. foreach ($files_rename_path as $value)
  5680. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5681. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5682. }
  5683. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5684. die();
  5685. }
  5686. /// Function for move an dir and your content for other dir
  5687. function selected_move_ilm () {
  5688. global $PAGE, $OUTPUT, $CFG;
  5689. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5690. $context = context_course::instance($this->id);
  5691. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5692. $dirid = $this->get_dir_ilm('dirid');
  5693. $dir_base = $this->get_dir_ilm('dir_base');
  5694. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5695. $code_javascript_ilm = "
  5696. <script type='text/javascript'>
  5697. //<![CDATA[
  5698. function getRadiobutton () {
  5699. var radioButtons = document.getElementsByTagName('input');
  5700. var param = '';
  5701. for (var counter=0; counter < radioButtons.length; counter++) {
  5702. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5703. param = radioButtons[counter].value;
  5704. }
  5705. return param;
  5706. }
  5707. function move_selected_ilm () {
  5708. var msgAnswer;
  5709. if (getRadiobutton() != '') {
  5710. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5711. if (msgAnswer)
  5712. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5713. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5714. }
  5715. else
  5716. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5717. }
  5718. function cancel_selected_ilm () {
  5719. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5720. }
  5721. //]]>
  5722. </script>\n";
  5723. $title = get_string('move_files', 'iassign');
  5724. $PAGE->set_title($title);
  5725. $PAGE->set_pagelayout('base');
  5726. print $OUTPUT->header();
  5727. print $OUTPUT->heading($title);
  5728. $dir_paths = array();
  5729. print $OUTPUT->box_start();
  5730. print "<center>";
  5731. foreach ($files_id as $file_id) {
  5732. $file = $fs->get_file_by_id($file_id);
  5733. if ($file) {
  5734. if (!$file->is_directory())
  5735. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5736. else {
  5737. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5738. array_push($dir_paths, $file->get_filepath());
  5739. }
  5740. }
  5741. }
  5742. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5743. if ($dir_base != '/') {
  5744. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5745. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5746. }
  5747. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5748. foreach ($files_tree as $file) {
  5749. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5750. $is_parent = false;
  5751. foreach ($dir_paths as $dir) {
  5752. $path = explode("/", $dir);
  5753. array_pop($path);
  5754. $path[count($path) - 1] = '';
  5755. $path = implode("/", $path);
  5756. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5757. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5758. }
  5759. if ($is_parent == false) {
  5760. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5761. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5762. }
  5763. }
  5764. }
  5765. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5766. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5767. print "</center>";
  5768. print $OUTPUT->box_end();
  5769. print $OUTPUT->footer();
  5770. print $code_javascript_ilm;
  5771. die;
  5772. }
  5773. /// Function for move files for an dir
  5774. function move_files_ilm () {
  5775. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5776. $context = context_course::instance($this->id);
  5777. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5778. $dirid = $this->get_dir_ilm('dirid');
  5779. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5780. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5781. foreach ($files_id as $file_id) {
  5782. $file = $fs->get_file_by_id($file_id);
  5783. if ($file) {
  5784. if ($file->is_directory()) {
  5785. $pathname = explode("/", $file->get_filepath());
  5786. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5787. foreach ($files_move_path as $value) {
  5788. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5789. $value->rename($path_move, $value->get_filename());
  5790. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5791. }
  5792. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5793. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5794. $file->rename($path_move, $file->get_filename());
  5795. } else {
  5796. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5797. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5798. }
  5799. }
  5800. }
  5801. //die;
  5802. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5803. die();
  5804. } // function move_files_ilm()
  5805. /// Function for recover files in use on all activities of a course
  5806. function recover_files_ilm () {
  5807. global $DB, $USER;
  5808. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5809. $courseid = optional_param('id', NULL, PARAM_INT);
  5810. $dirid = $this->get_dir_ilm('dirid');
  5811. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5812. $contextfile = context_course::instance($this->id);
  5813. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5814. foreach ($iassigns as $iassign) {
  5815. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5816. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5817. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5818. $context = context_module::instance($cm->id);
  5819. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5820. if ($files) {
  5821. foreach ($files as $value) {
  5822. $extension = explode(".", $value->get_filename());
  5823. if (!$value->is_directory()) {
  5824. $fileinfo = array('contextid' => $contextfile->id,
  5825. 'component' => 'mod_iassign',
  5826. 'filearea' => 'activity',
  5827. 'itemid' => 0,
  5828. 'filepath' => $this->get_dir_ilm('dir_base'),
  5829. 'userid' => $USER->id,
  5830. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5831. 'license' => 'allrightsreserved',
  5832. 'timecreated' => time(),
  5833. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5834. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5835. }
  5836. }
  5837. } // if ($files)
  5838. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5839. } // foreach ($iassigns as $iassign)
  5840. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5841. die();
  5842. } // function recover_files_ilm()
  5843. /// Auxiliary function the get all files in a given context
  5844. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5845. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5846. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5847. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5848. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5849. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5850. // (NAO s_iassign_statement.file = s_files.id)
  5851. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5852. $dir_base = $this->get_dir_ilm('dir_base');
  5853. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5854. $countf = 0;
  5855. $array_files_id = array(); // all files from this context
  5856. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5857. //$filename = $item_fc->get_filename();
  5858. //$filepath = $item_fc->get_filepath();
  5859. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5860. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5861. // $array_files_aux[] = $item_fc;
  5862. $itemid = $item_fc->get_id();
  5863. if (!in_array($itemid, $array_files_id)) {
  5864. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5865. if ($fileuserid == $userid)
  5866. $filesfrommine[] = $item_fc;
  5867. else
  5868. $filesfromothers[] = $item_fc;
  5869. $array_files_id[] = $itemid;
  5870. $countf++;
  5871. }
  5872. }
  5873. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5874. return $countf;
  5875. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5876. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5877. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5878. function get_all_ilm_files_by_fileid ($fileid) {
  5879. global $DB, $USER;
  5880. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5881. //TODO Criar coluna 'authorid'
  5882. $str_query = "SELECT * FROM {iassign_statement} " .
  5883. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5884. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5885. return $array_iassign_ilm;
  5886. }
  5887. //NN
  5888. //NN
  5889. // Build string with JavaScript code with function to edit/remove/double iLM files
  5890. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5891. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5892. global $CFG;
  5893. $error_files_exists = get_string('error_file_exists', 'iassign');
  5894. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5895. $code_javascript_ilm = "
  5896. <script type='text/javascript'>
  5897. //<![CDATA[
  5898. function preview_ilm (fileid, ilmid) { //JavaScript function
  5899. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5900. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5901. }
  5902. function update_ilm (ilmid, fileid) { //JavaScript function
  5903. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5904. }
  5905. function delete_ilm (ilmid, fileid) { //JavaScript function
  5906. var msgAnswer;
  5907. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5908. if (msgAnswer) {
  5909. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5910. }
  5911. }
  5912. function delete_selected_ilm () { //JavaScript function
  5913. var msgAnswer;
  5914. var param = getCheckbox();
  5915. if (param.join() != '') {
  5916. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5917. if (msgAnswer)
  5918. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5919. }
  5920. else
  5921. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5922. }
  5923. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5924. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5925. }
  5926. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5927. var filenamecopy;
  5928. var i;
  5929. var files = new Array(" . $files_array . ");
  5930. do {
  5931. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5932. } while (filenamecopy == '');
  5933. if (filenamecopy == null)
  5934. return false;\n
  5935. else {
  5936. for (i=0;i<files.length;i++) {
  5937. if (files[i]==filenamecopy) {
  5938. alert('" . $error_files_exists . "');
  5939. return false;\n
  5940. }
  5941. }\n" .
  5942. // @see: function 'duplicate_file_ilm()' above
  5943. "
  5944. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5945. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5946. } // else
  5947. }
  5948. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5949. var filenamecopy;
  5950. var i;
  5951. var files = new Array($files_array);
  5952. do {
  5953. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5954. } while (filenamecopy == '');
  5955. if (filenamecopy == null)
  5956. return false;
  5957. else {
  5958. for (i=0;i<files.length;i++) {
  5959. if (files[i]==filenamecopy) {
  5960. alert('" . $error_files_exists . "');
  5961. return false;
  5962. }
  5963. }
  5964. 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;
  5965. }
  5966. }
  5967. function export_files_ilm () { //JavaScript function
  5968. var param = getCheckbox();
  5969. if (param.join() != '')
  5970. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5971. else
  5972. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5973. }
  5974. function select_all_ilm () { //JavaScript function
  5975. var checkBoxes = document.getElementsByTagName('input');
  5976. var selectAll = document.getElementById('select_all');
  5977. for (var counter=0; counter < checkBoxes.length; counter++) {
  5978. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5979. checkBoxes[counter].checked = selectAll.checked;
  5980. }
  5981. }
  5982. function getCheckbox () { //JavaScript function
  5983. var checkBoxes = document.getElementsByTagName('input');
  5984. var param = new Array();
  5985. for (var counter=0; counter < checkBoxes.length; counter++) {
  5986. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5987. param.push(checkBoxes[counter].value);
  5988. }
  5989. return param;
  5990. }
  5991. function new_dir_ilm () { //JavaScript function
  5992. var dirname = '';
  5993. var i;
  5994. var dirs = new Array(" . $dirs_array . ");
  5995. do {
  5996. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5997. } while (dirname == '');
  5998. if (dirname == null)
  5999. return false;\n
  6000. else {
  6001. for (i=0;i<dirs.length;i++) {
  6002. if (dirs[i]==dirname) {
  6003. alert('" . $error_dir_exists . "');
  6004. return false;\n
  6005. }
  6006. }
  6007. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6008. }
  6009. }
  6010. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6011. var msgAnswer;
  6012. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6013. if (msgAnswer) {
  6014. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6015. }
  6016. }
  6017. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6018. var dirnamecopy;
  6019. var i;
  6020. var dirs = new Array($dirs_array);
  6021. do {
  6022. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6023. } while (dirnamecopy == '');
  6024. if (dirnamecopy == null)
  6025. return false;\n
  6026. else {
  6027. for (i=0;i<dirs.length;i++) {
  6028. if (dirs[i]==dirnamecopy) {
  6029. alert('" . $error_dir_exists . "');
  6030. return false;\n
  6031. }
  6032. }
  6033. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6034. }
  6035. }
  6036. function move_selected_ilm (ilmid) { //JavaScript function
  6037. var param = getCheckbox();
  6038. if (param.join() != '')
  6039. 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();
  6040. else
  6041. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6042. }
  6043. function recover_files_ilm () { //JavaScript function
  6044. var msgAnswer;
  6045. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6046. if (msgAnswer) {
  6047. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6048. }
  6049. }
  6050. window.onload = function() { //JavaScript function
  6051. var xPosition = 0;
  6052. var yPosition = 0;
  6053. element=document.getElementById('new_file');
  6054. while(element) {
  6055. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6056. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6057. element = element.offsetParent;
  6058. }
  6059. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6060. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6061. location.hash = '#new_file';
  6062. };
  6063. //]]>
  6064. </script>\n"; // end of $code_javascript_ilm
  6065. return $code_javascript_ilm;
  6066. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6067. /// List iassign files from course directory
  6068. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6069. function view_files_ilm ($iassign_ilm_class, $extension) {
  6070. global $CFG, $DB, $USER, $OUTPUT;
  6071. $fs = get_file_storage();
  6072. $context = context_course::instance($this->id);
  6073. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6074. $dirid = $this->get_dir_ilm('dirid');
  6075. $dir_base = $this->get_dir_ilm('dir_base');
  6076. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6077. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6078. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6079. $files_array = '';
  6080. foreach ($files_course as $value) {
  6081. if (!$value->is_directory())
  6082. $files_array .= "'" . $value->get_filename() . "',";
  6083. }
  6084. $files_array .= "''";
  6085. $error_files_exists = get_string('error_file_exists', 'iassign');
  6086. $dirs_array = '';
  6087. foreach ($files_course as $value) {
  6088. if ($value->is_directory()) {
  6089. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6090. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6091. }
  6092. }
  6093. $dirs_array .= "''";
  6094. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6095. // TODO Rever o preview pois só deixar ver uma vez.
  6096. $code_javascript_ilm = "
  6097. <script type='text/javascript'>
  6098. //<![CDATA[
  6099. function preview_ilm (fileid, ilmid) {
  6100. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6101. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6102. }
  6103. function update_ilm (ilmid, fileid) {
  6104. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6105. }
  6106. function delete_ilm (ilmid, fileid) {
  6107. var msgAnswer;
  6108. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6109. if (msgAnswer) {
  6110. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6111. }
  6112. }
  6113. function delete_selected_ilm () {
  6114. var msgAnswer;
  6115. var param = getCheckbox();
  6116. if (param.join() != '') {
  6117. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6118. if (msgAnswer)
  6119. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6120. }
  6121. else
  6122. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6123. }
  6124. function add_ilm_iassign (ilmid, filename, fileid) {
  6125. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6126. }
  6127. function duplicate_ilm (ilmid, filename, fileid) {
  6128. var filenamecopy;
  6129. var i;
  6130. var files = new Array($files_array);
  6131. do {
  6132. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6133. } while (filenamecopy == '');
  6134. if (filenamecopy == null)
  6135. return false;\n
  6136. else {
  6137. for (i=0;i<files.length;i++) {
  6138. if (files[i]==filenamecopy) {
  6139. alert('$error_files_exists');
  6140. return false;\n
  6141. }
  6142. }\n" .
  6143. // @see: function 'duplicate_file_ilm()' above
  6144. "
  6145. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6146. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6147. } // else
  6148. }
  6149. function rename_ilm (ilmid, filename, fileid) {
  6150. var filenamecopy;
  6151. var i;
  6152. var files = new Array($files_array);
  6153. do {
  6154. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6155. } while (filenamecopy == '');
  6156. if (filenamecopy == null)
  6157. return false;
  6158. else {
  6159. for (i=0;i<files.length;i++) {
  6160. if (files[i]==filenamecopy) {
  6161. alert('$error_files_exists');
  6162. return false;
  6163. }
  6164. }
  6165. 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;
  6166. }
  6167. }
  6168. function export_files_ilm () {
  6169. var param = getCheckbox();
  6170. if (param.join() != '')
  6171. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6172. else
  6173. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6174. }
  6175. function select_all_ilm () {
  6176. var checkBoxes = document.getElementsByTagName('input');
  6177. var selectAll = document.getElementById('select_all');
  6178. for (var counter=0; counter < checkBoxes.length; counter++) {
  6179. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6180. checkBoxes[counter].checked = selectAll.checked;
  6181. }
  6182. }
  6183. function getCheckbox () {
  6184. var checkBoxes = document.getElementsByTagName('input');
  6185. var param = new Array();
  6186. for (var counter=0; counter < checkBoxes.length; counter++) {
  6187. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6188. param.push(checkBoxes[counter].value);
  6189. }
  6190. return param;
  6191. }
  6192. function new_dir_ilm () {
  6193. var dirname = '';
  6194. var i;
  6195. var dirs = new Array($dirs_array);
  6196. do {
  6197. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6198. } while (dirname == '');
  6199. if (dirname == null)
  6200. return false;\n
  6201. else {
  6202. for (i=0;i<dirs.length;i++) {
  6203. if (dirs[i]==dirname) {
  6204. alert('$error_dir_exists');
  6205. return false;\n
  6206. }
  6207. }
  6208. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6209. }
  6210. }
  6211. function delete_dir_ilm (ilmid, dirid) {
  6212. var msgAnswer;
  6213. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6214. if (msgAnswer) {
  6215. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6216. }
  6217. }
  6218. function rename_dir_ilm (ilmid, dirname, dirid) {
  6219. var dirnamecopy;
  6220. var i;
  6221. var dirs = new Array($dirs_array);
  6222. do {
  6223. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6224. } while (dirnamecopy == '');
  6225. if (dirnamecopy == null)
  6226. return false;\n
  6227. else {
  6228. for (i=0;i<dirs.length;i++) {
  6229. if (dirs[i]==dirnamecopy) {
  6230. alert('$error_dir_exists');
  6231. return false;\n
  6232. }
  6233. }
  6234. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6235. }
  6236. }
  6237. function move_selected_ilm (ilmid) {
  6238. var param = getCheckbox();
  6239. if (param.join() != '')
  6240. 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();
  6241. else
  6242. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6243. }
  6244. function recover_files_ilm () {
  6245. var msgAnswer;
  6246. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6247. if (msgAnswer) {
  6248. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6249. }
  6250. }
  6251. window.onload = function() {
  6252. var xPosition = 0;
  6253. var yPosition = 0;
  6254. element=document.getElementById('new_file');
  6255. while(element) {
  6256. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6257. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6258. element = element.offsetParent;
  6259. }
  6260. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6261. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6262. location.hash = '#new_file';
  6263. };
  6264. //]]>
  6265. </script>\n";
  6266. $output = "";
  6267. $select_all = "";
  6268. $count_files = 0;
  6269. $extensions_allow = array();
  6270. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6271. foreach ($iassign_ilm as $item_iassign_ilm)
  6272. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6273. foreach ($files_course as $value) {
  6274. $filename = $value->get_filename();
  6275. $filepath = $value->get_filepath();
  6276. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6277. $pathname = $pathname[count($pathname) - 1];
  6278. $fileid = $value->get_id();
  6279. $tmp = explode(".", $filename);
  6280. if (count($tmp)>1) // avoid error if the file has no extension
  6281. $filetype = $tmp[1];
  6282. else // probably error...
  6283. $filetype = '';
  6284. $author = $value->get_author();
  6285. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6286. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6287. $extensions = explode(",", $extension);
  6288. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6289. $count_files ++;
  6290. // buscar fileid nas tabelas do iassign
  6291. $list_filein_use = "";
  6292. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6293. if ($iassign_statement_activity_list) {
  6294. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6295. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6296. }
  6297. }
  6298. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6299. if (!$iassign_ilm) {
  6300. $iassign_ilm = new stdClass();
  6301. $iassign_ilm->id = $ilmid;
  6302. }
  6303. // Do not use $var inside "..." - problem with some "unusual" operational system
  6304. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6305. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6306. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6307. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6308. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6309. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6310. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6311. $check_select = "";
  6312. $link_rename = "";
  6313. $link_delete = "";
  6314. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6315. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6316. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6317. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6318. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6319. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6320. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6321. if ($value->get_userid() == $USER->id) {
  6322. if ($iassign_statement_activity_list) {
  6323. $check_select = "";
  6324. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6325. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6326. $link_rename = "";
  6327. } else {
  6328. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6329. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6330. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6331. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6332. }
  6333. }
  6334. if (!in_array($filetype, $extensions_allow)) {
  6335. $link_edit = "";
  6336. $link_add_ilm_iassign = "";
  6337. $link_add_ilm_tinymce = "";
  6338. $link_add_ilm_atto = "";
  6339. $link_filter = "";
  6340. }
  6341. if ($value->is_directory()) {
  6342. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6343. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6344. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6345. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6346. <td><center>$author</center></td>
  6347. <td><center>$timecreated</center></td>
  6348. <td><center>$timemodified</center></td></tr>\n";
  6349. }
  6350. else if ($this->from == 'iassign') {
  6351. $new_id = "";
  6352. $new_class = "";
  6353. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6354. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6355. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6356. }
  6357. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6358. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6359. <td><center>$author</center></td>
  6360. <td><center>$timecreated</center></td>
  6361. <td><center>$timemodified</center></td></tr>\n";
  6362. }
  6363. else if ($this->from == 'block') {
  6364. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6365. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6366. <td><center>$author</center></td>
  6367. <td><center>$timecreated</center></td>
  6368. <td><center>$timemodified</center></td></tr>\n";
  6369. }
  6370. else if ($this->from == 'tinymce') {
  6371. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6372. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6373. <td><center>$author</center></td>
  6374. <td><center>$timecreated</center></td>
  6375. <td><center>$timemodified</center></td></tr>\n";
  6376. }
  6377. else if ($this->from == 'atto') {
  6378. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6379. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6380. <td><center>$author</center></td>
  6381. <td><center>$timecreated</center></td>
  6382. <td><center>$timemodified</center></td></tr>\n";
  6383. }
  6384. }
  6385. }
  6386. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6387. $dir_base = "";
  6388. $header = "";
  6389. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6390. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6391. foreach ($basename as $value) {
  6392. $dir_base .= $value . "/";
  6393. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6394. if ($dir_id) {
  6395. if ($value == "") {
  6396. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6397. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6398. } else {
  6399. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6400. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6401. }
  6402. }
  6403. } // foreach ($basename as $value)
  6404. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6405. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6406. $html .= "
  6407. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6408. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6409. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6410. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6411. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6412. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6413. </table>\n";
  6414. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6415. $html .= "<table width='100%'><tr>\n";
  6416. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6417. if ($count_files != 0) {
  6418. $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";
  6419. $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";
  6420. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6421. }
  6422. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6423. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6424. $html .= "</form>\n";
  6425. print $code_javascript_ilm;
  6426. print $html;
  6427. } // function view_files_ilm($extension)
  6428. } // class ilm_manager
  6429. /// Class to insert of icons
  6430. class iassign_icons {
  6431. static function insert ($icon) {
  6432. global $CFG;
  6433. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6434. return $string;
  6435. }
  6436. }
  6437. /// Class with util functions for plugin manage
  6438. class iassign_utils {
  6439. /// Function to return the filename extension
  6440. // @param string The $filename as an string
  6441. // @return string Return an string (last group after '.')
  6442. static function filename_extension ($filename) {
  6443. if ($filename == null || $filename == '') {
  6444. return null;
  6445. }
  6446. $itens = explode('.', $filename);
  6447. $num = count($itens);
  6448. if ($num < 2) {
  6449. return null;
  6450. }
  6451. return $itens[$num - 1];
  6452. }
  6453. /// Use the PHP class/package ZipArchive to create a Zip file
  6454. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6455. // 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
  6456. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6457. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6458. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6459. $zip = new zip_archive(); //2
  6460. $res = $zip->open($full_path_zip_filename);
  6461. $total_vet = count($vet_student_filename);
  6462. for ($ii=0; $ii<$total_vet; $ii++) {
  6463. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6464. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6465. }
  6466. $ret = $zip->close();
  6467. iassign_utils::download_file($full_path_zip_filename);
  6468. $filenameZip = $zip->filename;
  6469. return array($ret, $zip);
  6470. }
  6471. static function download_file ($zip_filename) {
  6472. header("Pragma: public");
  6473. header("Expires: 0");
  6474. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6475. header("Cache-Control: private", false);
  6476. header("Content-Type: application/zip");
  6477. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6478. header("Content-Transfer-Encoding: binary");
  6479. header("Content-Length: " . @filesize($zip_filename));
  6480. set_time_limit(0);
  6481. @readfile("$zip_filename") || die("File not found.");
  6482. unlink($zip_filename);
  6483. }
  6484. /// Function for format filename remove special caracters
  6485. // @param string $text String for clean
  6486. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6487. // @return string Return an string in clean format
  6488. static function format_filename ($text) {
  6489. if ($text != '.') {
  6490. //D $text = htmlspecialchars(urldecode($text));
  6491. //D echo "locallib.php: format_filename: $text<br/>";
  6492. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6493. $text = json_decode($text)->{current_language()};
  6494. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6495. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6496. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6497. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6498. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6499. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6500. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6501. // E.g. text = "exerc_midpoint.course.geo"
  6502. // 0123456789012345678901234
  6503. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6504. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6505. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6506. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6507. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6508. //$ext = strrpos($text, ".");
  6509. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6510. //$text = str_replace($array1, $array2, $text);
  6511. }
  6512. return $text;
  6513. }
  6514. /// Function to filter characters to the file name to iLM content
  6515. // @param string $text String for clean
  6516. // @param string $ext String ot the extension of the iLM
  6517. // @return string Return an string in clean format
  6518. static function filter_filename_extension ($filename, $ext) {
  6519. if ($filename != '.') {
  6520. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6521. $arrTo = array("_","","","","","","","","","","","","");
  6522. $filename = str_replace($arrFrom, $arrTo, $filename);
  6523. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6524. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6525. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6526. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6527. $index_lastposition = strlen($filenameF);
  6528. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6529. $text = str_replace(".", "_", $text); // erase all other "."
  6530. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6531. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6532. }
  6533. else
  6534. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6535. return $filenameF;
  6536. }
  6537. /// Function for format pathname remove special caracters
  6538. // @param string $text String for clean
  6539. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6540. // @return string Return an string in clean format
  6541. static function format_pathname ($text, $is_lowercase = true) {
  6542. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6543. $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", "-", "_", "", "", "");
  6544. $text = str_replace($array1, $array2, $text);
  6545. if ($is_lowercase)
  6546. $text = strtolower($text);
  6547. return $text;
  6548. }
  6549. /// Function for format file name from iLM original name
  6550. // @param string $text String to build the file neam
  6551. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6552. // @return string Return an string in clean format
  6553. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6554. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6555. $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", "-", "_", "", "", "");
  6556. $index_firstposition_blank = strpos($ilm_name, " ");
  6557. if ($index_firstposition_blank) { // truncate the name!
  6558. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6559. }
  6560. $index_firstposition_dots = strpos($ilm_name, ":");
  6561. if ($index_firstposition_dots) { // truncate the name!
  6562. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6563. }
  6564. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6565. if ($is_lowercase)
  6566. $namefiltered = strtolower($namefiltered);
  6567. return $namefiltered;
  6568. }
  6569. /// Function for insert version in the filename
  6570. // @param string $filename Name of file
  6571. // @return string Return the filename with version
  6572. static function version_filename ($filename) {
  6573. $array_filename = explode('.', $filename);
  6574. if (count($array_filename) > 1)
  6575. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6576. else
  6577. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6578. return $filename;
  6579. }
  6580. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6581. static function remove_code_message ($string) {
  6582. $array = explode("&lt;ia_uc&gt;", $string);
  6583. return $array[0];
  6584. }
  6585. }
  6586. // class iassign_utils
  6587. /// Class with language functions for plugin manage
  6588. class iassign_language {
  6589. /// Function for return text in language or get default language (en)
  6590. // @param string $lang Code of language
  6591. // @param string $description JSON text content all languages
  6592. // @return string Return an string in the language selected
  6593. static function get_description_lang ($lang, $descriptions) {
  6594. $description_lang = "";
  6595. $description = json_decode($descriptions);
  6596. if ($description == null) {
  6597. $description_lang = $descriptions;
  6598. }
  6599. else {
  6600. if (isset($description->{$lang}))
  6601. $description_lang = $description->{$lang};
  6602. else
  6603. if (isset($description->en)) //MOOC2014
  6604. $description_lang = $description->en;
  6605. else //MOOC2014
  6606. $description_lang = "en"; //MOOC2014
  6607. }
  6608. return $description_lang;
  6609. }
  6610. /// Function for return all language supported by iLM
  6611. // @param string $descriptions JSON text content all languages
  6612. // @return string Return as string with all languages
  6613. static function get_all_lang ($descriptions) {
  6614. $langs = "";
  6615. $description = json_decode($descriptions);
  6616. if ($description) {
  6617. foreach ($description as $key => $value) {
  6618. $langs .= $key . " ; ";
  6619. }
  6620. $langs = substr($langs, 0, strlen($langs) - 3);
  6621. }
  6622. return $langs;
  6623. }
  6624. /// Function for convert json in xml //MOOC2014
  6625. // @param string $json JSON text
  6626. // @return string Return as string with xml tags
  6627. static function json_to_xml ($json) {
  6628. $xml = "";
  6629. $json = json_decode($json);
  6630. foreach ($json as $key => $value) {
  6631. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6632. }
  6633. return $xml;
  6634. }
  6635. }
  6636. // class iassign_language
  6637. /// Class with log functions for plugin manage.
  6638. class iassign_log {
  6639. /// Function for insert log event
  6640. // @param string $action Code action of event
  6641. // @param string $information Text for describe action of event
  6642. // @param int $cmid Id of context module
  6643. // @param int $ilmid Id of iLM
  6644. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6645. global $COURSE, $CFG, $USER, $DB;
  6646. $newentry = new stdClass();
  6647. $newentry->time = time();
  6648. $newentry->userid = $USER->id;
  6649. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6650. $newentry->course = $COURSE->id;
  6651. $newentry->cmid = $cmid;
  6652. $newentry->ilmid = $ilmid;
  6653. $newentry->action = $action;
  6654. $newentry->info = $information;
  6655. $newentry->language = current_language();
  6656. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6657. if (ini_get("browscap") && function_exists('get_browse')) {
  6658. $browser = get_browse(null, true);
  6659. $newentry->javascript = $browser['javascript'];
  6660. $newentry->java = $browser['javaapplets'];
  6661. }
  6662. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6663. print_error('error_add_log', 'iassign');
  6664. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6665. } // class iassign_log