locallib.php 424 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.5 2021/12/28
  7. * + Detail to fix order o activities inside a block ('iassign_statement.position' - old instalation could generate order error)
  8. *
  9. * - v 4.9.4 2020/05/28
  10. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  11. *
  12. * - v 4.9.3 2020/01/16
  13. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  14. *
  15. * - v 4.9.2 2019/03/13
  16. * + Several fixes to allow iLM under HTML stack
  17. *
  18. * - v 4.9.1 2017/11/02
  19. * + 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")
  20. * + 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)'
  21. *
  22. * - v 4.9 2017/03/13
  23. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  24. *
  25. * - v 4.8 2016/05/12
  26. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  27. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  28. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  29. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  30. * replaced by
  31. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  32. * - v 4.7 2016/02/17
  33. * + 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(...)')
  34. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  35. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  36. * + 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)
  37. * + 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'
  38. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  39. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  40. *
  41. * --------------- (code bellow was used at our MOOC 2014)
  42. * - v 4.6 2014/02/25
  43. * + Fix bugs in filter function for open applets.
  44. * - v 4.5 2014/02/24
  45. * + Fix bugs in params.
  46. * + Insert new param type.
  47. * - v 4.4 2014/01/24
  48. * + Allow select type of params.
  49. * + Insert the use of applet params specific for activities.
  50. * - v 4.3 2014/01/23
  51. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  52. * - v 4.2 2016/02/13
  53. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  54. * --------------- (above code used at our MOOC 2014)
  55. *
  56. * - v 4.1 2013/12/13
  57. * + Insert log in iAssign actions.
  58. * + 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).
  59. * + Insert class for Log actions in system.
  60. * - v 4.0 2013/10/31
  61. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  62. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  63. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  64. * - v 3.9 2013/10/25
  65. * + Insert support of upgrade iLM.
  66. * + Insert support for more than one extension in iLM.
  67. * + Fix bugs in verion control.
  68. * - v 3.8 2013/09/19
  69. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  70. * - v 3.7 2013/09/12
  71. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  72. * + 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).
  73. * - v 3.6 2013/09/05
  74. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  75. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  76. * + Change tag APPLET in function ilm_settings::view_ilm.
  77. * - v 3.5 2013/08/26
  78. * + Fix bug in download package iassign without answers (iassign::report).
  79. * - v 3.4 2013/08/23
  80. * + Fix bug in export package iassign.
  81. * - v 3.3 2013/08/22
  82. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  83. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  84. * - v 3.2 2013/08/21
  85. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  86. * + Change functions for import files for ilm_manager.php.
  87. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  88. * - v 3.1 2013/08/15
  89. * + Change return file selected (ilm_manager::add_ilm).
  90. * + 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).
  91. * - v 3.0 2013/08/02
  92. * + 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).
  93. * - v 2.9 2013/08/01
  94. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  95. * - v 2.8 2013/07/25
  96. * + Insert the activity name in header of view (activity::view_dates).
  97. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  98. * - v 2.7 2013/07/24
  99. * + Create link previous and next for student view in one activity (activity::view_dates).
  100. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  101. * - v 2.6 2013/07/23
  102. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  103. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  104. * - v 2.5 2013/07/12
  105. * + 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).
  106. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  107. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  108. *
  109. * @author Patricia Alves Rodrigues
  110. * @author Leônidas O. Brandão
  111. * @contributor Igor Moreira Félix (2018-)
  112. * @contributor Márcio de Lima Passos (2014)
  113. * @version v 4.9.2 2019/03/13
  114. * @version v 4.8 2016/05/12
  115. * @package mod_iassign_lib
  116. * @since 2010/09/27
  117. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  118. *
  119. * <b>License</b>
  120. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  121. */
  122. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  123. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  124. //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"'
  125. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  126. /**
  127. * Standard base class for all iAssign
  128. */
  129. class iassign {
  130. var $cm;
  131. var $course;
  132. var $iassign;
  133. var $striassign;
  134. var $striassigns;
  135. var $context;
  136. var $activity;
  137. var $iassign_up;
  138. var $iassign_down;
  139. var $action;
  140. var $iassign_submission_current;
  141. var $userid_iassign;
  142. var $bottonPost;
  143. var $write_solution;
  144. var $view_iassign;
  145. // 3.1 update PHP 7.0 compatibility for all moodle versions
  146. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  147. /// Constructor for the base iassign class
  148. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  149. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  150. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  151. function __construct ($iassign, $cm, $course) {
  152. global $COURSE, $CFG, $USER, $DB;
  153. $botton = optional_param('botton', NULL, PARAM_TEXT);
  154. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  155. if (!is_null($botton))
  156. $USER->iassignEdit = $botton;
  157. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  158. // 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'
  159. $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"
  160. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  161. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  162. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  163. $this->action = optional_param('action', NULL, PARAM_TEXT);
  164. $this->cm = $cm;
  165. $this->context = context_module::instance($this->cm->id);
  166. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  167. $this->userid_iassign = $USER->id;
  168. if ($course) {
  169. $this->course = $course;
  170. }
  171. else if ($this->cm->course == $COURSE->id) {
  172. $this->course = $COURSE;
  173. }
  174. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  175. print_error('invalidid', 'iassign');
  176. }
  177. $this->coursecontext = context_course::instance($this->course->id);
  178. if ($iassign) {
  179. $this->iassign = $iassign;
  180. }
  181. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  182. print_error('invalidid', 'iassign');
  183. }
  184. $USER->context = context_module::instance($this->cm->id);
  185. $USER->cm = $this->cm->id;
  186. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  187. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  188. $this->context = context_module::instance($this->cm->id);
  189. $this->striassign = get_string('modulename', 'iassign');
  190. $this->striassigns = get_string('modulenameplural', 'iassign');
  191. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  192. $this->bottonPost = 0;
  193. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  194. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  195. $this->view();
  196. } // function __construct($iassign, $cm, $course)
  197. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  198. // This method provides the page to view each iLM with any interactive activity
  199. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  200. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  201. global $USER, $DB, $OUTPUT;
  202. // $iassign_statementid = $this->iassign->iassign_statementid;
  203. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  204. $iassign_statementid = $this->activity->get_activity()->id;
  205. else
  206. $iassign_statementid = "";
  207. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  208. // If this user has no capability to View 'iassign': stop here
  209. require_capability('mod/iassign:view', $this->context);
  210. // Trigger module view event
  211. $event = \mod_iassign\event\course_module_viewed::create(array(
  212. 'objectid' => $this->iassign->id,
  213. 'context' => $this->context
  214. ));
  215. $event->add_record_snapshot('course', $this->course);
  216. $event->trigger();
  217. if ($this->action) { // when student do/redo activity or teacher see student solution
  218. $this->action(); // calls '$this->view_iLM();'
  219. }
  220. else {
  221. print $OUTPUT->header();
  222. $this->view_iassigns(); // show the iLM with the content
  223. print $OUTPUT->footer();
  224. }
  225. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  226. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //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" }
  229. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  230. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  231. //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" }
  232. //D else echo "Apagou!<br/>";
  233. die();
  234. } // function view()
  235. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  236. function action () {
  237. global $USER;
  238. // action:
  239. // up - move up activity (mover atividade para cima)
  240. // down - move down activity (mover atividade para baixo)
  241. // visible - view/hide activity (exibir/ocultar atividade)
  242. // delete - delete activity (excluir atividade)
  243. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  244. // deleteno - does not erase activity (não apaga atividade)
  245. // add - add activity (adicionar atividade)
  246. // edit - edit activity (modificar atividade)
  247. $action_iassign = array(
  248. 'newcomment' => '$this->add_comment();',
  249. 'view' => '$this->view_iassign_current();',
  250. 'get_answer' => '$this->get_answer();',
  251. 'repeat' => '$this->view_iassign_current();',
  252. 'overwrite' => '$this->get_answer();',
  253. 'stats_student' => '$this->stats_students();',
  254. 'download_answer' => '$this->export_file_answer();',
  255. 'download_all_answer' => '$this->export_package_answer();',
  256. 'notifications' => '$this->view_notifications();');
  257. $action_iassign_limit = array(
  258. 'view' => '$this->view_iassign_current();',
  259. //'newcomment' => '$this->get_answer();',
  260. 'viewsubmission' => '$this->view_iassign_current();',
  261. 'edit_status' => '$this->edit_status();',
  262. 'edit_grade' => '$this->edit_grade();',
  263. 'export_csv' => '$this->export_csv();',
  264. 'report' => '$this->report();',
  265. 'print' => '$this->report();',
  266. 'stats' => '$this->stats();',
  267. 'printstats' => '$this->stats();');
  268. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  269. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  270. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  271. 'visible' => '$this->activity->visible_iassign($this->return);',
  272. 'delete' => '$this->activity->delete($this->return);',
  273. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  274. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  275. 'add' => '$this->add_edit_iassign();',
  276. 'edit' => '$this->add_edit_iassign();',
  277. 'get_answer' => '$this->get_answer();',
  278. 'duplicate_activity' => '$this->duplicate_activity();',
  279. 'move_activity' => '$this->move_activity();',
  280. 'auto_evaluate' => '$this->auto_evaluate();',
  281. 'all_submissions' => '$this->all_submissions();',
  282. 'delete_submissions' => '$this->delete_submissions();',
  283. 'download_submissions' => '$this->download_submissions();',
  284. 'open_individual_submission' => '$this->open_individual_submission();',
  285. 'get_individual_submission' => '$this->get_individual_submission();',
  286. 'get_student_submission' => '$this->get_student_submission();',
  287. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  288. 'post_auto_eval_result' => '$this->post_auto_eval_result();',
  289. 'import_activity' => '$this->import_activity();',
  290. 'import_activity_confirm' => '$this->import_activity_confirm();'
  291. );
  292. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  293. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  294. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  295. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  296. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  297. }
  298. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  299. eval($action_iassign_limit[$this->action]);
  300. }
  301. else { // Student reaches this point
  302. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  303. // Arrive here with: "get_answer"; "view"
  304. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  305. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  306. }
  307. } // function action()
  308. /// This method prints the student submission to a specific exercise
  309. function get_student_submission () {
  310. global $DB;
  311. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  312. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  313. if (!$student || !$exercise) exit;
  314. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  315. if ($iassign_submission)
  316. print($iassign_submission->answer);
  317. die();
  318. }
  319. /// This method prints the teacher exercise
  320. function get_teacher_exercise () {
  321. global $DB, $COURSE;
  322. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  323. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  324. $fs = get_file_storage(); // Get reference to all files in Moodle data
  325. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  326. //2021/12: $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  327. foreach ($files as $file) {
  328. if ($file->get_filename() != ".") {
  329. print($file->get_content());
  330. }
  331. }
  332. die();
  333. }
  334. /// This method receives the data from auto_eval event
  335. /// @see auto_evaluate()
  336. function post_auto_eval_result () {
  337. global $COURSE, $CFG, $USER, $DB;
  338. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  339. exit;
  340. //$exercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  341. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  342. $student = optional_param('student', -1, PARAM_INT);
  343. $grade = optional_param('grade', 0, PARAM_FLOAT);
  344. // 1: Recuperar a nota atual:
  345. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  346. // 2: Atualizar a tabela:
  347. $update_entry = new stdClass();
  348. $update_entry->id = $actual->id;
  349. $update_entry->previous_grade = $actual->grade;
  350. $update_entry->grade = $grade;
  351. // Update the iassign_submission
  352. $DB->update_record("iassign_submission", $update_entry);
  353. }
  354. /// Function to help download all_submissions files
  355. function download_submissions_help ($list) {
  356. global $DB, $CFG, $OUTPUT;
  357. // Get list of iLMs
  358. $ilm_list = $DB->get_records("iassign_ilm");
  359. // Get list of enrolled students:
  360. $params_temp = array('shortname' => 'student');
  361. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  362. $context = context_course::instance($this->course->id);
  363. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  364. $students_list = $DB->get_records_sql(
  365. "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_temp);
  366. $json_obj = new stdclass();
  367. $json_obj->submissions = [];
  368. $csvfields = [];
  369. $csvfields[] = 'submissionid';
  370. $csvfields[] = 'file';
  371. $csvfields[] = 'filesize';
  372. $csvfields[] = 'timestamp';
  373. $csvfields[] = 'humandate';
  374. $csvfields[] = 'grade';
  375. $csvfields[] = 'userid';
  376. $csvfields[] = 'exerciseid';
  377. $json_obj->submissions[] = $csvfields;
  378. $exercise_dir = [];
  379. $exercises_list = [];
  380. foreach ($list as $item) {
  381. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  382. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  383. $exercises_list[] = $temp;
  384. $exercise_dir[] = $temp->id;
  385. }
  386. }
  387. $student_dir = [];
  388. $students_list = [];
  389. foreach ($list as $item) {
  390. if (!in_array($item->userid, $student_dir)) {
  391. $temp = $DB->get_record("user", array("id" => $item->userid));
  392. $students_list[] = $temp;
  393. $student_dir[] = $temp->id;
  394. }
  395. }
  396. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  397. //TODO: tem que criar moodledata/temp/iassign_files
  398. // Create $CFG->dataroot/temp/iassign_files
  399. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  400. if (!file_exists($tempfilespath)) {
  401. mkdir($tempfilespath, 0777, true);
  402. }
  403. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  404. if (!file_exists($iassignfilespath)) {
  405. mkdir($iassignfilespath, 0777, true);
  406. }
  407. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  408. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  409. if (!file_exists($diretorio)) {
  410. echo 'Não foi possível criar o diretório para preparar o arquivo com as submissões. Possivelmente o caminho está bloqueado para escrita.';
  411. exit;
  412. }
  413. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  414. $zip = new zip_archive(); // create ZIP
  415. if (!$zip->open($zip_filename)) {
  416. echo 'Não foi possível criar o arquivo zip com as submissões dos alunos, pois o diretório no servidor está bloqueado para escrita: ' . $diretorio;
  417. exit;
  418. }
  419. ;
  420. foreach ($exercises_list as $exercise) {
  421. $dir_ex = iassign_utils::format_filename($exercise->name);
  422. $zip->add_directory($dir_ex);
  423. $extension_ilm = '';
  424. foreach ($ilm_list as $ilm) {
  425. if ($exercise->iassign_ilmid == $ilm->id) {
  426. $extension_ilm = $ilm->extension;
  427. break;
  428. }
  429. }
  430. foreach ($students_list as $student) {
  431. $individual_dir =
  432. $dir_ex . DIRECTORY_SEPARATOR .
  433. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  434. $zip->add_directory($individual_dir);
  435. $i = 1;
  436. foreach($list as $item) {
  437. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  438. $date = new DateTime();
  439. $date->setTimestamp($item->timecreated);
  440. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  441. $zip->add_file_from_string($new_file, $item->answer);
  442. $temp_json = [];
  443. $temp_json[] = intval($item->id);
  444. $temp_json[] = $new_file;
  445. $temp_json[] = strlen($new_file);
  446. $temp_json[] = intval($item->timecreated);
  447. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  448. $temp_json[] = doubleval($item->grade);
  449. $temp_json[] = intval($item->userid);
  450. $temp_json[] = intval($exercise->id);
  451. $json_obj->submissions[] = $temp_json;
  452. }
  453. }
  454. }
  455. }
  456. $csv_str = "";
  457. foreach($json_obj->submissions as $sub) {
  458. $csv_str .= $this->csvstr($sub) . "\n";
  459. }
  460. $zip->add_file_from_string('index.csv', $csv_str);
  461. $zip->close();
  462. iassign_utils::download_file($zip_filename);
  463. exit;
  464. }
  465. function csvstr(array $fields) : string {
  466. $f = fopen('php://memory', 'r+');
  467. if (fputcsv($f, $fields) === false) {
  468. return false;
  469. }
  470. rewind($f);
  471. $csv_line = stream_get_contents($f);
  472. return rtrim($csv_line);
  473. }
  474. /// Download submissions from table iassign_allsubmissions
  475. function download_submissions () {
  476. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  477. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  478. exit;
  479. $type = optional_param('type', NULL, PARAM_TEXT);
  480. $item = optional_param('item', NULL, PARAM_TEXT);
  481. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  482. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  483. $sub_list = [];
  484. if ($type == 'individual') {
  485. $sub_list[] = $DB->get_record(
  486. 'iassign_allsubmissions', array('id' => $item));
  487. } elseif ($type == 'student') {
  488. $sub_list = $DB->get_records(
  489. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  490. } elseif ($type == 'exercise') {
  491. $sub_list = $DB->get_records(
  492. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  493. } elseif ($type == 'block') {
  494. $exercises_in_block = $DB->get_records(
  495. 'iassign_statement', array('iassignid' => $iassign_id));
  496. foreach ($exercises_in_block as $exercise) {
  497. $temp = $DB->get_records(
  498. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  499. $sub_list = array_merge($sub_list, $temp);
  500. }
  501. }
  502. $this->download_submissions_help($sub_list);
  503. }
  504. /// Delete submissions in table iassign_allsubmissions
  505. function delete_submissions () {
  506. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  507. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  508. exit;
  509. $type = optional_param('type', NULL, PARAM_TEXT);
  510. $item = optional_param('item', NULL, PARAM_TEXT);
  511. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  512. if ($type == 'individual') {
  513. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  514. } elseif ($type == 'student') {
  515. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  516. } elseif ($type == 'exercise') {
  517. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  518. }
  519. }
  520. function get_individual_submission () {
  521. global $DB, $USER;
  522. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  523. exit;
  524. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  525. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  526. print $submission->answer;
  527. }
  528. /// Open individual submission
  529. function open_individual_submission () {
  530. global $DB, $USER, $CFG;
  531. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  532. exit;
  533. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  534. $id = $this->cm->id;
  535. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  536. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  537. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  538. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  539. $all_submissions = $DB->get_records('iassign_allsubmissions',
  540. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  541. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  542. $previous = null;
  543. $next = null;
  544. $i = 0;
  545. $found = false;
  546. foreach($all_submissions as $individual) {
  547. if (!$found && $individual->id != $submissionid) {
  548. $previous = $individual;
  549. }
  550. if ($found) {
  551. $next = $individual;
  552. break;
  553. }
  554. if ($individual->id === $submissionid) {
  555. $found = true;
  556. }
  557. $i++;
  558. }
  559. print '<center>';
  560. print '<table cellpading=5 cellspacing=5 style="padding-bottom: 2rem;font-size: 1.1em;"><tr><td>' . get_string('exercise', 'iassign') . ':</td><td>' . $atual_statement->name . '</td></tr>';
  561. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>';
  562. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>';
  563. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>';
  564. print '</table>';
  565. if ($previous) {
  566. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  567. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  568. } else {
  569. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  570. }
  571. print ' (' . $i . '/' . count($all_submissions) . ')';
  572. if ($next) {
  573. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  574. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  575. } else {
  576. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  577. }
  578. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  579. //array("type" => "editor_new", "notSEND" => "true")
  580. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  581. print '</center>';
  582. } // function open_individual_submission()
  583. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - inicio 1
  584. function import_activity_confirm () {
  585. global $USER, $DB;
  586. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  587. exit;
  588. if (!isset($_REQUEST['statements'])) exit;
  589. $iassign_destiny = $this->iassign->id;
  590. $activities_list = $_REQUEST['statements'];
  591. foreach($activities_list as $activity) {
  592. $activity_source = $DB->get_record('iassign_statement', array('id' => $activity));
  593. $activity_source->id = 0;
  594. $iassign_id_from = $activity_source->iassignid;
  595. $filesid_from = $activity_source->filesid;
  596. $activity_source->iassignid = $iassign_destiny;
  597. $author = $DB->get_record("user", array('id' => $USER->id));
  598. $activity_source->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  599. $activity_source->author_modified = $activity_source->author_modified_name;
  600. if ($id_ = $DB->insert_record("iassign_statement", $activity_source)) {
  601. $fs = get_file_storage();
  602. // Duplicate activity file
  603. $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
  604. print 'Arquivos a serem copiados: ';
  605. print_r($files_ids);
  606. foreach ($files_ids as $fileid) {
  607. $source_file = $fs->get_file_by_id($fileid->id);
  608. $newfile = $fs->create_file_from_storedfile(array('contextid' => $this->context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $source_file);
  609. $updateentry = new stdClass();
  610. $updateentry->id = $id_;
  611. $updateentry->filesid = $id_;
  612. // Update the duplicated iLM iAssign with new file id
  613. $DB->update_record("iassign_statement", $updateentry);
  614. }
  615. }
  616. }
  617. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->context->id));
  618. $str_index = count($activities_list) > 1 ? 'import_activities_success' : 'import_activity_success';
  619. redirect($this->return, get_string($str_index, 'iassign'), null, \core\output\notification::NOTIFY_SUCCESS);
  620. exit;
  621. }
  622. function import_activity () {
  623. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  624. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  625. exit;
  626. print '<script>
  627. function verify_selection () {
  628. document.getElementById("msg-error").classList.add("d-none");
  629. var checkboxes = document.getElementsByName("statements[]");
  630. for(var i = 0; i < checkboxes.length; i++)
  631. if (checkboxes[i].checked) return true;
  632. document.getElementById("msg-error").classList.remove("d-none");
  633. return false;
  634. }
  635. </script>';
  636. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id, 'action' => 'import_activity_confirm'));
  637. print $OUTPUT->header();
  638. $this->print_main_menu();
  639. print '<h2 class="m-b-2 mt-4">' . get_string('import_activity', 'iassign') . '</h2>';
  640. print '<form action="'.$destiny_url.'" method="post" onsubmit="return verify_selection()">';
  641. $courses_as_teacher = $this->get_courses_enroled_as_teacher($USER->id);
  642. foreach ($courses_as_teacher as $course) {
  643. print '<a href="#item-'.$course->id.'" class="list-group-item list-group-item-action h5" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> ' . $course->fullname . ' </a>';
  644. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$course->id.'">';
  645. $iassigns = $this->get_iassign_items_by_course($course->id);
  646. if ($iassigns) {
  647. foreach ($iassigns as $iassign) {
  648. print '<a href="#item-'.$course->id.'-'.$iassign->id.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'><i class="fa fa-caret-right"></i> '.$iassign->name.'</a>';
  649. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$course->id.'-'.$iassign->id.'">';
  650. $statements = $this->get_iassign_statement_by_iassign($iassign->id);
  651. print '<table class="table table-hover">';
  652. if ($statements) {
  653. foreach ($statements as $statement) {
  654. print '<tr><td> <div class="form-check"> <input class="form-check-input" name="statements[]" type="checkbox" value="'.$statement->id.'" id="statement-' . $statement->id . '">';
  655. print '<label class="form-check-label w-100" for="statement-' . $statement->id . '">' . $statement->name;
  656. print '</label></div></td></tr>';
  657. }
  658. }
  659. else {
  660. print '<tr><td>' . get_string('no_activity', 'iassign') . '</td></tr>';
  661. }
  662. print '</table></div>';
  663. }
  664. }
  665. else {
  666. print '<div class="p-2">' . get_string('import_statement_empty', 'iassign').'</div>';
  667. }
  668. print '</div>';
  669. }
  670. print '<div class="text-center"><button type="submit" class="btn btn-primary mt-2">Confirmar</button></div>';
  671. print '<div class="text-center text-danger d-none" id="msg-error">'.get_string('import_statement_no_exercise', 'iassign').'</div>';
  672. print "</form>\n";
  673. print $OUTPUT->footer();
  674. }
  675. function get_iassign_items_by_course ($courseid) {
  676. global $DB;
  677. return $DB->get_records("iassign", array("course" => $courseid));
  678. }
  679. function get_iassign_statement_by_iassign ($iassignid) {
  680. global $DB;
  681. return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  682. }
  683. function get_courses_enroled_as_teacher($userid) {
  684. $all_enroled = enrol_get_users_courses($userid);
  685. $return = array();
  686. foreach ($all_enroled as $enroled) {
  687. $context_course = context_course::instance($enroled->id);
  688. if (has_capability('mod/iassign:runautoevaluate', $context_course, $userid, false) ) {
  689. array_push($return, $enroled);
  690. }
  691. }
  692. return $return;
  693. }
  694. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - final 1
  695. /// Manage all submissions in exercises to table iassign_allsubmissions
  696. function all_submissions () {
  697. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  698. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  699. exit;
  700. print $OUTPUT->header();
  701. $this->print_main_menu();
  702. $id = $this->cm->id;
  703. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  704. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  705. print '
  706. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  707. <div class="modal-dialog modal-dialog-centered" role="document">
  708. <div class="modal-content">
  709. <div class="modal-header">
  710. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  711. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  712. <span aria-hidden="true">&times;</span>
  713. </button>
  714. </div>
  715. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  716. <div class="modal-footer">
  717. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  718. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  719. </div>
  720. </div>
  721. </div>
  722. </div>'; // "
  723. print '
  724. <script>
  725. var sub_type;
  726. var sub_item;
  727. var sub_el;
  728. var sub_exercise;
  729. function delete_submission (type, item, el, exercise = 0) {
  730. sub_type = type;
  731. sub_item = item;
  732. sub_exercise = exercise;
  733. sub_el = el.closest("tr");
  734. if (!sub_el) sub_el = el.closest("a");
  735. $("#modalConfirm").modal();
  736. }
  737. function confirm_delete () {
  738. var url = "'.$enderecoPOST.'&action=delete_submissions";
  739. var xhttp = new XMLHttpRequest();
  740. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  741. xhttp.send();
  742. $("#modalConfirm").modal("hide");
  743. if ($(sub_el).attr("href"))
  744. $($(sub_el).attr("href")).remove();
  745. if (sub_el) sub_el.remove();
  746. }
  747. function download_submission(type, item, exercise = 0, iassign = 0) {
  748. var url = "'.$enderecoPOST.'&action=download_submissions";
  749. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  750. document.location = url;
  751. }
  752. function open_submission(item) {
  753. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  754. var poupup = window.open(url, "popup", "width=900,height=900");
  755. }
  756. </script>' . chr(13); // '
  757. // Get list of exercises in the instance:
  758. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  759. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  760. print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
  761. print '<i onclick="download_submission(\'block\', 0, 0, '.$iassignid.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.5rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> </h2>';
  762. // Get list of enrolled students:
  763. $params_temp = array('shortname' => 'student');
  764. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  765. $context = context_course::instance($this->course->id);
  766. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  767. $students_list = $DB->get_records_sql(
  768. "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_temp);
  769. print '<div>';
  770. foreach ($exercises_list as $exercise) {
  771. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  772. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  773. print '
  774. <a href="#item-'.$exercise->id.'" class="list-group-item list-group-item-action h4" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> '
  775. . $exercise->name
  776. . ' - ' . $iassign_ilm->name
  777. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  778. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  779. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  780. . $exercise->id .')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> '
  781. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  782. . '</a>';
  783. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  784. foreach ($students_list as $student) {
  785. $total = 0;
  786. $student_submissions = [];
  787. foreach ($submissions_list as $submission) {
  788. if ($submission->userid == $student->userid) {
  789. $student_submissions[] = $submission;
  790. $total++;
  791. }
  792. }
  793. print '<a href="#item-'.$exercise->id.'-'.$student->userid.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'>
  794. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  795. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  796. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  797. . '<i onclick="event.stopPropagation(); download_submission(\'student\', '.$student->userid.', '.$exercise->id.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.3rem; cursor: pointer; margin-left: 1rem; margin-top: .1rem;" aria-hidden="true"></i> '
  798. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  799. . ' </a>';
  800. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  801. print '<table class="table table-striped table-hover"><thead>
  802. <tr>
  803. <th scope="col">#</th>
  804. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  805. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  806. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  807. </tr>
  808. </thead><tbody>'; // "
  809. $i = 1;
  810. foreach ($student_submissions as $individual) {
  811. $date = new DateTime();
  812. $date->setTimestamp($individual->timecreated);
  813. print '<tr>';
  814. print '<td>'.$i++.'</td>';
  815. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  816. print '<td>'.$individual->grade.'</td>';
  817. print '<td>
  818. <i onclick="open_submission('.$individual->id.')" class="fa fa-external-link" style="color:#1177d1; cursor: pointer; font-size: 1.2rem; margin-right: .5rem;" aria-hidden="true"></i>
  819. <i onclick="download_submission(\'individual\', '.$individual->id.')" class="fa fa-download" style="color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-right: .5rem;" aria-hidden="true"></i>
  820. <i class="fa fa-times" onclick="delete_submission(\'individual\', '.$individual->id.', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; " aria-hidden="true"></i></td>';
  821. print " </tr>\n";
  822. }
  823. print '</tbody></table>';
  824. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  825. print '</div>';
  826. }
  827. print '</div>';
  828. }
  829. print '</div>';
  830. print $OUTPUT->footer();
  831. } // function all_submissions()
  832. /// This method runs activities auto evaluation in teacher area
  833. function auto_evaluate () {
  834. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  835. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  836. exit;
  837. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  838. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  839. // Get list of exercises in the instance:
  840. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  841. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  842. // Get list of enrolled students:
  843. $params_temp = array('shortname' => 'student');
  844. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  845. $context = context_course::instance($this->course->id);
  846. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  847. $students_list = $DB->get_records_sql(
  848. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  849. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  850. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  851. print $OUTPUT->header();
  852. $this->print_main_menu();
  853. print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  854. print '<ul style="list-style-type: none; margin: 1em;">';
  855. foreach ($exercises_list as $exercise) {
  856. $matches = [];
  857. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  858. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  859. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  860. if ($matches[0][0]) {
  861. 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>';
  862. } else {
  863. 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>';
  864. }
  865. } else {
  866. if ($matches[0][0]) {
  867. 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>';
  868. } else {
  869. 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>';
  870. }
  871. }
  872. }
  873. print '</ul>
  874. <center>
  875. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  876. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  877. <div id="evaluate_message" style="color: red"></div>
  878. <div id="evaluate_alerts"></div>
  879. <div>
  880. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  881. <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>
  882. </div>
  883. </center>'; // close "
  884. print ' </div>' . "\n";
  885. print ' <script>';
  886. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  887. print ' var submissions = [';
  888. // Get list of student id have submit for each exercise:
  889. foreach ($exercises_list as $exercise) {
  890. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  891. print '
  892. {
  893. "exerciseid": "' . $exercise->id . '",
  894. "grade": ' . $exercise->grade . ',
  895. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  896. "submited": ['; // "
  897. $params_temp = array('iassign_statementid' => $exercise->id);
  898. $submited = $DB->get_records_sql( // Get userid and his grade
  899. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  900. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  901. foreach ($submited as $ss) {
  902. print($ss->userid . ',');
  903. }
  904. print '],';
  905. print '"allgrades": [';
  906. foreach ($submited as $ss) {
  907. print( $ss->grade . ',');
  908. }
  909. print ']
  910. },'; // close "
  911. } // foreach ($exercises_list as $exercise)
  912. print " ];\n";
  913. print '
  914. var total_submissions = 0;
  915. var selected_exercises;
  916. var count_steps;
  917. var value_by_step;
  918. var stoped = false;
  919. var time_interval = 5000;
  920. var var_interval;
  921. function add_hover_th (id_th, id_li) { //AJAX
  922. $("#" + id_th).hover(function() {
  923. $("#" + id_li).css("background-color", "#d9d8d8");
  924. $(this).css("background-color", "#d9d8d8");
  925. }, function() {
  926. $("#" + id_li).css("background-color", "");
  927. $(this).css("background-color", "");
  928. });
  929. }
  930. function start_evaluation () {
  931. stoped = false;
  932. //AJAX
  933. $("#progress_bar").css("display", "none");
  934. $("#evaluate_message").text("");
  935. $("#evaluate_alerts").text("");
  936. $(".added-col").remove();
  937. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  938. selected_exercises = [];
  939. var c = 0;
  940. for (var i = 0; i < exercises.length; i++) {
  941. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  942. selected_exercises[c++] = exercises[i];
  943. }
  944. }
  945. if (selected_exercises.length == 0) {
  946. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  947. return;
  948. } else {
  949. $("input:checkbox").attr("disabled", true); //AJAX
  950. for (var i = 0; i < selected_exercises.length; i++) {
  951. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  952. //AJAX
  953. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  954. $("#table-results tbody tr").each(function(e) {
  955. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  956. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  957. });
  958. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  959. }
  960. //AJAX
  961. $("#button_start").prop("disabled", true);
  962. $("#button_stop").prop("disabled", false);
  963. $("#progress_bar").css("display", "block");
  964. }
  965. total_submissions = selected_exercises.length * students.length;
  966. count_steps = 0;
  967. value_by_step = 100/total_submissions;
  968. actual_exercise = 0;
  969. actual_student = 0;
  970. actual_submission = 0;
  971. get_original_propositions();
  972. var_interval = setInterval(verifyBreak, time_interval);
  973. } // function start_evaluation()
  974. var actual_exercise;
  975. var actual_student;
  976. var actual_submission;
  977. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  978. function run_individual_evaluation () {
  979. if (stoped) return;
  980. // Verify if student really sent his answer
  981. var found = false;
  982. for (var j = 0; j < submissions.length; j++) {
  983. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  984. for (var k = 0; k < submissions[j].submited.length; k++) {
  985. if (students[actual_student] == submissions[j].submited[k]) {
  986. found = true;
  987. break;
  988. }
  989. }
  990. break;
  991. }
  992. }
  993. if (found == false) {
  994. postResultAutoEval();
  995. } else {
  996. // If it was sent, search it...
  997. var final_url = "";
  998. 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];
  999. for (var j = 0; j < submissions.length; j++) {
  1000. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  1001. final_url = submissions[j].ilm;
  1002. break;
  1003. }
  1004. }
  1005. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  1006. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1007. window.frames["ifrm"].location=final_url;
  1008. }
  1009. } // function run_individual_evaluation()
  1010. var break_student = -1;
  1011. var break_exercise = -1;
  1012. function verifyBreak () {
  1013. if (actual_student == break_student && actual_exercise == break_exercise) {
  1014. postResultAutoEval(-6);
  1015. break_student = -1;
  1016. break_exercise = -1;
  1017. return;
  1018. } else {
  1019. break_student = actual_student;
  1020. break_exercise = actual_exercise;
  1021. }
  1022. }
  1023. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  1024. function getStudentAnswerURL () {
  1025. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1026. }
  1027. // This function is called by the iLM!!!
  1028. function getAutoEvalOriginalData () {
  1029. return original_propositions[actual_exercise];
  1030. }
  1031. function updateProgressBar () {
  1032. if (stoped) return;
  1033. var temp = (count_steps * value_by_step)|0;
  1034. count_steps++;
  1035. temp = temp > 100 ? 100 : temp;
  1036. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  1037. if (temp >= 100) {
  1038. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1039. $("#button_start").prop("disabled", false);
  1040. $("#button_stop").prop("disabled", true);
  1041. $("input:checkbox").attr("disabled", false);
  1042. clearInterval(var_interval);
  1043. }
  1044. }
  1045. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  1046. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  1047. function postResultAutoEval (grade = null) {
  1048. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  1049. if (grade == null) {
  1050. $("#"+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>\');
  1051. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1052. } else {
  1053. // Verify if the re-evaluation grade is the of that one registered:
  1054. var actual_value = 0;
  1055. var actual_student_grade = 0;
  1056. for (var k = 0; k < submissions.length; k++) {
  1057. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  1058. actual_value = submissions[k].grade;
  1059. for (var h = 0; h < submissions[k].submited.length; h++) {
  1060. if (submissions[k].submited[h] == students[actual_student]) {
  1061. actual_student_grade = submissions[k].allgrades[h];
  1062. break;
  1063. }
  1064. }
  1065. break;
  1066. }
  1067. }
  1068. // @FeedbackConvention
  1069. if (grade < 0) {
  1070. switch (grade) {
  1071. case -1:
  1072. // Test-cases are empty:
  1073. $("#"+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>\');
  1074. var mm = actual_exercise;
  1075. $("#"+id_t).find(".details-button").click(function(e) {
  1076. $(".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>\');
  1077. });
  1078. break;
  1079. case -2:
  1080. // Test-cases were manually altered by the student (fraud!):
  1081. $("#"+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>\');
  1082. var mm = actual_exercise;
  1083. $("#"+id_t).find(".details-button").click(function(e) {
  1084. $(".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>");
  1085. });
  1086. //AJAX
  1087. $.ajax({
  1088. dataType: "html",
  1089. 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",
  1090. success: function(d) {} });
  1091. break;
  1092. case -5:
  1093. // Execution failed:
  1094. $("#"+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>\');
  1095. var mm = actual_exercise;
  1096. //AJAX
  1097. $("#"+id_t).find(".details-button").click(function(e) {
  1098. $(".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>\');
  1099. });
  1100. break;
  1101. case -6: // iLM not answering was detected in "verifyBreak()"
  1102. // The iLM are not answering:
  1103. //AJAX
  1104. $("#"+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>\');
  1105. $("#"+id_t).find(".details-button").click(function(e) {
  1106. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  1107. });
  1108. break;
  1109. }
  1110. //AJAX
  1111. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1112. } else {
  1113. console.log((grade), (actual_student_grade));
  1114. if ((grade) == (actual_student_grade)) {
  1115. $("#"+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>\');
  1116. } else { // Notas diferem:
  1117. $("#"+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>\');
  1118. var mm = actual_exercise;
  1119. //AJAX
  1120. $("#"+id_t).find(".details-button").click(function(e) {
  1121. $(".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>\');
  1122. });
  1123. //AJAX
  1124. // Send to the endpoint the post_auto_eval_result to verify:
  1125. $.ajax({
  1126. dataType: "html",
  1127. 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),
  1128. success: function(d) {}
  1129. });
  1130. }
  1131. //AJAX
  1132. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1133. }
  1134. }
  1135. updateProgressBar();
  1136. // Does it must continue in the same exercise or stop?
  1137. if (actual_student < students.length) {
  1138. actual_student++;
  1139. run_individual_evaluation();
  1140. } else {
  1141. actual_student = 0;
  1142. // Does it go to next exercise or is it finished?
  1143. if (actual_exercise < selected_exercises.length) {
  1144. actual_exercise++;
  1145. run_individual_evaluation();
  1146. } else {
  1147. //AJAX
  1148. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1149. }
  1150. }
  1151. }
  1152. var original_propositions;
  1153. function get_original_propositions () {
  1154. original_propositions = [];
  1155. var count = 0;
  1156. for (var i = 0; i < exercises.length; i++) {
  1157. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1158. //AJAX
  1159. $.ajax({
  1160. dataType: "html",
  1161. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1162. success: function(d) { // variable "d" has the iLM content
  1163. original_propositions[count] = d; // exercise original content
  1164. count++;
  1165. if (count == selected_exercises.length) {
  1166. run_individual_evaluation();
  1167. }
  1168. }
  1169. });
  1170. }
  1171. }
  1172. }
  1173. function stop_evaluation () {
  1174. stoped = true;
  1175. //AJAX
  1176. $("#button_start").prop("disabled", false);
  1177. $("#button_stop").prop("disabled", true);
  1178. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1179. $("input:checkbox").attr("disabled", false);
  1180. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1181. clearInterval(var_interval);
  1182. }
  1183. var exercises = [ '; // '
  1184. foreach ($exercises_list as $exercise) {
  1185. print $exercise->id . ',';
  1186. }
  1187. print ' ];';
  1188. print ' var students = [ ';
  1189. foreach ($students_list as $student) {
  1190. print $student->userid . ',';
  1191. }
  1192. print '];';
  1193. print ' var ilms = [';
  1194. foreach ($exercises_list as $exercise) {
  1195. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1196. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1197. }
  1198. print ']';
  1199. print '</script>';
  1200. print '
  1201. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1202. <div class="modal-dialog modal-dialog-centered" role="document">
  1203. <div class="modal-content">
  1204. <div class="modal-header">
  1205. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1206. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1207. <span aria-hidden="true">&times;</span>
  1208. </button>
  1209. </div>
  1210. <div class="modal-body">
  1211. ...
  1212. </div>
  1213. <div class="modal-footer">
  1214. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1215. </div>
  1216. </div>
  1217. </div>
  1218. </div>'; //
  1219. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1220. print '<table id="table-results" class="table table-hover m-t-1">
  1221. <thead>
  1222. <tr id="cols-exercises">
  1223. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1224. </tr>
  1225. </thead>
  1226. <tbody>'; // "
  1227. foreach ($students_list as $student) {
  1228. $user = $DB->get_record('user', array('id' => $student->userid));
  1229. $avatar = new user_picture($user);
  1230. $avatar->courseid = $COURSE->id;
  1231. $avatar->link = true;
  1232. print ' <tr data-student="' . $student->userid . '">
  1233. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1234. </tr>' . "\n"; // "
  1235. }
  1236. print " </tbody>
  1237. </table>\n";
  1238. print $OUTPUT->footer();
  1239. } // function auto_evaluate()
  1240. /// This method moves an iAssign activity
  1241. function move_activity () {
  1242. global $USER, $CFG, $DB, $COURSE;
  1243. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1244. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1245. $update_entry_new_iassign = new stdClass();
  1246. $update_entry_new_iassign->id = $iassign_id;
  1247. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1248. // Update the iassign_statement
  1249. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1250. // Update file context
  1251. $c_i = context_module::instance($this->cm->id);
  1252. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1253. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1254. $path_module = context_course::instance($COURSE->id);
  1255. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1256. $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny); //2021/12
  1257. if ($context_file) {
  1258. $id_context = $context_file->id;
  1259. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1260. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1261. $context = context_module::instance($USER->cm); //2021/12
  1262. //2021/12 $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1263. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  1264. foreach ($files as $value) {
  1265. if ($value->get_filename() != ".") {
  1266. //2021/12 $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1267. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1268. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1269. $newfile = null; //TODO: desnecessario! Atribuicao 2 linhas abaixo!
  1270. $destiny_context = context_module::instance($course_module->id);
  1271. $newfile = $fs->create_file_from_string(array('contextid' => $destiny_context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id, 'filepath' => '/', 'filename' => $value->get_filename()), $value->get_content());
  1272. $updateentry = new stdClass();
  1273. $updateentry->id = $iassign_id;
  1274. $updateentry->filesid = $iassign_id; //2021/12 $newfile->get_itemid(); //TODO: esta' correto? $newfile definido 3 linhas acima NAO mais usado?
  1275. $DB->update_record("iassign_statement", $updateentry);
  1276. //2021/12 $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1277. break;
  1278. }
  1279. }
  1280. }
  1281. //2021/12 $this->return_home_course('moved_activity');
  1282. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
  1283. redirect($this->return, get_string('moved_activity', 'iassign').' <a href="'.$destiny_url.'">' . get_string('move_activity_access', 'iassign') . '\'' . $course_module->name . '\'</a>', null, \core\output\notification::NOTIFY_SUCCESS);
  1284. exit;
  1285. } // function move_activity()
  1286. /// This method duplicates an iAssign activity
  1287. function duplicate_activity () {
  1288. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1289. $id = $this->cm->id;
  1290. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1291. $context = context_module::instance($this->cm->id);
  1292. $contextuser = context_user::instance($USER->id);
  1293. // Get the the iAssign acitivity to be duplicated
  1294. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1295. // Remove the current id of activity
  1296. $id_source_copy = $iassign_statement->id;
  1297. $iassign_statement->id=0;
  1298. // Include prefix (Copy of ...)
  1299. $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
  1300. // Get the information about current author, and add this information in author_modified field
  1301. $author = $DB->get_record("user", array('id' => $USER->id));
  1302. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1303. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1304. // Store the activity in the table
  1305. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1306. // Duplicate activity file
  1307. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1308. //2021/12 $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1309. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
  1310. foreach ($files as $value) {
  1311. if ($value->get_filename() != ".") {
  1312. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1313. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1314. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
  1315. $updateentry = new stdClass();
  1316. $updateentry->id = $id_;
  1317. //2021/12 $updateentry->filesid = $newfile->get_itemid();
  1318. $updateentry->filesid = $id_;
  1319. // Update the duplicated iLM iAssign with new file id
  1320. $DB->update_record("iassign_statement", $updateentry);
  1321. }
  1322. }
  1323. }
  1324. // log event --------------------------------------------------------------------------------------
  1325. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1326. $this->return_home_course('duplicated_activity');
  1327. exit;
  1328. }
  1329. // / This method gets the content from comment and register it
  1330. function add_comment () {
  1331. global $USER, $DB;
  1332. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1333. $comment = false;
  1334. if ($submission_comment)
  1335. $comment = $this->write_comment_submission();
  1336. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1337. if (!$id_submission) {
  1338. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  1339. if ($iassign_submission) {
  1340. $id_submission = $iassign_submission->id;
  1341. }
  1342. }
  1343. $content = $this->search_comment_submission($id_submission);
  1344. ob_end_clean();
  1345. header("Connection: close\r\n");
  1346. header("Content-Encoding: none\r\n");
  1347. header('Content-Type: text/html');
  1348. ob_start();
  1349. print $this->search_comment_submission($id_submission);
  1350. $size = ob_get_length();
  1351. header("Content-Length: $size");
  1352. ob_end_flush();
  1353. flush();
  1354. ob_end_clean();
  1355. // Send email to users:
  1356. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $id_submission));
  1357. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1358. }
  1359. /// This method alerts envolved to new comment sent
  1360. function send_alert_new_comment ($comment, $student_id = -1) {
  1361. global $USER, $DB, $COURSE, $SITE;
  1362. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign') . " ";
  1363. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); //leo 2021/12
  1364. $subject .= $iassign_ilm->name . ' ' . get_string('new_comment_mail_at', 'iassign') . ' ' . get_string("iassign", "iassign") . '/Moodle'; //leo 2021/12
  1365. $url_curso;
  1366. $url_submissao;
  1367. $text = "<p style='margin-top: 1rem;'>\n";
  1368. $text .= "<a href=\"" . new moodle_url('/course/view.php', array('id' => $COURSE->id)) . "\">" . $COURSE->shortname . "</a> " . " &#8811;\n";
  1369. $modinfo = get_fast_modinfo($COURSE);
  1370. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1371. if ($modinfo->get_section_info($i) && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1372. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1373. $text .= "<a href=\"" . $url_curso . "#section-" . $modinfo->get_section_info($i)->section . "\">" . get_section_name($COURSE, $modinfo->get_section_info($i)->section) . "</a> &#8811;\n";
  1374. break;
  1375. }
  1376. }
  1377. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1378. $text .= "<a href=\"" . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id)) . "\">" . $iassign->name . "</a> &#8811;\n";
  1379. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1380. array(
  1381. 'id' => $this->cm->id,
  1382. 'action' => 'viewsubmission',
  1383. 'iassign_current' => $this->activity->get_activity()->id,
  1384. 'userid_iassign' => $USER->id));
  1385. $text .= "<a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a></p>\n";
  1386. $text .= "<div style='margin-left: .5rem;'>\n";
  1387. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>\n";
  1388. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1389. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>\n";
  1390. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1391. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': ' . "<a href=\"" .
  1392. new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">" . $USER->firstname . " " . $USER->lastname . "</a>\n";
  1393. $text .= " - " . userdate(time());
  1394. $text .= "</div><div style='margin: 2rem;'>\n";
  1395. $text .= $comment;
  1396. $text .= "</div><div>\n";
  1397. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | \n";
  1398. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>\n";
  1399. $text .= "</div>\n";
  1400. // Who has to receive?
  1401. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1402. $userfrom = \core_user::get_noreply_user();
  1403. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1404. // other teachers receive also: (excepts the sender)
  1405. foreach ($teachers as $teacher) {
  1406. if ($teacher->id != $USER->id) {
  1407. email_to_user(
  1408. $teacher,
  1409. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1410. $subject,
  1411. "",
  1412. $text,
  1413. '',
  1414. '',
  1415. false,
  1416. $userfrom->email,
  1417. 'Não responda a esta mensagem' //TODO: internacionalizar
  1418. );
  1419. $message = new \core\message\message();
  1420. $message->component = 'mod_iassign';
  1421. $message->name = 'message';
  1422. $message->userfrom = core_user::get_noreply_user();
  1423. $message->userto = $teacher;
  1424. $message->subject = $subject;
  1425. $message->fullmessage = $text;
  1426. $message->fullmessageformat = FORMAT_MARKDOWN;
  1427. $message->fullmessagehtml = $text;
  1428. $message->smallmessage = $subject;
  1429. $message->notification = 1;
  1430. $message->contexturl = $url_submissao . '#comments';
  1431. $message->contexturlname = $this->activity->get_activity()->name;
  1432. $messageid = message_send($message);
  1433. }
  1434. } // foreach
  1435. // and student:
  1436. $student = $DB->get_record('user', array('id' => $student_id));
  1437. $formated_text = str_replace("viewsubmission", "view", $text);
  1438. email_to_user(
  1439. $student,
  1440. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1441. $subject,
  1442. "",
  1443. $formated_text,
  1444. '',
  1445. '',
  1446. false,
  1447. $userfrom->email,
  1448. 'Não responda a esta mensagem' //TODO: internacionalizar
  1449. );
  1450. $url_student = new moodle_url('/mod/iassign/view.php',
  1451. array(
  1452. 'id' => $this->cm->id,
  1453. 'action' => 'view',
  1454. 'iassign_current' => $this->activity->get_activity()->id));
  1455. $message = new \core\message\message();
  1456. $message->component = 'mod_iassign';
  1457. $message->name = 'message';
  1458. $message->userfrom = core_user::get_noreply_user();
  1459. $message->userto = $student;
  1460. $message->subject = $subject;
  1461. $message->fullmessage = $formated_text;
  1462. $message->fullmessageformat = FORMAT_MARKDOWN;
  1463. $message->fullmessagehtml = $formated_text;
  1464. $message->smallmessage = $subject;
  1465. $message->notification = 1;
  1466. $message->contexturl = $url_student . '#comments';
  1467. $message->contexturlname = $this->activity->get_activity()->name;
  1468. $messageid = message_send($message);
  1469. } else { // a student has sent the comment:
  1470. foreach ($teachers as $teacher) {
  1471. email_to_user(
  1472. $teacher,
  1473. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1474. $subject,
  1475. "",
  1476. $text,
  1477. '',
  1478. '',
  1479. false,
  1480. $userfrom->email,
  1481. 'Não responda a esta mensagem' //TODO: internacionalizar
  1482. );
  1483. $message = new \core\message\message();
  1484. $message->component = 'mod_iassign';
  1485. $message->name = 'message';
  1486. $message->userfrom = core_user::get_noreply_user();
  1487. $message->userto = $teacher;
  1488. $message->subject = $subject;
  1489. $message->fullmessage = $text;
  1490. $message->fullmessageformat = FORMAT_MARKDOWN;
  1491. $message->fullmessagehtml = $text;
  1492. $message->smallmessage = $subject;
  1493. $message->notification = 1;
  1494. $message->contexturl = $url_submissao . '#comments';
  1495. $message->contexturlname = $this->activity->get_activity()->name;
  1496. $messageid = message_send($message);
  1497. }
  1498. }
  1499. } // function send_alert_new_comment($comment, $student_id = -1)
  1500. /// This method gets the content from the iLM and register it
  1501. // It could be the "exercise template" (teacher) or an answer (student)
  1502. function get_answer () {
  1503. global $USER, $CFG, $DB, $OUTPUT;
  1504. $id = $this->cm->id;
  1505. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1506. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1507. if ($submission_ajax == 1) ob_start();
  1508. $comment = false;
  1509. if ($submission_comment)
  1510. $comment = $this->write_comment_submission();
  1511. // receives data of iLM using the current activity
  1512. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1513. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1514. // receives data of submission of current activity
  1515. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1516. // receives post and get
  1517. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1518. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1519. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1520. $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)
  1521. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1522. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1523. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1524. $msg = '';
  1525. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1526. $newentry = new stdClass();
  1527. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1528. $newentry->userid = $this->userid_iassign;
  1529. $newentry->timecreated = time();
  1530. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1531. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1532. $DB->insert_record("iassign_allsubmissions", $newentry);
  1533. }
  1534. // Feedback
  1535. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1536. $str_action = "view"; // repeat
  1537. if (strtolower($iassign_ilm->name) == "igeom") {
  1538. }
  1539. $title = get_string('evaluate_iassign', 'iassign');
  1540. print $OUTPUT->header();
  1541. print $OUTPUT->box_start();
  1542. // Action = { view ; repeat ; viewsubmission }
  1543. // * '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")
  1544. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1545. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1546. $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;
  1547. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1548. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1549. print '<table width=100% >';
  1550. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1551. //TODO alterar aqui???
  1552. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1553. // empty_answer_post = No solution was posted.
  1554. if ($comment)
  1555. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1556. else
  1557. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1558. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1559. } else {
  1560. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1561. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1562. // Correct answer!!
  1563. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1564. $this->write_solution = 1; //
  1565. $status = 3;
  1566. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1567. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1568. // log record
  1569. $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;
  1570. // Trigger module viewed event.
  1571. $event = \mod_iassign\event\submission_created::create(array(
  1572. 'objectid' => $this->iassign->id,
  1573. 'context' => $this->context,
  1574. 'other' => $info
  1575. ));
  1576. $event->add_record_snapshot('course', $this->course);
  1577. $event->trigger();
  1578. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1579. // Wrong answer...: get_answer_incorrect
  1580. $status = 2;
  1581. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1582. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1583. // log record
  1584. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1585. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1586. // Trigger module viewed event.
  1587. $event = \mod_iassign\event\submission_created::create(array(
  1588. 'objectid' => $this->iassign->id,
  1589. 'context' => $this->context,
  1590. 'other' => $info
  1591. ));
  1592. $event->add_record_snapshot('course', $this->course);
  1593. $event->trigger();
  1594. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1595. // Presents to the learner the result of the automatic evaluate?
  1596. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1597. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1598. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1599. print '<tr>';
  1600. // log record
  1601. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1602. // Trigger module viewed event.
  1603. $event = \mod_iassign\event\submission_created::create(array(
  1604. 'objectid' => $this->iassign->id,
  1605. 'context' => $this->context,
  1606. 'other' => $info
  1607. ));
  1608. $event->add_record_snapshot('course', $this->course);
  1609. $event->trigger();
  1610. } else { // yes!!!
  1611. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1612. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1613. print '<tr>';
  1614. print $msg;
  1615. }
  1616. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1617. $status = 1;
  1618. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1619. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1620. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1621. print '<tr>';
  1622. // log record
  1623. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1624. $event = \mod_iassign\event\submission_created::create(array(
  1625. 'objectid' => $this->iassign->id,
  1626. 'context' => $this->context,
  1627. 'other' => $info
  1628. ));
  1629. $event->add_record_snapshot('course', $this->course);
  1630. $event->trigger();
  1631. } // if ($iassign_ilm->evaluate == 1)
  1632. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1633. print '</tr></table>';
  1634. print $OUTPUT->box_end();
  1635. // add or update evaluate
  1636. if ($this->write_solution == 1) {
  1637. $timenow = time();
  1638. // new record
  1639. if (!$iassign_submission) {
  1640. $newentry = new stdClass();
  1641. $newentry->userid = $this->userid_iassign;
  1642. // $newentry->userid = $USER->id;
  1643. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1644. $newentry->timecreated = $timenow;
  1645. $newentry->timemodified = $timenow;
  1646. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1647. $newentry->grade = round($grade_student, 2);
  1648. $newentry->status = $status;
  1649. $newentry->experiment = 1;
  1650. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1651. print_error('error_insert', 'iassign');
  1652. } else {
  1653. // Trigger module viewed event.
  1654. $event = \mod_iassign\event\submission_created::create(array(
  1655. 'objectid' => $this->iassign->id,
  1656. 'context' => $this->context
  1657. ));
  1658. $event->add_record_snapshot('course', $this->course);
  1659. $event->trigger();
  1660. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1661. }
  1662. } elseif ($iassign_submission->status != 3) {
  1663. $newentry = new stdClass();
  1664. $newentry->id = $iassign_submission->id;
  1665. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1666. $newentry->userid = $iassign_submission->userid;
  1667. $newentry->timecreated = $iassign_submission->timecreated;
  1668. $newentry->timemodified = $timenow;
  1669. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1670. $newentry->grade = round($grade_student, 2);
  1671. $newentry->status = $status;
  1672. $newentry->experiment = $iassign_submission->experiment + 1;
  1673. if (!$DB->update_record("iassign_submission", $newentry)) {
  1674. print_error('error_update', 'iassign');
  1675. //D depurar...
  1676. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1677. //D $fp = fopen("teste1.txt","w");
  1678. //D fwrite($fp,$stringAux);
  1679. } else {
  1680. // Trigger module viewed event.
  1681. $event = \mod_iassign\event\submission_updated::create(array(
  1682. 'objectid' => $this->iassign->id,
  1683. 'context' => $this->context
  1684. ));
  1685. $event->add_record_snapshot('course', $this->course);
  1686. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1687. }
  1688. } else {
  1689. if ($return_get_answer == 1) {
  1690. $newentry = new stdClass();
  1691. $newentry->id = $iassign_submission->id;
  1692. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1693. $newentry->userid = $iassign_submission->userid;
  1694. $newentry->timecreated = $iassign_submission->timecreated;
  1695. $newentry->timemodified = $timenow;
  1696. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1697. $newentry->grade = round($grade_student, 2);
  1698. $newentry->status = $status;
  1699. $newentry->experiment = $iassign_submission->experiment + 1;
  1700. if (!$DB->update_record("iassign_submission", $newentry))
  1701. print_error('error_update', 'iassign');
  1702. else {
  1703. $event = \mod_iassign\event\submission_updated::create(array(
  1704. 'objectid' => $this->iassign->id,
  1705. 'context' => $this->context
  1706. ));
  1707. $event->add_record_snapshot('course', $this->course);
  1708. $event->trigger();
  1709. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1710. print $OUTPUT->box_start();
  1711. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1712. print $OUTPUT->box_end();
  1713. }
  1714. } elseif ($return_get_answer == 2) {
  1715. print $OUTPUT->box_start();
  1716. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1717. print $OUTPUT->box_end();
  1718. } else {
  1719. print $OUTPUT->box_start();
  1720. print "
  1721. <script type='text/javascript'>
  1722. //<![CDATA[
  1723. function overwrite () {
  1724. document.formEnvio.return_get_answer.value = 1;
  1725. document.formEnvio.submit();
  1726. }
  1727. function nooverwrite () {
  1728. document.formEnvio.return_get_answer.value = 2;
  1729. document.formEnvio.submit();
  1730. }
  1731. //]]>
  1732. </script>";
  1733. $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;
  1734. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1735. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1736. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1737. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1738. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1739. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1740. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1741. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1742. <input type='hidden' name='return_get_answer'/> ";
  1743. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1744. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1745. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1746. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1747. print " </form>";
  1748. print $OUTPUT->box_end();
  1749. }
  1750. }
  1751. } // if ($this->write_solution == 1)
  1752. print $OUTPUT->footer();
  1753. if ($submission_ajax == 1) {
  1754. ob_end_clean();
  1755. print 'OK';
  1756. }
  1757. die();
  1758. } // function get_answer()
  1759. /// Export in file the answer of student.
  1760. function export_file_answer () {
  1761. global $DB;
  1762. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1763. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1764. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1765. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1766. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1767. $extensions = explode(",", $iassign_ilm->extension);
  1768. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1769. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1770. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1771. header("Pragma: public");
  1772. header("Expires: 0");
  1773. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1774. header("Cache-Control: private", false);
  1775. header("Content-Type: document/unknown");
  1776. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1777. set_time_limit(0);
  1778. print($iassign_submission->answer);
  1779. exit;
  1780. } // function export_file_answer()
  1781. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1782. // @calledby $this->export_package_answer()
  1783. //TODO Precisa terminar! //TODO_HTML
  1784. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1785. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1786. <head>
  1787. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1788. $str_html .= " </head>
  1789. <body>\n";
  1790. $tam = sizeof($array_iassign_name);
  1791. for ($ii=0; $ii<$tam; $ii++) {
  1792. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1793. }
  1794. $str_html .= "
  1795. </body>\n</html>";
  1796. return $str_html;
  1797. }
  1798. /// Export an package (zip) with all answer of students
  1799. // @calledby $this->action()
  1800. function export_package_answer () {
  1801. global $DB, $CFG, $OUTPUT;
  1802. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1803. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1804. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1805. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1806. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1807. $userid = optional_param('userid', NULL, PARAM_INT);
  1808. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1809. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1810. //TODO_HTML echo "username=$username<br/>"; exit;
  1811. $current_date = date('Y_m_d_H');
  1812. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1813. // If temporary directory under Moodle data does not exists => create it
  1814. if (!is_dir($diretorio)) {
  1815. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1816. // created directory with permissions to be seen by everyone
  1817. }
  1818. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1819. if (!is_writable($diretorio)) { // send a highlighted message!
  1820. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1821. exit; // just in case
  1822. }
  1823. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1824. $zip = new zip_archive(); // create ZIP
  1825. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1826. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1827. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1828. $vet_student_filename = array();
  1829. $vet_student_content = array();
  1830. foreach ($iassign_statements as $iassign_statement) {
  1831. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1832. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1833. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1834. $extensions = explode(",", $iassign_ilm->extension);
  1835. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1836. if ($iassign_submission) {
  1837. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1838. $student_content = $iassign_submission->answer;
  1839. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1840. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1841. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1842. if ($resp) {
  1843. $vet_student_filename[] = $student_filename;
  1844. $vet_student_content[] = $student_content;
  1845. }
  1846. else { // send a highlighted message!
  1847. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1848. exit; // just in case
  1849. }
  1850. }
  1851. }
  1852. $zip->close(); // close the ZIP file
  1853. if (count($vet_student_filename)>0) {
  1854. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1855. $result_tf = $vet_result[0];
  1856. $filenameZip = $vet_result[1]->filename;
  1857. }
  1858. iassign_utils::download_file($zip_filename); // download the ZIP file
  1859. exit;
  1860. } // function export_package_answer()
  1861. /// Editing status of interactive activities
  1862. function edit_status () {
  1863. global $USER, $DB, $OUTPUT;
  1864. $newentry = new stdClass();
  1865. $newentry->id = $this->iassign_submission_current;
  1866. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1867. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1868. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1869. $newentry->status = $iassign_submission->status;
  1870. $newentry->teacher = $USER->id;
  1871. if (!$DB->update_record('iassign_submission', $newentry))
  1872. print_error('error_update', 'iassign');
  1873. else {
  1874. // Trigger module viewed event.
  1875. $event = \mod_iassign\event\submission_updated::create(array(
  1876. 'objectid' => $this->iassign->id,
  1877. 'context' => $this->context
  1878. ));
  1879. $event->add_record_snapshot('course', $this->course);
  1880. $event->trigger();
  1881. $this->action = 'viewsubmission';
  1882. $this->view_iassign_current();
  1883. } // if (!$DB->update_record('iassign_submission', $newentry))
  1884. } // function edit_status()
  1885. /// Editing grade of interactive activities
  1886. function edit_grade () {
  1887. global $USER, $DB, $OUTPUT;
  1888. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1889. if ($newgrade && $newgrade >= 0) {
  1890. $newentry = new stdClass();
  1891. $newentry->id = $this->iassign_submission_current;
  1892. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1893. $newentry->teacher = $USER->id;
  1894. if (!$DB->update_record('iassign_submission', $newentry))
  1895. print_error('error_update', 'iassign');
  1896. else {
  1897. // Trigger module viewed event.
  1898. $event = \mod_iassign\event\submission_updated::create(array(
  1899. 'objectid' => $this->iassign->id,
  1900. 'context' => $this->context
  1901. ));
  1902. $event->add_record_snapshot('course', $this->course);
  1903. $event->trigger();
  1904. }
  1905. } // if ($newgrade >= 0)
  1906. $this->action = 'viewsubmission';
  1907. $this->view_iassign_current();
  1908. }
  1909. /// Add or Edit interactive activities
  1910. // Get here when editing form and and submitted form data
  1911. // @calledby $this->action()
  1912. function add_edit_iassign () {
  1913. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1914. require_once('iassign_form.php');
  1915. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1916. $iassignid = $this->iassign->id;
  1917. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1918. $param->action = $this->action; // hidden
  1919. $param->id = $id; // hidden
  1920. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1921. $COURSE->cm = $id;
  1922. $COURSE->iassignid = $iassignid;
  1923. $COURSE->iassign_file_id = NULL;
  1924. $context = context_module::instance($this->cm->id);
  1925. $contextuser = context_user::instance($USER->id);
  1926. $component = 'mod_iassign';
  1927. $filearea = 'exercise';
  1928. if (!empty($this->iassign_current))
  1929. $COURSE->iassign_id = $this->iassign_current;
  1930. else
  1931. $COURSE->iassign_id = 0;
  1932. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1933. if ($this->action == 'add') {
  1934. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1935. $params_temp = array('iassignid' => $iassignid);
  1936. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1937. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1938. $total_of_activities = count($iassign_statement);
  1939. $param->iassignid = $iassignid;
  1940. $param->name = "";
  1941. $param->oldname = "";
  1942. $param->type_iassign = 3;
  1943. $param->proposition = "";
  1944. $author = $DB->get_record("user", array("id" => $USER->id));
  1945. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1946. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1947. $param->author = $param->author_name;
  1948. $param->author_modified = $param->author_modified_name;
  1949. $COURSE->iassign_list = array();
  1950. $param->iassign_list = array();
  1951. if ($iassign_statement) {
  1952. foreach ($iassign_statement as $iassign) {
  1953. $iassignid = $iassign->id;
  1954. $param->iassign_list[$iassignid] = 0;
  1955. $COURSE->iassign_list[$iassignid] = new stdClass();
  1956. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1957. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1958. $COURSE->iassign_list[$iassignid]->enable = 1;
  1959. } // foreach ($iassign_statement as $iassign)
  1960. }
  1961. $param->iassign_ilmid = 0;
  1962. $param->file = 0;
  1963. $param->fileold = 0;
  1964. $param->filename = "";
  1965. $param->grade = $iassign_data->grade;
  1966. $param->timemodified = time();
  1967. $param->timecreated = time();
  1968. $param->timeavailable = $iassign_data->timeavailable;
  1969. $param->timedue = $iassign_data->timedue;
  1970. $param->preventlate = $iassign_data->preventlate;
  1971. $param->test = $iassign_data->test;
  1972. $param->special_param1 = 0;
  1973. $param->visible = 1;
  1974. $param->max_experiment = $iassign_data->max_experiment;
  1975. $param->dependency = 0;
  1976. $param->automatic_evaluate = 1;
  1977. $param->show_answer = 1;
  1978. } // if ($this->action == 'add')
  1979. elseif ($this->action == 'edit') {
  1980. $COURSE->iassign_list = array();
  1981. $this_activity = $this->activity->get_activity();
  1982. if ($this_activity != null) { // first enter here: fill form data
  1983. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1984. $param->iassign_id = $iassign_statement_current->id; // oculto
  1985. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1986. $param->name = $iassign_statement_current->name;
  1987. $param->oldname = $iassign_statement_current->name;
  1988. $param->type_iassign = $iassign_statement_current->type_iassign;
  1989. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1990. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1991. $param->author_name = $iassign_statement_current->author_name; // oculto
  1992. $param->author = $iassign_statement_current->author_name;
  1993. $author = $DB->get_record("user", array('id' => $USER->id));
  1994. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1995. $param->author_modified = $param->author_modified_name;
  1996. $dependency = explode(';', $iassign_statement_current->dependency);
  1997. $param->iassign_list = array();
  1998. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1999. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  2000. $array_dependency = array();
  2001. $subdependency = "";
  2002. $sub_subdependency = "";
  2003. // Dependents on this exercise
  2004. if ($iassign_statement_dependency) {
  2005. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  2006. // to whom this exercise depends
  2007. foreach ($inter as $tmp)
  2008. $sub_subdependency .= $this->search_sub_dependency($tmp);
  2009. $list_dependency = $subdependency . $sub_subdependency;
  2010. $array_dependency = explode(";", $list_dependency);
  2011. }
  2012. // Get all activities in the same iAssigment block:
  2013. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  2014. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  2015. $total_of_activities = count($all_others_iassign_statement) + 1;
  2016. $inter = array();
  2017. if ($all_others_iassign_statement) {
  2018. foreach ($all_others_iassign_statement as $iassign)
  2019. if (in_array($iassign->id, $dependency))
  2020. $inter[] = $iassign->id;
  2021. }
  2022. if ($all_others_iassign_statement) {
  2023. foreach ($all_others_iassign_statement as $iassign) {
  2024. $iassignid = $iassign->id;
  2025. $COURSE->iassign_list[$iassignid] = new stdClass();
  2026. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  2027. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  2028. if (in_array($iassignid, $dependency))
  2029. $param->iassign_list[$iassignid] = 1;
  2030. else
  2031. $param->iassign_list[$iassignid] = 0;
  2032. if (in_array($iassignid, $array_dependency))
  2033. $COURSE->iassign_list[$iassignid]->enable = 0;
  2034. else
  2035. $COURSE->iassign_list[$iassignid]->enable = 1;
  2036. } // foreach ($all_others_iassign_statement as $iassign)
  2037. } // if ($all_others_iassign_statement)
  2038. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  2039. $param->fileold = 0;
  2040. $param->filesid = 0;
  2041. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  2042. $param->filename = '';
  2043. $param->grade = $iassign_statement_current->grade;
  2044. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  2045. $param->timeavailable = $iassign_statement_current->timeavailable;
  2046. $param->timedue = $iassign_statement_current->timedue;
  2047. $param->preventlate = $iassign_statement_current->preventlate;
  2048. $param->test = $iassign_statement_current->test;
  2049. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  2050. $param->position = $iassign_statement_current->position; // hidden
  2051. $param->visible = $iassign_statement_current->visible;
  2052. $param->max_experiment = $iassign_statement_current->max_experiment;
  2053. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  2054. $param->show_answer = $iassign_statement_current->show_answer;
  2055. $fs = get_file_storage(); // Get reference to all files in Moodle data
  2056. //2021/12 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  2057. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id);
  2058. if ($files) {
  2059. foreach ($files as $file) {
  2060. if ($file->get_filename() != '.') {
  2061. $param->filename = $file->get_filename();
  2062. $param->file = $file->get_id();
  2063. $param->fileold = $file->get_id();
  2064. $COURSE->iassign_file_id = $file->get_id();
  2065. }
  2066. }
  2067. }
  2068. //TODO //MOOC2014 -- inicio
  2069. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  2070. //D if ($iassign_ilm_configs) {
  2071. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  2072. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  2073. //D } //MOOC2014 -- fim
  2074. } // if ($this_activity != null)
  2075. } // elseif ($this->action == 'edit')
  2076. // Get all iActivity in the iAssign block with id = $this->iassign->id
  2077. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  2078. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  2079. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  2080. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  2081. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  2082. $param->position = $total_of_activities;
  2083. // Create form and associate its data
  2084. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  2085. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  2086. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  2087. if (isset($param->iassign_ilmid)) {
  2088. // array is additional atributes to 'form'
  2089. // 'special_param1 == 1' => script of iGeom : <select class="custom-select" name="special_param1" id="id_special_param1"> "Assignment with script(algorithm)? (Applicable only to iGeom iLM)"
  2090. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  2091. }
  2092. else {
  2093. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  2094. }
  2095. $mform->set_data($param); // define data in the form
  2096. if ($mform->is_cancelled()) {
  2097. $this->return_home_course('iassign_cancel');
  2098. exit;
  2099. }
  2100. else { // else if ($mform->is_cancelled())
  2101. $result = $mform->get_data();
  2102. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  2103. if ($result) {
  2104. $result->context = $context;
  2105. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  2106. $result->grade = 0;
  2107. if ($result->type_iassign == 1) {
  2108. $result->automatic_evaluate = 0;
  2109. $result->show_answer = 0;
  2110. }
  2111. elseif ($result->automatic_evaluate == 0)
  2112. $result->show_answer = 0;
  2113. // $_POST['iassign_list']
  2114. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  2115. if ($result->iassign_list) {
  2116. foreach ($result->iassign_list as $key => $value)
  2117. $result->dependency .= $key . ';';
  2118. }
  2119. else
  2120. $result->dependency = 0;
  2121. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  2122. //TODO Then get it directly from the form data $_POST!
  2123. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  2124. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  2125. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  2126. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  2127. if ($this->action == 'add') {
  2128. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  2129. if ($iassign_statement_name) {
  2130. $this->return_home_course('error_iassign_name');
  2131. die();
  2132. }
  2133. // Really insert the new iActivity in table '*_iassign_statement'
  2134. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  2135. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  2136. // Trigger module viewed event.
  2137. $event = \mod_iassign\event\iassign_created::create(array(
  2138. 'objectid' => $iassignid,
  2139. 'context' => $context
  2140. ));
  2141. $event->add_record_snapshot('course', $this->course);
  2142. $event->trigger();
  2143. $this->return_home_course('iassign_add');
  2144. } // if ($this->action == 'add')
  2145. elseif ($this->action == 'edit') {
  2146. $iassignid = $this->activity->update_iassign($result);
  2147. $this->activity->update_calendar($iassignid, $result->oldname);
  2148. // Trigger module viewed event.
  2149. $event = \mod_iassign\event\iassign_updated::create(array(
  2150. 'objectid' => $iassignid,
  2151. 'context' => $context
  2152. ));
  2153. $event->add_record_snapshot('course', $this->course);
  2154. $event->trigger();
  2155. $this->return_home_course('iassign_update');
  2156. } // elseif ($this->action == 'edit')
  2157. die();
  2158. } // if ($result)
  2159. } // else if ($mform->is_cancelled())
  2160. print $OUTPUT->header();
  2161. $mform->display();
  2162. print $OUTPUT->footer();
  2163. die();
  2164. } // function add_edit_iassign()
  2165. /// Search for dependencies
  2166. function search_dependency ($search_iassing_id, $iassign_statement) {
  2167. global $DB, $OUTPUT;
  2168. $dependency = "";
  2169. if ($iassign_statement)
  2170. foreach ($iassign_statement as $iassign) {
  2171. $inter_dependency = explode(';', $iassign->dependency);
  2172. if (in_array($search_iassing_id, $inter_dependency)) {
  2173. $dependency .= $iassign->id . ";";
  2174. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2175. } // if (in_array($search_iassing_id, $inter_dependency))
  2176. } // foreach ($iassign_statement as $iassign)
  2177. return $dependency;
  2178. }
  2179. /// Search for "sub"dependency
  2180. function search_sub_dependency ($search_iassing_id) {
  2181. global $DB, $OUTPUT;
  2182. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2183. $dependency = "";
  2184. if ($iassign_statement) {
  2185. $inter_dependency = explode(';', $iassign_statement->dependency);
  2186. foreach ($inter_dependency as $tmp) {
  2187. if ($tmp != 0)
  2188. $dependency .= $tmp . ";";
  2189. $dependency .= $this->search_sub_dependency($tmp);
  2190. } // foreach ($inter_dependency as $tmp)
  2191. } // if ($iassign_statement)
  2192. return $dependency;
  2193. }
  2194. // Warning message
  2195. static function warning_message_iassign ($strcode) {
  2196. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2197. }
  2198. /// Update grade of iAssign
  2199. // Called always any iAssign activity is created
  2200. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2201. static function update_grade_iassign ($iassignid) {
  2202. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2203. require_once($CFG->libdir . '/gradelib.php');
  2204. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2205. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2206. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2207. // Each iAssign item is associated with one item on the "gradebook"
  2208. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2209. //$sum_grade = 0;
  2210. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2211. //foreach($grade as $tmp) {
  2212. // $sum_grade += $tmp->grade;
  2213. // }
  2214. //1 Solution 1
  2215. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2216. //1 $sum_grade = 0; //1
  2217. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2218. //2 Solution 2
  2219. $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
  2220. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2221. if (key($array_sum_grade))
  2222. $sum_grade = key($array_sum_grade); //2
  2223. else
  2224. $sum_grade = 0; //2
  2225. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2226. $grades = NULL;
  2227. $params_temp = array('itemname' => $grade_iassign->name);
  2228. $params_temp['iteminstance'] = $iassignid;
  2229. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2230. //2016 if ($sum_grade != 0) {
  2231. $params_temp['grademax'] = $sum_grade;
  2232. $params_temp['rawgrademax'] = $sum_grade;
  2233. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2234. $params_temp['grademin'] = 0;
  2235. // @calls /lib/gradelib.php: call to grade_item->insert()
  2236. //TODO: is there any error here in Moodle version 3.0?
  2237. //TODO: Incorrect property 'grademax' found when inserting grade object
  2238. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2239. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2240. }
  2241. /// Update grade of student
  2242. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2243. global $CFG, $DB, $OUTPUT;
  2244. require_once($CFG->libdir . '/gradelib.php');
  2245. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2246. // Review all the student submission for this iAssign activity
  2247. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2248. $total_grade = 0;
  2249. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2250. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2251. if ($iassign_submission)
  2252. $total_grade += $iassign_submission->grade;
  2253. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2254. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2255. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2256. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2257. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2258. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2259. $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
  2260. if (key($array_sum_grade))
  2261. $sum_grade = key($array_sum_grade); //2
  2262. else
  2263. $sum_grade = 0; //2
  2264. $grades['userid'] = $userid;
  2265. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2266. $params_temp = array('itemname' => $grade_iassign->name);
  2267. $params_temp['iteminstance'] = $iassignid;
  2268. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2269. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2270. $params_temp['grademax'] = $sum_grade;
  2271. $params_temp['rawgrademax'] = $sum_grade;
  2272. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2273. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2274. }
  2275. /// Display caption of icons - to the bottom page of teacher's report
  2276. function view_legend_icons () {
  2277. global $USER, $CFG, $DB, $OUTPUT;
  2278. $id = $this->cm->id;
  2279. if ($this->action == 'print')
  2280. print '<table border=1 width=100%><tr>';
  2281. else
  2282. print '<table width=100%><tr>';
  2283. print '<td >';
  2284. //leo 2021/12 cortes: /home/leo/projetos/iMA/lms/itarefa/novo/alteracoes_2021/locallib_view_legend_icons_antes_corte.php
  2285. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2286. if ($this->action != 'print') {
  2287. $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>\n";
  2288. $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>\n";
  2289. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2290. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2291. } // if ($this->action != 'print')
  2292. print '</tr></table>' . "\n";
  2293. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2294. print '</td></tr></table>' . "\n";
  2295. } // function view_legend_icons()
  2296. /// Display activity current
  2297. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2298. function view_iassign_current () {
  2299. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2300. $id = $this->cm->id;
  2301. $iassignid = $this->iassign->id;
  2302. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2303. $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
  2304. // 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 ...
  2305. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2306. if (!$iassign_statement_activity_item) {
  2307. print $OUTPUT->header();
  2308. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2309. print $OUTPUT->footer();
  2310. exit;
  2311. }
  2312. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2313. $ilm_name = '';
  2314. if ($ilm->ilm)
  2315. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2316. // 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
  2317. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2318. // log record
  2319. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2320. //Trigger module viewed event.
  2321. $event = \mod_iassign\event\submission_viewed::create(array(
  2322. 'objectid' => $iassign->id,
  2323. 'context' => $this->context,
  2324. 'other' => $info
  2325. ));
  2326. $event->add_record_snapshot('course', $this->course);
  2327. $event->trigger();
  2328. // Search of iLM data used in the current activity
  2329. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2330. // Add actual activity to navbar:
  2331. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2332. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2333. print $OUTPUT->header();
  2334. if ($this->action == 'viewsubmission') {
  2335. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2336. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2337. else
  2338. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2339. } else {
  2340. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2341. }
  2342. if ($iassign_submission)
  2343. $this->update_comment($iassign_submission->id);
  2344. //2021/12 $file = $iassign_statement_activity_item->filesid;
  2345. $file = $iassign_statement_activity_item->id;
  2346. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2347. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2348. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2349. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2350. $this->bottonPost = 0; // hide submit button
  2351. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2352. $this->view_iassign = false; // disable visualization of activity
  2353. $repeat = "";
  2354. $last_iassign = "";
  2355. $student_answer = "";
  2356. $comment = "";
  2357. // *** Teacher access (view learner's submission)
  2358. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2359. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2360. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2361. // ---> access teacher for test
  2362. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2363. $this->bottonPost = 1;
  2364. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2365. $this->activity->view_dates();
  2366. $USER->iassignEdit = $this->bottonPost;
  2367. $this->activity->show_info_iassign();
  2368. if ($iassign_submission) {
  2369. //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;
  2370. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2371. } else {
  2372. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2373. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2374. }
  2375. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2376. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2377. // Prepare tags to present the iLM
  2378. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2379. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2380. // *** (end) Teacher access (view the activity)
  2381. // *** Teacher access (view learner's submission to the activity)
  2382. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2383. // It is teacher or 'nonediting teacher' that can evaluate
  2384. // ----> area teacher evaluate
  2385. $row = optional_param('row', 0, PARAM_INT);
  2386. $column = optional_param('column', 0, PARAM_INT);
  2387. $link_next = iassign_icons::insert('right_disable');
  2388. $link_previous = iassign_icons::insert('left_disable');
  2389. $link_up = iassign_icons::insert('up_disable');
  2390. $link_down = iassign_icons::insert('down_disable');
  2391. $has_row_column = isset($USER->matrix_iassign[$row][$column]) ? True : False;
  2392. // next_activity
  2393. if ($has_row_column && $USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2394. $url_next = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column + 1]->iassign_submission_current . "&userid_iassign=$t$
  2395. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2396. }
  2397. // previous_activity
  2398. if ($has_row_column && $USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2399. $url_previous = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column - 1]->iassign_submission_current . "&userid_iassig$
  2400. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2401. }
  2402. // previous_student
  2403. if ($has_row_column && $USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2404. $url_down = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row + 1][$column]->iassign_submission_current . "&userid_iassign=" $
  2405. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2406. }
  2407. // next_student
  2408. if ($has_row_column && $USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2409. if ($iassign_submission) {
  2410. $student_answer = $iassign_submission->answer;
  2411. }
  2412. $last_iassign = get_string('last_iassign', 'iassign');
  2413. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2414. // Messages related to due date (and user role)
  2415. $this->activity->view_dates();
  2416. print $OUTPUT->box_start();
  2417. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2418. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2419. print $OUTPUT->user_picture($user_data);
  2420. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2421. print '</td>' . "\n";
  2422. print '<td width=20% align=right>' . "\n";
  2423. print '<table width=50 cellpadding="0">';
  2424. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2425. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2426. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2427. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2428. print '</table>' . "\n";
  2429. print '</td></tr></table>' . "\n";
  2430. print $OUTPUT->box_end();
  2431. print $OUTPUT->box_start();
  2432. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2433. print '<td width=60% valign="top">' . "\n";
  2434. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2435. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2436. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2437. $resp = get_string('yes');
  2438. else
  2439. $resp = get_string('no');
  2440. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2441. if ($iassign_statement_activity_item->show_answer == 1)
  2442. $resp = get_string('yes');
  2443. else
  2444. $resp = get_string('no');
  2445. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2446. print '</td>';
  2447. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2448. print '<td width=40% valign="top" align="left">';
  2449. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2450. // check status of solution sent by the student
  2451. if ($iassign_submission) {
  2452. switch ($iassign_submission->status) {
  2453. case 3 :
  2454. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2455. break;
  2456. case 2 :
  2457. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2458. break;
  2459. case 1 :
  2460. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2461. break;
  2462. default :
  2463. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2464. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2465. } // switch ($iassign_submission->status)
  2466. }
  2467. else { // if ($iassign_submission)
  2468. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2469. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2470. }
  2471. // update_status
  2472. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2473. $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);
  2474. print " <script type='text/javascript'>
  2475. //<![CDATA[
  2476. function overwriteStatus (newstatus) {
  2477. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2478. document.formEditStatus.return_status.value=newstatus;
  2479. document.formEditStatus.submit();
  2480. }
  2481. else
  2482. document.formEditStatus.return_status.value=-1;
  2483. }
  2484. //]]>
  2485. </script>";
  2486. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2487. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2488. 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";
  2489. print " <input type='hidden' name='return_status'>\n";
  2490. print "</form>\n";
  2491. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2492. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2493. $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);
  2494. print "
  2495. <script type='text/javascript'>
  2496. //<![CDATA[
  2497. function overwriteGrade (newgrade,maxgrade) {
  2498. if (newgrade<0 || newgrade>maxgrade) {
  2499. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2500. document.formEditGrade.return_grade.value=-1;
  2501. document.formEditGrade.submit();
  2502. }
  2503. else {
  2504. document.formEditGrade.return_grade.value=newgrade;
  2505. document.formEditGrade.submit();
  2506. }
  2507. }
  2508. //]]>
  2509. </script>";
  2510. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2511. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2512. print " <input type='text' name='grade' size='6'>";
  2513. print " <input type='hidden' name='return_grade'> ";
  2514. 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";
  2515. print "</form>";
  2516. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2517. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2518. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2519. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2520. if ($teacher)
  2521. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2522. } // if ($iassign_submission->experiment > 0)
  2523. print '</td>';
  2524. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2525. print '</tr></table>';
  2526. print $OUTPUT->box_end();
  2527. $USER->iassignEdit = $this->bottonPost;
  2528. print activity::toggle_columns_script();
  2529. if ($iassign_submission && $allow_resubmission) {
  2530. // Put the iLM to
  2531. print $OUTPUT->box_start();
  2532. print '<p><strong>' . $last_iassign . '</strong></p>';
  2533. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2534. $enderecoPOST = "";
  2535. // Prepare tags to present the iLM
  2536. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2537. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2538. print $OUTPUT->box_end();
  2539. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2540. // ATTENTION: exception used by iGeom (exercise with "script")
  2541. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2542. if (substr($ilm_name, 0, 5)=="igeom") {
  2543. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2544. $loadTeacherActivity = true;
  2545. }
  2546. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2547. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2548. print activity::toggle_columns_script();
  2549. // Prepare tags to present the iLM
  2550. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2551. }
  2552. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2553. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2554. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2555. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2556. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2557. // *** (end) Teacher access (view learner's submission to the activity)
  2558. // *** Student access (view the activity)
  2559. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2560. // It could be the learner (he could send or resend the activity)
  2561. // ---> access student
  2562. $time_now = time();
  2563. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2564. // activity of type example - not submit button for submission
  2565. $this->view_iassign = true;
  2566. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2567. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2568. // activity of type test - iLM automatic evaluator - submit button for submission
  2569. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2570. $this->bottonPost = 1;
  2571. $this->view_iassign = true;
  2572. } else
  2573. $this->view_iassign = false;
  2574. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2575. // activity of type exercise (learner can send his answer, if yet open...)
  2576. $this->view_iassign = true;
  2577. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2578. $this->view_iassign = false;
  2579. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2580. $this->bottonPost = 1; // allow the submit button
  2581. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2582. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2583. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2584. if (!$iassign_submission) {
  2585. $str_iassign_submission_id = '';
  2586. $str_iassign_submission_answer = '';
  2587. }
  2588. else {
  2589. $str_iassign_submission_id = $iassign_submission->id;
  2590. $str_iassign_submission_answer = $iassign_submission->answer;
  2591. }
  2592. if ($this->action != 'repeat') {
  2593. $repeat = "<a href='view.php?action=repeat&id="
  2594. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2595. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2596. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2597. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2598. }
  2599. $this->bottonPost = 1;
  2600. $this->write_solution = 1; // can register his submission
  2601. $student_answer = $str_iassign_submission_answer;
  2602. }
  2603. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2604. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2605. $last_iassign = get_string('last_iassign', 'iassign');
  2606. if ($iassign_submission) {
  2607. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2608. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2609. $student_answer = $iassign_submission->answer;
  2610. } else {
  2611. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2612. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2613. }
  2614. }
  2615. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2616. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2617. $this->bottonPost = 1;
  2618. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2619. } else {
  2620. $last_iassign = get_string('last_iassign', 'iassign');
  2621. if ($iassign_submission) {
  2622. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2623. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2624. $student_answer = $iassign_submission->answer;
  2625. } else {
  2626. // Symbol of "redo activity"
  2627. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2628. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2629. }
  2630. }
  2631. } // elseif ($iassign_statement_activity_item->test == 1)
  2632. elseif ($iassign_statement_activity_item->test == 0)
  2633. $this->view_iassign = false;
  2634. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2635. if ($iassign_submission)
  2636. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2637. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2638. else
  2639. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2640. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2641. $this->activity->view_dates();
  2642. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2643. print $OUTPUT->box_start();
  2644. print '<table width=100% border=0 valign="top">' . "\n";
  2645. print '<tr><td width=60% valign="top">' . "\n";
  2646. $flag_dependency = true;
  2647. if ($iassign_statement_activity_item->type_iassign == 3) {
  2648. if ($iassign_statement_activity_item->dependency == 0) {
  2649. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2650. } else {
  2651. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2652. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2653. foreach ($dependencys as $dependency) {
  2654. if ($dependency) {
  2655. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2656. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2657. if ($dependencysubmissions) {
  2658. if ($dependencysubmissions->status == 3)
  2659. $icon = iassign_icons::insert('correct');
  2660. elseif ($dependencysubmissions->status == 2) {
  2661. $icon = iassign_icons::insert('incorrect');
  2662. $flag_dependency = false;
  2663. } elseif ($dependencysubmissions->status == 1) {
  2664. $icon = iassign_icons::insert('post');
  2665. $flag_dependency = false;
  2666. } elseif ($dependencysubmissions->status == 0) {
  2667. $icon = iassign_icons::insert('not_post');
  2668. $flag_dependency = false;
  2669. }
  2670. } else {
  2671. $icon = iassign_icons::insert('not_post');
  2672. $flag_dependency = false;
  2673. } // if ($dependencysubmissions)
  2674. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2675. } // if ($dependency)
  2676. } // foreach ($dependencys as $dependency)
  2677. } // if ($iassign_statement_activity_item->dependency == 0)
  2678. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2679. if ($flag_dependency == false) {
  2680. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2681. $this->view_iassign = false;
  2682. print '</tr></table>' . "\n";
  2683. }
  2684. else {
  2685. $this->view_iassign = true;
  2686. print '</td>' . "\n";
  2687. } // if ($flag_dependency == false)
  2688. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2689. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2690. // receiver=1 - message to teacher
  2691. // receiver=2 - message to student
  2692. if ($iassign_submission) {
  2693. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2694. if ($verify_message)
  2695. $comment = iassign_icons::insert('comment_unread');
  2696. }
  2697. print '<td width=40% valign="top" align="left">';
  2698. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2699. if ($iassign_statement_activity_item->show_answer == 1) {
  2700. // check status of solution sent by the student
  2701. if ($iassign_submission) {
  2702. switch ($iassign_submission->status) {
  2703. case 3 :
  2704. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2705. break;
  2706. case 2 :
  2707. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2708. break;
  2709. case 1 :
  2710. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2711. break;
  2712. default :
  2713. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2714. $repeat = "";
  2715. $last_iassign = "";
  2716. } // switch ($iassign_submission->status)
  2717. } else {
  2718. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2719. $repeat = "";
  2720. $last_iassign = "";
  2721. }
  2722. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2723. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2724. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2725. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2726. if ($iassign_statement_activity_item->max_experiment == 0)
  2727. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2728. else {
  2729. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2730. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2731. $repeat = "";
  2732. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2733. $this->bottonPost = 0;
  2734. $this->write_solution = 0;
  2735. }
  2736. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2737. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2738. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2739. if ($teacher)
  2740. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2741. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2742. } // if ($iassign_statement_activity_item->show_answer==1)
  2743. else {
  2744. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2745. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2746. $repeat = "";
  2747. $last_iassign = "";
  2748. } elseif ($iassign_submission->status == 1) {
  2749. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2750. }
  2751. }
  2752. print '</td>';
  2753. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2754. print '</tr></table>' . "\n";
  2755. // Presents the iLM
  2756. print '<table width=100% border=0 valign="top">' . "\n";
  2757. print '<td width=80% align="left">';
  2758. 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\".
  2759. print '<td width=20% align="rigth">';
  2760. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2761. print $repeat; // symbol of "redo activity"
  2762. print '</td></tr></table>' . "\n";
  2763. //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)'
  2764. print activity::toggle_columns_script();
  2765. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2766. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2767. $output = '';
  2768. if (!$iassign_ilm) {
  2769. $iassign_ilm = new stdClass();
  2770. $iassign_ilm->file_jar = "";
  2771. }
  2772. $output .= $OUTPUT->box_start();
  2773. $USER->iassignEdit = $this->bottonPost;
  2774. // ---
  2775. // Presents the iLM
  2776. // Prepare tags to present the iLM
  2777. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2778. $student_answer = ""; //?
  2779. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2780. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2781. $student_answer = "";
  2782. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2783. } else {
  2784. // When student is redoing his activity
  2785. // ATTENTION: exception used by iGeom (exercise with "script")
  2786. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2787. if (substr($ilm_name, 0, 5)=="igeom") {
  2788. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2789. $loadTeacherActivity = true;
  2790. }
  2791. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2792. }
  2793. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2794. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2795. //1 $history_comment = '';
  2796. //1 if ($iassign_submission) {
  2797. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2798. //1 }
  2799. //1 if (!empty($history_comment)) {
  2800. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2801. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2802. //1 $output .= $history_comment;
  2803. //1 $output .= "</table>\n";
  2804. //1 }
  2805. //1 $output .= "</form></center>\n";
  2806. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2807. //1 }
  2808. $output .= $OUTPUT->box_end();
  2809. print $output;
  2810. } // if ($this->view_iassign)
  2811. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2812. } // if ($this->view_iassign)
  2813. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2814. else
  2815. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2816. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2817. print '<table width=100% border=0 valign="top">' . "\n";
  2818. print '<tr><td width=60% valign="top">' . "\n";
  2819. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2820. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2821. print '</tr></table>' . "\n";
  2822. $student_answer = "";
  2823. $enderecoPOST = "";
  2824. // Prepare tags to present the iLM
  2825. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2826. print $output;
  2827. }
  2828. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2829. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2830. 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
  2831. // Put a block with area to sent/answer comments
  2832. $output = '';
  2833. $history_comment = '';
  2834. $row = optional_param('row', 0, PARAM_INT);
  2835. $column = optional_param('column', 0, PARAM_INT);
  2836. if ($iassign_submission) {
  2837. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2838. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2839. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2840. }
  2841. else {
  2842. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2843. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2844. }
  2845. $output .= $OUTPUT->box_start();
  2846. //if (!empty($history_comment)) {
  2847. $output .= "<a id='comments'></a>";
  2848. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2849. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2850. $output .= "</table>";
  2851. print " <script type='text/javascript'>
  2852. //<![CDATA[
  2853. function submit_comment(url) {
  2854. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2855. var formData = new FormData();
  2856. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2857. var request = new XMLHttpRequest();
  2858. request.open('POST', url);
  2859. document.getElementById('comments_history').innerHTML = '';
  2860. request.onload = function (e) {
  2861. if (request.readyState === 4) {
  2862. if (request.status === 200) {
  2863. document.getElementById('comments_history').innerHTML = request.responseText;
  2864. document.getElementById('check-message-success').style.visibility = 'visible';
  2865. setTimeout(function(){
  2866. document.getElementById('check-message-success').style.visibility = 'hidden';
  2867. }, 3000);
  2868. }
  2869. }
  2870. };
  2871. document.formEnvioComment.submission_comment.value = '';
  2872. request.send(formData);
  2873. }
  2874. function event_text_area (event) {
  2875. if (event.ctrlKey && event.keyCode == 13)
  2876. submit_comment('" . $enderecoPOSTcomment . "');
  2877. }
  2878. //]]>
  2879. </script>";
  2880. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2881. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
  2882. $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";
  2883. $output .= "</form> </center>\n";
  2884. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2885. // }
  2886. $output .= $OUTPUT->box_end();
  2887. print $output;
  2888. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2889. // final block 'studant'
  2890. print $OUTPUT->footer();
  2891. die();
  2892. } // function view_iassign_current()
  2893. /// Export the data from performance report into CSV file format
  2894. function export_csv () {
  2895. global $USER, $CFG, $DB, $OUTPUT;
  2896. $str = "";
  2897. $fields = "student_id, student_name";
  2898. // Finding all iassign activities for the iassign:
  2899. $id = $this->cm->id;
  2900. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2901. $c = 1;
  2902. foreach ($iassign_list as $iassign) {
  2903. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2904. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2905. $c++;
  2906. }
  2907. // Finding enrolled students:
  2908. $params_temp = array('shortname' => 'student');
  2909. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2910. $context = context_course::instance($this->course->id);
  2911. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2912. $students = $DB->get_records_sql(
  2913. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2914. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2915. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2916. foreach ($students as $student) {
  2917. $str .= $student->userid . ',';
  2918. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2919. foreach ($iassign_list as $iassign) {
  2920. $str .= ',' . $iassign->id . ',';
  2921. $str .= '"' . $iassign->name . '",';
  2922. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2923. if ($student_submissions) {
  2924. $str .= $student_submissions->experiment . ',';
  2925. $str .= $student_submissions->grade . ',';
  2926. switch ($student_submissions->status) {
  2927. case 3:
  2928. $str .= '"correct",';
  2929. break;
  2930. case 2:
  2931. $str .= '"incorrect",';
  2932. break;
  2933. case 1:
  2934. $str .= '"post",';
  2935. break;
  2936. case 0:
  2937. $str .= '"not_post",';
  2938. break;
  2939. }
  2940. }
  2941. else {
  2942. $str .= ',,"not_post",';
  2943. }
  2944. $str .= $iassign->iassign_ilmid . ',';
  2945. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2946. $str .= '"' . $ilm_activity->name . '"';
  2947. }
  2948. $str .= "\n";
  2949. }
  2950. $str = $fields . "\n" . $str;
  2951. header("Content-type: text/csv");
  2952. header("Content-disposition: attachment; filename=report.csv");
  2953. header("Pragma: no-cache");
  2954. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2955. header('Content-Length: ' . strlen($str));
  2956. header('Connection: close');
  2957. print $str;
  2958. flush();
  2959. } // function export_csv()
  2960. /// Display report of performance
  2961. function report () {
  2962. global $USER, $CFG, $DB, $OUTPUT;
  2963. $id = $this->cm->id;
  2964. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2965. if ($this->action != 'print') {
  2966. $title = get_string('report', 'iassign');
  2967. print $OUTPUT->header();
  2968. } // if ($this->action != 'print')
  2969. $this->print_main_menu();
  2970. print $OUTPUT->box_start();
  2971. $this->view_legend_icons();
  2972. print $OUTPUT->box_end();
  2973. if ($this->action == 'print')
  2974. print '<table border=1 width="100%">' . "\n";
  2975. else
  2976. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
  2977. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2978. // $num = array();
  2979. $i = 1;
  2980. $num = array();
  2981. $stylebutton = "background: none; -webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75); min-width: 4.5rem;";
  2982. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2983. $test_exercise = "";
  2984. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2985. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2986. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2987. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2988. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2989. $num[$i] = new stdClass();
  2990. $num[$i]->name = $iassign->name;
  2991. $num[$i]->id = $i;
  2992. $num[$i]->iassignid = $iassign->id;
  2993. print ' <tr >' . "\n";
  2994. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2995. print "<td class=\"cell c0 actvity\">";
  2996. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2997. print ' </tr>' . "\n";
  2998. $i++;
  2999. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  3000. } // foreach ($iassign_list as $iassign)
  3001. $num_exerc = $i; // total of exercises
  3002. print "</table>";
  3003. print "<p></p>";
  3004. if ($this->action == 'print')
  3005. print '<table border=1 width="100%">' . "\n";
  3006. else // ./theme/boost/style/moodle.css: .generaltable
  3007. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  3008. $context = context_course::instance($this->course->id);
  3009. if ($num_exerc > 1) {
  3010. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3011. $params_temp = array('shortname' => 'student');
  3012. $role = $DB->get_record_sql(
  3013. "SELECT s.id, s.shortname FROM {role} s " .
  3014. " WHERE s.shortname = :shortname", $params_temp);
  3015. // $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");
  3016. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3017. $students = $DB->get_records_sql(
  3018. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3019. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3020. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3021. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  3022. $width = 90/$num_exerc;
  3023. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  3024. $sum_iassign_correct[$j] = 0;
  3025. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  3026. }
  3027. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  3028. $sum_iassign = $j - 1;
  3029. print '</tr>' . "\n";
  3030. $total = 0;
  3031. $sum_student = 0;
  3032. $comment = iassign_icons::insert('comment_read');
  3033. $sum_comment = 0;
  3034. $sum_correct_iassign = array();
  3035. $sum_correct_student = array();
  3036. $USER->matrix_iassign = array();
  3037. if ($students) {
  3038. $w = 0;
  3039. foreach ($students as $tmp) { // count students
  3040. $users_array[$w] = $tmp;
  3041. $w++;
  3042. }
  3043. for ($x=0; $x<$w; $x++) { // for all students
  3044. print '<tr>' . "\n";
  3045. $sum_student++;
  3046. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  3047. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  3048. $total_student = 0;
  3049. $tentativas = 0;
  3050. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  3051. $sum_comment = $sum_verify_message = 0;
  3052. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  3053. if ($student_submissions) {
  3054. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  3055. $tentativas = $student_submissions->experiment;
  3056. // Get student comments
  3057. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  3058. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  3059. $student_submissions_comment = $DB->get_record_sql(
  3060. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3061. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  3062. if ($student_submissions_comment) // student has comment
  3063. foreach ($student_submissions_comment as $tmp)
  3064. $sum_comment = $tmp;
  3065. // informations to previous activities
  3066. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  3067. else $iassign_previous = $num[$j - 1]->iassignid;
  3068. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3069. else $user_previous = $users_array[$x - 1]->userid;
  3070. // next
  3071. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3072. else $iassign_next = "-1";
  3073. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3074. else $user_next = "-1";
  3075. $position = "&row= $x&column=$j";
  3076. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  3077. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3078. $url .= $position;
  3079. // receiver=1 - message to teacher
  3080. // receiver=2 - message to student
  3081. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  3082. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  3083. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  3084. $verify_message = $DB->get_record_sql(
  3085. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3086. "WHERE iassign_submissionid = :iassign_submissionid " .
  3087. " AND return_status= :return_status " .
  3088. " AND receiver= :receiver", $params_temp);
  3089. if ($verify_message)
  3090. foreach ($verify_message as $tmp)
  3091. $sum_verify_message = $tmp;
  3092. if ($sum_verify_message > 0)
  3093. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  3094. else
  3095. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  3096. if ($student_submissions->status == 3) {
  3097. $sum_iassign_correct[$j]++;
  3098. $total_student++;
  3099. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  3100. }
  3101. elseif ($student_submissions->status == 2) {
  3102. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  3103. }
  3104. elseif ($student_submissions->status == 1) {
  3105. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3106. }
  3107. elseif ($student_submissions->status == 0) {
  3108. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3109. }
  3110. if ($this->action != 'print') {
  3111. if ($tentativas > 0)
  3112. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3113. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3114. . $feedback
  3115. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3116. . $tentativas
  3117. . '</span> </button>'
  3118. . '</a>' . "\n";
  3119. else
  3120. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3121. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3122. . $feedback
  3123. .'</button>'
  3124. . '</a>' . "\n";
  3125. if ($sum_comment > 0 && $sum_verify_message > 0)
  3126. print '<a href="' . $url . '"> '
  3127. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3128. . $comment
  3129. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3130. . $sum_verify_message . '/' . $sum_comment
  3131. . '</span> </button>'
  3132. . '</a>';
  3133. else if ($sum_comment > 0)
  3134. print '<a href="' . $url . '"> '
  3135. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  3136. . $comment
  3137. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3138. . $sum_comment
  3139. . '</span> </button>'
  3140. . '</a>';
  3141. print '</td>' . "\n";
  3142. }
  3143. if ($this->action == 'print')
  3144. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3145. } // if ($student_submissions)
  3146. else { // if ($student_submissions)
  3147. // Student does not have any submission
  3148. // informations to browse previous activities
  3149. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3150. else $iassign_previous = $num[$j - 1]->iassignid;
  3151. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3152. else $user_previous = $users_array[$x - 1]->userid;
  3153. // next
  3154. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3155. else $iassign_next = "-1";
  3156. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3157. else $user_next = "-1";
  3158. $position = "&row= $x&column=$j";
  3159. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3160. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3161. $url .= $position;
  3162. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3163. if ($this->action == 'print')
  3164. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3165. else {
  3166. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3167. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3168. . $feedback
  3169. .'</button>'
  3170. . '</a>' . "\n";
  3171. // print '<td> &nbsp;</td>';
  3172. if ($sum_comment > 0)
  3173. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3174. // else print '<td> &nbsp;</td>';
  3175. print '</td>';
  3176. }
  3177. } // else if ($student_submissions)
  3178. $USER->matrix_iassign[$x][$j] = new stdClass();
  3179. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3180. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3181. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3182. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3183. if ($student_submissions)
  3184. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3185. else
  3186. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3187. //print '</td>' . "\n";
  3188. } // for ($j=1; $j<$num_exerc; $j++)
  3189. $total = $total + $total_student;
  3190. $porcentagem = ($total_student / ($j - 1)) * 100;
  3191. if ($tentativas != 0 && $tentativas != null) {
  3192. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3193. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3194. }
  3195. else {
  3196. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3197. }
  3198. print '</tr>' . "\n";
  3199. $sum_correct_student[$sum_student] = new stdClass();
  3200. $sum_correct_student[$sum_student]->name = $name;
  3201. $sum_correct_student[$sum_student]->sum = $total_student;
  3202. } // for ($x = 0; $x < $w; $x ++)
  3203. for ($i = 1; $i < $j; $i++) {
  3204. if (is_null($sum_iassign_correct[$i]))
  3205. $sum_iassign_correct[$i] = 0;
  3206. $sum_correct_iassign[$i] = new stdClass();
  3207. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3208. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3209. }
  3210. // print '</tr></table>' . "\n";
  3211. }
  3212. } // if ($i>1)
  3213. else {
  3214. print_string('no_activity', 'iassign');
  3215. }
  3216. print "</table>\n";
  3217. print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . "</p>\n"; // the number of atemps is...
  3218. print '<p>' . get_string('ps_comment', 'iassign') . "</p>\n"; // the total number of messages is...
  3219. if ($this->action != 'print')
  3220. print $OUTPUT->footer();
  3221. die();
  3222. } // function report()
  3223. /// Display graphics of performance
  3224. function stats () {
  3225. global $USER, $CFG, $DB, $OUTPUT;
  3226. $id = $this->cm->id;
  3227. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3228. if ($this->action != 'printstats')
  3229. $title = get_string('graphic', 'iassign');
  3230. $num = array();
  3231. $sum_correct_iassign = array();
  3232. $sum_correct_student = array();
  3233. $sum_student = 0;
  3234. $i = 1;
  3235. foreach ($iassign_list as $iassign) {
  3236. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3237. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3238. $sum_iassign_correct[$i] = 0;
  3239. $num[$i] = new stdClass();
  3240. $num[$i]->name = $iassign->name;
  3241. $num[$i]->id = $i;
  3242. $num[$i]->iassignid = $iassign->id;
  3243. $i++;
  3244. } // if ($iassign->type_iassign == 3)
  3245. } // foreach ($iassign_list as $iassign)
  3246. $sum_iassign = $i - 1;
  3247. $context = context_course::instance($this->course->id);
  3248. if ($i > 1) {
  3249. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3250. $params_temp = array('shortname' => 'student');
  3251. $role = $DB->get_record_sql(
  3252. "SELECT s.id, s.shortname FROM {role} s " .
  3253. " WHERE s.shortname = :shortname", $params_temp);
  3254. // $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");
  3255. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3256. $students = $DB->get_records_sql(
  3257. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3258. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3259. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3260. $total = 0;
  3261. $sum_student = 0;
  3262. $j = 0;
  3263. $sum_correct_iassign = array();
  3264. $sum_correct_student = array();
  3265. $sum_experiment = array();
  3266. if ($students) {
  3267. foreach ($students as $users) {
  3268. $sum_student++;
  3269. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3270. // rows
  3271. $total_student = 0;
  3272. for ($j = 1; $j < $i; $j++) {
  3273. $total_experiment = 0;
  3274. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3275. if ($student_submissions) {
  3276. if ($student_submissions->status == 3) {
  3277. $sum_iassign_correct[$j]++;
  3278. $total_student++;
  3279. } // if ($student_submissions->status == 3)
  3280. $total_experiment += $student_submissions->experiment;
  3281. }
  3282. $sum_experiment[$j] = $total_experiment;
  3283. } // for ($j=1; $j<$i; $j++)
  3284. $total = $total + $total_student;
  3285. $sum_correct_student[$sum_student] = new stdClass();
  3286. $sum_correct_student[$sum_student]->name = $name;
  3287. $sum_correct_student[$sum_student]->sum = $total_student;
  3288. } // foreach ($students as $users)
  3289. }
  3290. for ($i = 1; $i < $j; $i++) {
  3291. if (is_null($sum_iassign_correct[$i]))
  3292. $sum_iassign_correct[$i] = 0;
  3293. $sum_correct_iassign[$i] = new stdClass();
  3294. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3295. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3296. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3297. } // for ($i = 1; $i < $j; $i++)
  3298. } // if ($i > 1)
  3299. print $OUTPUT->header();
  3300. $this->print_main_menu();
  3301. if ($this->action != 'printstats') {
  3302. $title = get_string('graphic', 'iassign');
  3303. $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>";
  3304. $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>";
  3305. print '<table width=100%><tr>';
  3306. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3307. print '<td width=15% align="right">' . $link_report . '</td>';
  3308. print '</td></tr></table>' . "\n";
  3309. print "<br><br>";
  3310. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3311. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3312. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3313. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3314. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3315. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3316. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3317. print '</tr>' . "\n";
  3318. $sum_correct = 0;
  3319. if ($sum_correct_iassign) {
  3320. foreach ($sum_correct_iassign as $iassign) {
  3321. if (is_null($iassign->experiment))
  3322. $iassign->experiment = 0;
  3323. $bar = "";
  3324. $sum = $iassign->sum;
  3325. $percent = ($sum / $sum_student) * 100;
  3326. $text = number_format($percent, 1) . '%';
  3327. $sum_correct += $sum;
  3328. if ($sum > 0) {
  3329. for ($i = 1; $i < $percent * 2; $i++)
  3330. $bar .= iassign_icons::insert('hbar_blue');
  3331. $bar .= iassign_icons::insert('hbar_blue_r');
  3332. } // if ($sum > 0)
  3333. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3334. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3335. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3336. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3337. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3338. print '</tr>' . "\n";
  3339. } // foreach ($sum_correct_iassign as $iassign)
  3340. }
  3341. print "</table>";
  3342. print "<br><br>";
  3343. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3344. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3345. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3346. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3347. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3348. print '</tr>' . "\n";
  3349. $sum_correct = 0;
  3350. foreach ($sum_correct_student as $student) {
  3351. $bar = "";
  3352. $sum = $student->sum;
  3353. $percent = ($sum / $sum_iassign) * 100;
  3354. $text = number_format($percent, 1) . '%';
  3355. $sum_correct += $sum;
  3356. if ($sum > 0) {
  3357. for ($i = 1; $i < $percent * 2; $i++)
  3358. $bar .= iassign_icons::insert('hbar_blue');
  3359. $bar .= iassign_icons::insert('hbar_blue_r');
  3360. } // if ($sum > 0)
  3361. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3362. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3363. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3364. print '</tr>' . "\n";
  3365. } // foreach ($sum_correct_student as $student)
  3366. print "</table>\n";
  3367. print "<br><br>\n";
  3368. $var = 0;
  3369. $cv = 0;
  3370. $dv = 0;
  3371. $avg = 0;
  3372. if ($sum_correct_student) {
  3373. $avg = $sum_correct / $sum_student;
  3374. if ($avg > 0) {
  3375. foreach ($sum_correct_student as $student)
  3376. $var += pow($student->sum - $avg, 2);
  3377. $var = $var / $sum_student;
  3378. $dv = sqrt($var);
  3379. $cv = ($dv / $avg) * 100;
  3380. }
  3381. }
  3382. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3383. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3384. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3385. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3386. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3387. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3388. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3389. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3390. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3391. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3392. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3393. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3394. print "</table>\n";
  3395. print $OUTPUT->footer();
  3396. } else {
  3397. print "<STYLE TYPE='text/css'>
  3398. <!--
  3399. .boldtable {
  3400. font-family:sans-serif;
  3401. font-size:10pt;
  3402. }
  3403. -->
  3404. </STYLE>\n";
  3405. print '<table border=1 width=100%>' . "\n";
  3406. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3407. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3408. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3409. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3410. print '</tr>' . "\n";
  3411. $sum_correct = 0;
  3412. foreach ($sum_correct_iassign as $iassign) {
  3413. $bar = "";
  3414. $sum = $iassign->sum;
  3415. $percent = ($sum / $sum_student) * 100;
  3416. $text = number_format($percent, 1) . '%';
  3417. $sum_correct += $sum;
  3418. if ($sum > 0) {
  3419. for ($i = 1; $i < $percent * 2; $i++)
  3420. $bar .= iassign_icons::insert('hbar_blue');
  3421. $bar .= iassign_icons::insert('hbar_blue_r');
  3422. } // if ($sum > 0)
  3423. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3424. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3425. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3426. print '</tr>' . "\n";
  3427. } // foreach ($sum_correct_iassign as $iassign)
  3428. print "</table>";
  3429. print "<br><br>";
  3430. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3431. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3432. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3433. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3434. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3435. print '</tr>' . "\n";
  3436. $sum_correct = 0;
  3437. foreach ($sum_correct_student as $student) {
  3438. $bar = "";
  3439. $sum = $student->sum;
  3440. $percent = ($sum / $sum_iassign) * 100;
  3441. $text = number_format($percent, 1) . '%';
  3442. $sum_correct += $sum;
  3443. if ($sum > 0) {
  3444. for ($i = 1; $i < $percent * 2; $i++)
  3445. $bar .= iassign_icons::insert('hbar_blue');
  3446. $bar .= iassign_icons::insert('hbar_blue_r');
  3447. } // if ($sum > 0)
  3448. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3449. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3450. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3451. print '</tr>' . "\n";
  3452. } // foreach ($sum_correct_student as $student)
  3453. print "</table>\n";
  3454. print "<br/><br/>\n";
  3455. $var = 0;
  3456. $cv = 0;
  3457. $dv = 0;
  3458. $avg = 0;
  3459. if ($sum_correct_student) {
  3460. $avg = $sum_correct / $sum_student;
  3461. if ($avg > 0) {
  3462. foreach ($sum_correct_student as $student)
  3463. $var += pow($student->sum - $avg, 2);
  3464. $var = $var / $sum_student;
  3465. $dv = sqrt($var);
  3466. $cv = ($dv / $avg) * 100;
  3467. }
  3468. }
  3469. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3470. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3471. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3472. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3473. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3474. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3475. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3476. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3477. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3478. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3479. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3480. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3481. print "</table>\n";
  3482. } // if ($this->action != 'printstats')
  3483. die();
  3484. }
  3485. /// Display graphics of performance for students
  3486. function stats_students () {
  3487. global $USER, $CFG, $DB, $OUTPUT;
  3488. $id = $this->cm->id;
  3489. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3490. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3491. $title = get_string('results', 'iassign');
  3492. $sum_correct = 0;
  3493. $sum_incorrect = 0;
  3494. $sum_post = 0;
  3495. $sum_nopost = 0;
  3496. $sum_iassign = count($iassign_statement_list);
  3497. $bar_nopost = "";
  3498. $bar_correct = "";
  3499. $bar_incorrect = "";
  3500. $bar_post = "";
  3501. $text_nopost = "";
  3502. $text_correct = "";
  3503. $text_incorrect = "";
  3504. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3505. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3506. if ($iassign_submission) {
  3507. if ($iassign_submission->status == 3)
  3508. $sum_correct++;
  3509. elseif ($iassign_submission->status == 2)
  3510. $sum_incorrect++;
  3511. elseif ($iassign_submission->status == 1)
  3512. $sum_post++;
  3513. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3514. $sum_nopost++;
  3515. } // if ($iassign_submission)
  3516. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3517. if ($sum_iassign > 0) {
  3518. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3519. $text_correct = number_format($percent_correct, 1) . '%';
  3520. }
  3521. if ($sum_correct > 0) {
  3522. for ($i = 1; $i < $percent_correct * 2; $i++)
  3523. $bar_correct .= iassign_icons::insert('hbar_green');
  3524. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3525. } // if ($sum_correct > 0)
  3526. if ($sum_iassign > 0) {
  3527. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3528. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3529. }
  3530. if ($sum_incorrect > 0) {
  3531. for ($i = 1; $i < $percent_incorrect * 2; $i++)
  3532. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3533. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3534. } // if ($sum_incorrect > 0)
  3535. if ($sum_iassign > 0) {
  3536. $percent_post = ($sum_post / $sum_iassign) * 100;
  3537. $text_post = number_format($percent_post, 1) . '%';
  3538. }
  3539. if ($sum_post > 0) {
  3540. for ($i = 1; $i < $percent_post * 2; $i++)
  3541. $bar_post .= iassign_icons::insert('hbar_blue');
  3542. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3543. } // if ($sum_post > 0)
  3544. if ($sum_iassign > 0) {
  3545. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3546. $text_nopost = number_format($percent_nopost, 1) . '%';
  3547. }
  3548. if ($sum_nopost > 0) {
  3549. for ($i = 1; $i < $percent_nopost * 2; $i++)
  3550. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3551. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3552. } // if ($sum_nopost > 0)
  3553. print $OUTPUT->header();
  3554. $this->print_main_menu();
  3555. //2021/12 $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3556. //2021/12 print '<table width=100%><tr>';
  3557. //2021/12 print '<td align="right">' . $link_return . '</td>' . "\n";
  3558. //2021/12 print '</td></tr></table>' . "\n";
  3559. print "<br/><br/>\n";
  3560. print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
  3561. print '<tr><th colspan=3 class="header c1">' . "\n";
  3562. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3563. // $imagetext = '');
  3564. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3565. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3566. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3567. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3568. print '</tr>' . "\n";
  3569. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3570. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3571. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3572. print '</tr>' . "\n";
  3573. if ($sum_post) {
  3574. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3575. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3576. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3577. print '</tr>' . "\n";
  3578. } // if ($sum_post)
  3579. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3580. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3581. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3582. print '</tr>' . "\n";
  3583. print "</table>";
  3584. print "<br><br>";
  3585. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3586. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3587. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3588. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3589. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3590. $sum_grade = 0;
  3591. $sum_grade_student = 0;
  3592. $avg = 0;
  3593. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3594. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3595. if (!$iassign_submission) {
  3596. $iassign_submission = new stdClass();
  3597. $iassign_submission->grade = 0;
  3598. }
  3599. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3600. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3601. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3602. print '</tr>' . "\n";
  3603. $sum_grade += $iassign_statement_activity_item->grade;
  3604. $sum_grade_student += $iassign_submission->grade;
  3605. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3606. if ($sum_grade > 0)
  3607. $avg = $sum_grade_student / $sum_grade * 100;
  3608. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3609. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3610. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3611. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3612. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3613. print "</table>";
  3614. print $OUTPUT->footer();
  3615. die();
  3616. } // function stats_students()
  3617. function get_total_notifications () {
  3618. global $DB, $USER, $COURSE;
  3619. $total_messages = 0;
  3620. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3621. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3622. $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3623. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3624. }
  3625. else {
  3626. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3627. $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3628. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3629. }
  3630. return $total_messages->total;
  3631. }
  3632. function get_iassign_statement_messages () {
  3633. global $DB, $USER, $COURSE;
  3634. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3635. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3636. $totais = array();
  3637. $messages = $DB->get_records_sql("SELECT c.id AS commentid, st.id AS stid, s.userid AS user, ias.id AS iasid, s.id AS subid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3638. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3639. foreach($messages as $item) {
  3640. if (isset($totais[$item->subid])) {
  3641. $totais[$item->subid]->total++;
  3642. }
  3643. else {
  3644. $totais[$item->subid] = new stdclass();
  3645. $item->total = 1;
  3646. $totais[$item->subid] = $item;
  3647. }
  3648. }
  3649. return $totais;
  3650. }
  3651. else {
  3652. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3653. $totais = array();
  3654. $messages = $DB->get_records_sql("SELECT c.id as commentid, s.id AS subid, st.id AS stid, ias.id AS iasid, s.userid AS userid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3655. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3656. foreach($messages as $item) {
  3657. if (isset($totais[$item->subid])) {
  3658. $totais[$item->subid]->total++;
  3659. }
  3660. else {
  3661. $totais[$item->subid] = new stdclass();
  3662. $item->total = 1;
  3663. $totais[$item->subid] = $item;
  3664. }
  3665. }
  3666. return $totais;
  3667. }
  3668. }
  3669. function view_notifications_teachers () {
  3670. global $OUTPUT, $USER, $DB;
  3671. $messages = $this->get_iassign_statement_messages();
  3672. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3673. // 1º. listar as mensagens recebidas no bloco atual:
  3674. $actual_block = $this->iassign->id;
  3675. $id = $this->cm->id;
  3676. $total_include = 0;
  3677. $activities_actual_block = array();
  3678. if ($messages)
  3679. foreach ($messages as $item)
  3680. if ($item->iasid == $actual_block)
  3681. if (!in_array($item->stid, $activities_actual_block))
  3682. array_push($activities_actual_block, $item->stid);
  3683. if ($activities_actual_block)
  3684. foreach ($activities_actual_block as $activity_id) {
  3685. $printed = false;
  3686. foreach ($messages as $item) {
  3687. if ($item->stid == $activity_id) {
  3688. if (!$printed) {
  3689. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
  3690. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3691. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3692. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3693. $printed = true;
  3694. }
  3695. $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
  3696. $user = $DB->get_record('user', array('id' => $item->user));
  3697. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3698. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3699. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3700. '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td>'
  3701. .'</tr>';
  3702. $total_include++;
  3703. }
  3704. }
  3705. print '</td></tr></table>';
  3706. }
  3707. print '</table>';
  3708. if (count($activities_actual_block) == 0) {
  3709. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3710. print '<hr class="my-4">';
  3711. }
  3712. if ($messages && $total_include == count($messages)) {
  3713. print $OUTPUT->footer();
  3714. return;
  3715. }
  3716. print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
  3717. $iassign_ids = array();
  3718. if ($messages)
  3719. foreach ($messages as $item)
  3720. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3721. array_push($iassign_ids, $item->iasid);
  3722. foreach ($iassign_ids as $id_iassign) {
  3723. $printed = false;
  3724. $activities_in_block = array();
  3725. foreach ($messages as $subitem)
  3726. if ($subitem->iasid == $id_iassign)
  3727. if (!in_array($item->stid, $activities_in_block))
  3728. array_push($activities_in_block, $item->stid);
  3729. foreach ($messages as $item) {
  3730. if ($item->iasid == $id_iassign) {
  3731. if (!$printed) {
  3732. $printed = true;
  3733. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3734. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3735. }
  3736. foreach ($activities_in_block as $id_activity) {
  3737. $print = false;
  3738. foreach ($messages as $subitem) {
  3739. if ($subitem->stid == $id_activity) {
  3740. if (!$print) {
  3741. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
  3742. $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
  3743. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3744. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3745. $print = true;
  3746. }
  3747. foreach ($messages as $comment_student) {
  3748. if ($comment_student->stid == $id_activity) {
  3749. $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
  3750. $user = $DB->get_record('user', array('id' => $comment_student->user));
  3751. $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3752. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3753. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3754. '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$comment_student->total.'</span> </span></a></td>'
  3755. .'</tr>';
  3756. }
  3757. }
  3758. break;
  3759. }
  3760. }
  3761. }
  3762. print '</table></td></tr></table>';
  3763. break;
  3764. }
  3765. }
  3766. }
  3767. print $OUTPUT->footer();
  3768. }
  3769. function view_notifications () {
  3770. global $OUTPUT, $USER;
  3771. print $OUTPUT->header();
  3772. $this->print_main_menu();
  3773. print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
  3774. if ($this->get_total_notifications() == 0) {
  3775. print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
  3776. print '<hr class="my-4">';
  3777. print $OUTPUT->footer();
  3778. return;
  3779. }
  3780. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3781. $this->view_notifications_teachers();
  3782. return;
  3783. }
  3784. $messages = $this->get_iassign_statement_messages();
  3785. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3786. // 1º. listar as mensagens recebidas no bloco atual:
  3787. $actual_block = $this->iassign->id;
  3788. $id = $this->cm->id;
  3789. $total_include = 0;
  3790. if ($messages)
  3791. foreach ($messages as $item) {
  3792. if ($item->iasid == $actual_block) {
  3793. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3794. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3795. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3796. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td></tr>';
  3797. $total_include++;
  3798. }
  3799. }
  3800. print '</table>';
  3801. if ($total_include == 0) {
  3802. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3803. print '<hr class="my-4">';
  3804. }
  3805. if ($messages && $total_include == count($messages)) {
  3806. print $OUTPUT->footer();
  3807. return;
  3808. }
  3809. print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
  3810. // 2º. listar as mensagens recebidas nos demais blocos do curso:
  3811. $iassign_ids = array();
  3812. if ($messages)
  3813. foreach ($messages as $item)
  3814. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3815. array_push($iassign_ids, $item->iasid);
  3816. foreach ($iassign_ids as $id_iassign) {
  3817. $printed = false;
  3818. foreach ($messages as $item) {
  3819. if ($item->iasid == $id_iassign) {
  3820. if (!$printed) {
  3821. $printed = true;
  3822. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3823. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3824. }
  3825. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3826. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3827. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3828. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a> </td></tr>';
  3829. }
  3830. }
  3831. print '</table>';
  3832. }
  3833. print $OUTPUT->footer();
  3834. }
  3835. function print_main_menu () {
  3836. global $USER;
  3837. $id = $this->cm->id;
  3838. $actual_action = optional_param('action', '', PARAM_TEXT);
  3839. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3840. $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
  3841. $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
  3842. $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
  3843. $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
  3844. $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
  3845. $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
  3846. $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
  3847. $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
  3848. $url_import_activity = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'import_activity', 'iassignid' => $this->iassign->id));
  3849. print '<div class="btn-group" role="group" aria-label="">';
  3850. print '<a href="' . $url_home . '" class="btn btn-outline-primary ' . ($actual_action == '' ? 'active' : '') . '">' . "\n";
  3851. print ' <i class="fa fa-home" aria-hidden="true"></i> ' . get_string('activities_page', 'iassign') . "</a>\n";
  3852. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3853. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3854. // Has capability to see "report": teacher or up
  3855. print '<a href="'.$url_help.'" class="btn btn-outline-primary"><i class="fa fa-question-circle" aria-hidden="true"></i> '.get_string('help_ilm', 'iassign').'</a>';
  3856. print '<div class="btn-group"><div class="btn-group">
  3857. <a href="'.$url_report.'" class="btn btn-outline-primary '.($actual_action == 'report' || $actual_action == 'stats' || $actual_action == 'all_submissions' ? 'active' : '').' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  3858. <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
  3859. <div class="dropdown-menu">
  3860. <a href="'.$url_report.'" class=" '.($actual_action == 'report' ? 'active' : ''). ' dropdown-item"><i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('home', 'iassign').'</a>
  3861. <div class="dropdown-divider"></div>
  3862. <a href="'.$url_sub_stats.'" class="dropdown-item '.($actual_action == 'stats' ? 'active' : '').'"><i class="fa fa-pie-chart" aria-hidden="true"></i> '.get_string('graphic', 'iassign') .'</a>
  3863. <div class="dropdown-divider"></div>
  3864. <a href="'.$url_all_submissions.'" class="dropdown-item '.($actual_action == 'all_submissions' ? 'active' : '').'"><i class="fa fa-files-o" aria-hidden="true"></i> '.get_string('all_submissions_manager', 'iassign') .'</a>
  3865. </div>
  3866. </div>
  3867. '; // "
  3868. print '<a href="'.$url_stats.'" class="btn btn-outline-primary '.($actual_action == 'stats_student' ? 'active' : '').'"><i class="fa fa-list" aria-hidden="true"></i> '.get_string('results', 'iassign').'</a>';
  3869. print '<a href="'.$url_auto_evaluate.'" class="btn btn-outline-primary '.($actual_action == 'auto_evaluate' ? 'active' : '').'"><i class="fa fa-check-square-o" aria-hidden="true"></i> '.get_string('auto_evaluate_name_config', 'iassign').'</a>';
  3870. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3871. $notifications = $this->get_total_notifications();
  3872. print '<a href="' . $url_notifications . '" class="btn btn-outline-primary ' . ($actual_action == 'notifications' ? 'active' : '') . '">' . "\n"; // '
  3873. print ' <i class="fa fa-bell" aria-hidden="true"></i> ' . get_string('notifications', 'iassign');
  3874. if ($notifications > 0)
  3875. print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
  3876. print '</a></div><div class="btn-group">';
  3877. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3878. print '<a href="' . $url_add . '" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i> ' . get_string('add_iassign', 'iassign') . "</a>\n";
  3879. print '
  3880. <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  3881. </button>
  3882. <div class="dropdown-menu">
  3883. <a class="dropdown-item" href="'.$url_import_activity.'">'.get_string('import_activity', 'iassign').'</a>
  3884. </div>'; // "
  3885. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3886. print '</div></div>' . "\n";
  3887. }
  3888. /// Display page of iAssign's block of activities
  3889. function view_iassigns () {
  3890. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3891. $id = $this->cm->id;
  3892. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3893. $notice = optional_param('notice', '', PARAM_TEXT);
  3894. if (strpos($notice, 'error'))
  3895. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3896. else if ($notice != '')
  3897. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3898. $this->print_main_menu(); // teachers' menu: Page of activities; About iLM; Report; Results; Reevaluation; Notifications
  3899. print $OUTPUT->box_start();
  3900. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3901. print '<div class="border float-right">' . "\n";
  3902. if ($iassign_list) {
  3903. // $USER->iassignEdit == 0 view 'Turn editing off'
  3904. // $USER->iassignEdit == 1 view 'Turn editing on'
  3905. if (!isset($USER->iassignEdit))
  3906. $USER->iassignEdit = 0;
  3907. if ($USER->iassignEdit == 0) {
  3908. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3909. $botton = 1;
  3910. }
  3911. elseif ($USER->iassignEdit == 1) {
  3912. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3913. $botton = 0;
  3914. }
  3915. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3916. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3917. print " <input class='btn btn-primary' type=submit value='" . $bottonEdit_message . "'/>\n";
  3918. print "</form>\n";
  3919. } // if ($iassign_list)
  3920. print "</div>\n";
  3921. }
  3922. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3923. // $this->view_legend_icons();
  3924. print $OUTPUT->box_end();
  3925. $iassign_array_exercise = array();
  3926. $i_exercise = 0; // count total number of activities of type 'exercise' inside the block
  3927. $iassign_array_test = array();
  3928. $i_test = 0; // count total number of activities of type 'test' inside the block
  3929. $iassign_array_example = array();
  3930. $i_example = 0; // count total number of activities of type 'example' inside the block
  3931. $iassign_array_general = array();
  3932. $i_general = 0;
  3933. if ($iassign_list) {
  3934. if ($this->iassign->activity_group == 0) {
  3935. foreach ($iassign_list as $iassign) {
  3936. $iassign_array_general[$i_general] = $iassign;
  3937. $i_general++;
  3938. }
  3939. } // if ($this->iassign->activity_group == 0)
  3940. else {
  3941. foreach ($iassign_list as $iassign) {
  3942. if ($iassign->type_iassign == 3) {
  3943. $iassign_array_exercise[$i_exercise] = $iassign;
  3944. $i_exercise++;
  3945. } // if ($iassign->type_iassign == 3)
  3946. if ($iassign->type_iassign == 2) {
  3947. $iassign_array_test[$i_test] = $iassign;
  3948. $i_test++;
  3949. } // if ($iassign->type_iassign == 2)
  3950. if ($iassign->type_iassign == 1) {
  3951. $iassign_array_example[$i_example] = $iassign;
  3952. $i_example++;
  3953. } // if ($iassign->type_iassign == 1)
  3954. }
  3955. }
  3956. if ($iassign_array_exercise) {
  3957. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3958. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3959. }
  3960. if ($iassign_array_test) {
  3961. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3962. $this->show_iassign($title, $iassign_array_test, $i_test);
  3963. }
  3964. if ($iassign_array_example) {
  3965. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3966. $this->show_iassign($title, $iassign_array_example, $i_example);
  3967. }
  3968. if ($iassign_array_general) {
  3969. $title = "";
  3970. $this->show_iassign($title, $iassign_array_general, $i_general);
  3971. }
  3972. } else { // if ($iassign_list)
  3973. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3974. }
  3975. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3976. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3977. print $OUTPUT->box_start();
  3978. print '<table width=100% border=0><tr>' . "\n";
  3979. print '<td width=10% align="left">' . "\n";
  3980. print $link_report;
  3981. print '</td>' . "\n";
  3982. print '</tr></table>' . "\n";
  3983. print $OUTPUT->box_end();
  3984. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3985. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3986. print $OUTPUT->box_start();
  3987. print '<table width=100% border=0><tr>' . "\n";
  3988. print '<td align="left">' . "\n";
  3989. print $link_add;
  3990. print '</td>' . "\n";
  3991. print '</tr></table>' . "\n";
  3992. print $OUTPUT->box_end();
  3993. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3994. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3995. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3996. // $this->view_legend_icons();
  3997. } // function view_iassigns()
  3998. /// Display all iAssigns: the list of activities inside the iAssign block
  3999. // HTTP: ./mod/iassign/view.php?id= <$id>
  4000. function show_iassign ($title, $iassign_array, $total_of_activities) {
  4001. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  4002. $id = $this->cm->id; // ID of iAssign block (accessed throgh table "couse_module")
  4003. print $OUTPUT->box_start();
  4004. print " <script type='text/javascript'>
  4005. //<![CDATA[
  4006. function validate_move () {
  4007. var radios = document.getElementsByName('iassign_destiny');
  4008. var formValid = false;
  4009. //alert('aqui validate_move()');
  4010. var i = 0;
  4011. while (!formValid && i < radios.length) {
  4012. if (radios[i].checked) formValid = true;
  4013. i++;
  4014. }
  4015. if (!formValid) {
  4016. document.getElementById('move_dest').classList.add('alert-danger');
  4017. }
  4018. return formValid;
  4019. }
  4020. var modal;
  4021. function load_move(id_ias) {
  4022. document.form_move_activity.iassign_current.value = id_ias;
  4023. modal.style.display = 'block';
  4024. var radios = document.getElementsByName('iassign_destiny');
  4025. var i = 0;
  4026. while (i < radios.length) {
  4027. radios[i].checked = false;
  4028. i++;
  4029. }
  4030. document.getElementById('move_dest').classList.remove('alert-danger');
  4031. }
  4032. function closeModal () {
  4033. modal.style.display = 'none';
  4034. }
  4035. function load_modal_elements () {
  4036. modal = document.getElementById('myModal');
  4037. var span = document.getElementById('close_modal');
  4038. span.onclick = function() {
  4039. modal.style.display = 'none';
  4040. }
  4041. window.onclick = function(event) {
  4042. if (event.target == modal) {
  4043. modal.style.display = 'none';
  4044. }
  4045. }
  4046. }
  4047. window.onload = load_modal_elements;
  4048. //]]>
  4049. </script>\n";
  4050. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  4051. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  4052. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  4053. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  4054. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  4055. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  4056. <input type='hidden' name='iassign_current' value='' />";
  4057. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  4058. $section = $course_sections[0];
  4059. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  4060. for ($k = 0; $k < count($ids_sections); $k++) {
  4061. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  4062. for ($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  4063. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  4064. if ($c_cm) {
  4065. if ($ccm->instance == $c_cm->instance) {
  4066. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4067. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4068. }
  4069. else {
  4070. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4071. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4072. }
  4073. }
  4074. }
  4075. $radio_buttons .= "</ul>";
  4076. }
  4077. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  4078. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
  4079. </form>
  4080. </div></div> </div></div>\n";
  4081. print " <style>.modal {
  4082. display: none;
  4083. position: fixed;
  4084. z-index: 1;
  4085. left: 0;
  4086. top: 0;
  4087. width: 100%;
  4088. height: 100%;
  4089. overflow: scroll;
  4090. background-color: rgb(0,0,0);
  4091. background-color: rgba(0,0,0,0.4);
  4092. }
  4093. .modal-content {
  4094. background-color: #fefefe;
  4095. margin: 15% auto;
  4096. padding: 10px 10px;
  4097. border: 1px solid #888;
  4098. width: 50%;
  4099. }
  4100. #close_modal {
  4101. color: #aaa;
  4102. float: right;
  4103. font-size: 28px;
  4104. font-weight: bold;
  4105. margin-top: -15px;
  4106. margin-right: -3px;
  4107. }
  4108. #close_modal:hover,
  4109. #close_modal:focus {
  4110. color: black;
  4111. text-decoration: none;
  4112. cursor: pointer;
  4113. }
  4114. #modal_title {
  4115. min-height: 3rem;
  4116. color: initial;
  4117. background: initial;
  4118. font-size: 1.5rem;
  4119. line-height: 1.5;
  4120. padding: 15px;
  4121. border-bottom: 1px solid #e5e5e5;
  4122. }
  4123. .input_move {
  4124. width: 90%;
  4125. padding: 2px;
  4126. }
  4127. .input_move:hover {
  4128. background: #eff0ef;
  4129. }
  4130. </style>";
  4131. $action_links = "";
  4132. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4133. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4134. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4135. for ($j=0; $j<$total_of_activities; $j++) {
  4136. $iassign_current = $iassign_array[$j]->id;
  4137. // receiver=1 - message to teacher
  4138. // receiver=2 - message to student
  4139. $sum_comment = 0;
  4140. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  4141. foreach ($iassign_submissions as $iassign_submission) {
  4142. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  4143. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4144. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4145. if ($verify_message)
  4146. foreach ($verify_message as $tmp)
  4147. $sum_comment += $tmp;
  4148. } // foreach ($iassign_submissions as $iassign_submission)
  4149. if ($sum_comment == 0)
  4150. $comment_unread = "";
  4151. else {
  4152. $comment_unread_message = get_string('comment_unread', 'iassign');
  4153. if ($sum_comment == 1)
  4154. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4155. $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '">' .
  4156. ' <span class="badge bg-danger ml-2" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message .
  4157. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . '</span> </span></a>' . "\n";
  4158. }
  4159. if ($j == $total_of_activities - 1)
  4160. $iassign_down = $iassign_array[$j]->id;
  4161. else
  4162. $iassign_down = $iassign_array[$j + 1]->id;
  4163. if ($j > 0)
  4164. $iassign_up = $iassign_array[$j - 1]->id;
  4165. else
  4166. $iassign_up = $iassign_array[$j]->id;
  4167. if ($iassign_array[$j]->visible == 0)
  4168. $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>\n";
  4169. else
  4170. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4171. $links .= $comment_unread;
  4172. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  4173. $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>\n";
  4174. $str_aux = "&id=" . $id . "&iassign_current=" . $iassign_current . "&iassign_up=" . $iassign_up . "&iassign_down=" . $iassign_down;
  4175. $link_up = "<li class='page-item'><a href='view.php?action=up" . $str_aux . "' class='page-link' title='" . get_string('move_up_iassign', 'iassign') . "'><i class='fa fa-arrow-up' aria-hidden='true'></i></a></li>\n";
  4176. if ($j==0) // first activity
  4177. $link_down = "<li class='page-item'><a href='view.php?action=firstdown" . $str_aux . "' class='page-link' title='" . get_string('move_down_iassign', 'iassign') . "'><i class='fa fa-arrow-down' aria-hidden='true'></i></a></li>\n";
  4178. else
  4179. $link_down = "<li class='page-item'><a href='view.php?action=down" . $str_aux . "' class='page-link' title='" . get_string('move_up_iassign', 'iassign') . "'><i class='fa fa-arrow-down' aria-hidden='true'></i></a></li>\n";
  4180. $link_delete = "<li class='page-item'><a href='view.php?action=delete" . $str_aux . "' class='page-link' title='" . get_string('delete_iassign', 'iassign') . "'><i class='fa fa-trash-o' aria-hidden='true'></i></a></li>\n";
  4181. $link_visible_hide = "<li class='page-item'><a href='view.php?action=visible" . $str_aux . "' class='page-link' title='" . get_string('hide_iassign', 'iassign') . "'><i class='fa fa-eye' aria-hidden='true'></i></a></li>\n";
  4182. $link_visible_show = "<li class='page-item'><a href='view.php?action=visible" . $str_aux . "' class='page-link' title='" . get_string('show_iassign', 'iassign') . "'><i class='fa fa-eye-slash' aria-hidden='true'></i></a></li>\n";
  4183. $link_edit = "<li class='page-item'><a href='view.php?action=edit" . $str_aux . "' class='page-link' title='" . get_string('edit_iassign', 'iassign') . "'><i class='fa fa-pencil-square-o' aria-hidden='true'></i></a></li>\n";
  4184. $link_duplicate_activity = "<li class='page-item'><a href='view.php?action=duplicate_activity" . $str_aux . "' class='page-link' title='" . get_string('duplicate_iassign', 'iassign') . "'><i class='fa fa-clone' aria-hidden='true'></i></a></li>\n";
  4185. $link_move_activity = "<li class='page-item'><a href='#' onclick='load_move(" . $iassign_current . "); return false;' class='page-link' title='" . get_string('move_activity', 'iassign') . "'><i class='fa fa-sign-out' aria-hidden='true'></i></a></li>\n";
  4186. if (count($iassign_array) > 1) {
  4187. if ($j == 0)
  4188. $action_links .= $link_down;
  4189. elseif ($j == $total_of_activities - 1)
  4190. $action_links .= $link_up;
  4191. else
  4192. $action_links .= $link_up . $link_down;
  4193. } // if (count($iassign_array) > 1)
  4194. $action_links .= $link_edit . $link_delete;
  4195. if ($iassign_array[$j]->visible == 0)
  4196. $action_links .= $link_visible_show;
  4197. else
  4198. $action_links .= $link_visible_hide;
  4199. $action_links .= $link_duplicate_activity . $link_move_activity;
  4200. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4201. $action_links .= "</ul></nav>\n";
  4202. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle">' . $action_links . "</td></tr>\n";
  4203. } // for ($j=0; $j<$total_of_activities; $j++)
  4204. print "</tbody></table>\n";
  4205. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4206. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  4207. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4208. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4209. $corect_position = 1; //EXTRA: to detect (and fix it) 'iassign_statement.position' errors
  4210. for ($j=0; $j<$total_of_activities; $j++) {
  4211. if ($iassign_array[$j]->position!=$corect_position) { // ops, the current 'position' is wrong, fix it!
  4212. activity::move_change_activity_position($DB, $iassign_array[$j]->id, $iassign_array[$j]->id, $corect_position, $corect_position);
  4213. }
  4214. $corect_position++;
  4215. }
  4216. for ($j=0; $j<$total_of_activities; $j++) {
  4217. $icon_status = "";
  4218. $icon_comment = "";
  4219. if ($iassign_array[$j]->visible == 1) {
  4220. $iassign_current = $iassign_array[$j]->id;
  4221. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  4222. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4223. $icon_status = "";
  4224. $icon_comment = "";
  4225. if ($iassign_submission) {
  4226. // receiver=1 - message to teacher
  4227. // receiver=2 - message to student
  4228. // $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");
  4229. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  4230. $verify_message = $DB->get_record_sql(
  4231. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4232. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4233. if ($verify_message)
  4234. foreach ($verify_message as $tmp)
  4235. $sum_comment = $tmp;
  4236. if ($sum_comment > 0) {
  4237. $comment_unread_message = get_string('comment_unread', 'iassign');
  4238. if ($sum_comment == 1)
  4239. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4240. $icon_comment = "<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "#comments'>\n" .
  4241. ' <span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . "\n" .
  4242. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . "</span> </span></a>\n";
  4243. }
  4244. // $icon_comment = iassign_icons::insert('comment_unread');
  4245. if ($iassign_array[$j]->type_iassign == 3) {
  4246. if ($iassign_array[$j]->show_answer == 1) {
  4247. if ($iassign_submission->status == 3)
  4248. $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('correct', 'iassign').'"></i>' . "\n";
  4249. elseif ($iassign_submission->status == 2)
  4250. $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('incorrect', 'iassign').'"></i>' . "\n";
  4251. elseif ($iassign_submission->status == 1)
  4252. $icon_status = '<i class="fa fa-question" style="color: #77229; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4253. //2021/12 $icon_status = iassign_icons::insert('post');
  4254. elseif ($iassign_submission->status == 0)
  4255. $icon_status = '<i class="fa fa-question" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4256. } // if ($iassign_array[$j]->show_answer==1)
  4257. else {
  4258. if ($iassign_submission->status == 0)
  4259. //TODO: $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4260. $icon_status = iassign_icons::insert('not_post');
  4261. else
  4262. //TODO: $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4263. $icon_status = iassign_icons::insert('post');
  4264. }
  4265. } // if ($iassign_array[$j]->type_iassign == 3)
  4266. } // if ($iassign_submission)
  4267. elseif ($iassign_array[$j]->type_iassign == 3) {
  4268. $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4269. //2021/12 $icon_status = iassign_icons::insert('not_post');
  4270. } // if ($iassign_array[$j]->type_iassign == 3)
  4271. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 0; text-align: center;">'. $icon_status .'</td><td style="white-space: nowrap; width: 1%; padding-right: 2rem; padding-left: 0.2rem;">'
  4272. . $links . '</td><td>'. $icon_comment.'</td></tr>' . "\n";
  4273. //print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  4274. } // if ($iassign_array[$j]->visible == 1)
  4275. } // for ($j=0; $j<$total_of_activities; $j++)
  4276. print "</table>\n";
  4277. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4278. else if (isguestuser()) {
  4279. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  4280. print '<table width=100% ><tr>' . "\n";
  4281. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  4282. print '</tr></table>' . "\n";
  4283. for ($j=0; $j<$total_of_activities; $j++) {
  4284. $icon_status = "";
  4285. $icon_comment = "";
  4286. if ($iassign_array[$j]->visible == 1) {
  4287. $iassign_current = $iassign_array[$j]->id;
  4288. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4289. print '<p>' . $links . '</p>' . "\n";
  4290. } // if ($iassign_array[$j]->visible == 1)
  4291. }
  4292. }
  4293. print $OUTPUT->box_end();
  4294. } // function show_iassign($title, $iassign_array, $total_of_activities)
  4295. /// Show message of return
  4296. function return_home_course ($message) {
  4297. //D global $DB, $OUTPUT;
  4298. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4299. //D echo $OUTPUT->box_start();
  4300. //D echo '<table width=100% border=0 valign="top">' . "\n";
  4301. //D echo '<tr><td align="left"><strong>' . "\n";
  4302. //D print_string($message, 'iassign');
  4303. //D echo '</strong></td>' . "\n";
  4304. //D echo '<td width=20% align="right">' . "\n";
  4305. //D echo $link_return;
  4306. //D echo '</td></tr></table>' . "\n";
  4307. //D echo $OUTPUT->box_end();
  4308. //D // echo $OUTPUT->footer();
  4309. redirect(new moodle_url($this->return . '&notice=' . $message));
  4310. exit;
  4311. }
  4312. /// Search comment of activity
  4313. function search_comment_submission ($iassign_submissionid) {
  4314. global $USER, $DB, $OUTPUT, $COURSE;
  4315. // $context = context_course::instance($COURSE->id);
  4316. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  4317. $colorEdit2 = "#d2e5fc";
  4318. $has_capability = 0;
  4319. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  4320. $text = "";
  4321. if ($comments) {
  4322. $even = 1;
  4323. foreach ($comments as $tmp) {
  4324. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  4325. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  4326. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  4327. // $text .= $tmp->comment . "</td></tr>";
  4328. //} else {
  4329. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  4330. $avatar = new user_picture($user_data);
  4331. $avatar->courseid = $COURSE->id;
  4332. $avatar->link = true;
  4333. $user_picture = $OUTPUT->render($avatar);
  4334. $user_picture = str_replace('"35"', '"45"', $user_picture);
  4335. if ($even) {
  4336. $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";
  4337. $even = 0;
  4338. } else {
  4339. $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";
  4340. $even = 1;
  4341. }
  4342. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  4343. } // foreach ($comments as $tmp)
  4344. }
  4345. return $text;
  4346. }
  4347. /// Update comment of activity
  4348. function update_comment ($iassign_submissionid) {
  4349. global $USER, $DB, $OUTPUT;
  4350. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  4351. $receiver = 1; // student message to teacher
  4352. else
  4353. $receiver = 2; // teacher message to student
  4354. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  4355. if ($verify_message) {
  4356. foreach ($verify_message as $message) {
  4357. if ($message->receiver == $receiver) {
  4358. $newentry = new stdClass();
  4359. $newentry->id = $message->id;
  4360. $newentry->return_status = 1;
  4361. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  4362. print_error('error_update', 'iassign');
  4363. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  4364. } // if ($message->receiver == $receiver)
  4365. // Trigger module viewed event.
  4366. $event = \mod_iassign\event\submission_comment_updated::create(array(
  4367. 'objectid' => $this->iassign->id,
  4368. 'context' => $this->context
  4369. ));
  4370. $event->add_record_snapshot('course', $this->course);
  4371. $event->trigger();
  4372. } // foreach ($verify_message as $message)
  4373. }
  4374. }
  4375. /// Record comment of activity
  4376. function write_comment_submission () {
  4377. global $USER, $CFG, $DB;
  4378. $id = $this->cm->id;
  4379. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  4380. $row = optional_param('row', 0, PARAM_INT);
  4381. $column = optional_param('column', 0, PARAM_INT);
  4382. $sum_comment = 0;
  4383. $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);
  4384. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  4385. $str1 = trim($submission_comment);
  4386. $str2 = trim(get_string('box_comment_message', 'iassign'));
  4387. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  4388. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  4389. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  4390. $receiver = 1; // student message to teacher
  4391. $this->action = 'view';
  4392. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  4393. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  4394. } else {
  4395. $receiver = 2; // teacher message to student
  4396. $this->action = 'viewsubmission';
  4397. //D $tousers = array(); //MOOC 2016
  4398. //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
  4399. }
  4400. //MOOC 2016: foi p/ 15 linhas acima:
  4401. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  4402. // verificar se existe uma submissão para o exercício e aluno informados
  4403. if (!$iassign_submission) {
  4404. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  4405. }
  4406. if (!$iassign_submission) {
  4407. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  4408. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  4409. $this->iassign_submission_current = $id_submission;
  4410. }
  4411. else {
  4412. $id_submission = $iassign_submission->id;
  4413. } // if (!$iassign_submission)
  4414. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4415. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4416. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4417. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4418. $comments = $DB->get_record_sql(
  4419. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4420. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4421. if ($comments)
  4422. foreach ($comments as $tmp)
  4423. $sum_comment = $tmp;
  4424. if ($sum_comment == 0) {
  4425. $newentry = new stdClass();
  4426. $newentry->iassign_submissionid = $id_submission;
  4427. $newentry->comment_authorid = $USER->id;
  4428. $newentry->timecreated = time();
  4429. $newentry->comment = $submission_comment;
  4430. $newentry->receiver = $receiver;
  4431. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4432. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  4433. // Trigger module viewed event.
  4434. $event = \mod_iassign\event\submission_comment_created::create(array(
  4435. 'objectid' => $this->iassign->id,
  4436. 'context' => $this->context
  4437. ));
  4438. $event->add_record_snapshot('course', $this->course);
  4439. $event->trigger();
  4440. }
  4441. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4442. // if ($this->action=='viewsubmission') {
  4443. // echo $OUTPUT->header();
  4444. // $this->return_last('confirm_add_comment', $link_return);
  4445. // die;
  4446. // }
  4447. return true;
  4448. } // function write_comment_submission()
  4449. /// Writes a new submission
  4450. // The first student answer is under 'function get_answer()'
  4451. function new_submission ($iassignid, $id_user, $receiver) {
  4452. global $USER, $DB, $OUTPUT;
  4453. $newentry = new stdClass();
  4454. $newentry->iassign_statementid = $iassignid;
  4455. $newentry->userid = $id_user;
  4456. $newentry->timecreated = time();
  4457. $newentry->timemodified = time();
  4458. $newentry->answer = 0; // student only submit message
  4459. if ($receiver == 2) // teacher message to student (write id teacher)
  4460. $newentry->teacher = $USER->id;
  4461. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4462. return_home_course('error_insert_submissions');
  4463. else {
  4464. // Trigger module view event
  4465. $event = \mod_iassign\event\submission_created::create(array(
  4466. 'objectid' => $this->iassign->id,
  4467. 'context' => $this->context
  4468. ));
  4469. $event->add_record_snapshot('course', $this->course);
  4470. $event->trigger();
  4471. }
  4472. return $newentry->id;
  4473. }
  4474. /// Return to a specific address of page
  4475. function return_last ($message, $link_return) {
  4476. global $DB, $OUTPUT;
  4477. print $OUTPUT->box_start();
  4478. print '<table width=100% border=0 valign="top">' . "\n";
  4479. print '<tr><td align="left"><strong>' . "\n";
  4480. print_string($message, 'iassign');
  4481. print '</strong></td>' . "\n";
  4482. print '<td width=20% align="right">' . "\n";
  4483. print $link_return;
  4484. print '</td></tr></table>' . "\n";
  4485. print $OUTPUT->box_end();
  4486. print $OUTPUT->footer();
  4487. die();
  4488. } // function return_last($message, $link_return)
  4489. } // class iassign
  4490. /// Class for manage activities
  4491. class activity {
  4492. var $activity;
  4493. /// Constructor of class.
  4494. // @param int $id Id of activity
  4495. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4496. //D public function activity($id) { self::__construct($id); }
  4497. function __construct ($id) {
  4498. global $DB;
  4499. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4500. if (empty($this->activity))
  4501. $this->activity = null;
  4502. }
  4503. /// Get an activity
  4504. // @return NULL
  4505. function get_activity () {
  4506. if ($this->activity != null)
  4507. return $this->activity;
  4508. else
  4509. return null;
  4510. }
  4511. /// Delete interactive activities
  4512. function delete ($return) {
  4513. global $USER, $CFG, $DB, $OUTPUT;
  4514. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4515. print $OUTPUT->header();
  4516. $output .= $OUTPUT->box_start();
  4517. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4518. if ($iassign_submission_currents) {
  4519. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4520. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4521. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4522. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4523. $output .= $OUTPUT->box_end();
  4524. $output .= $OUTPUT->footer();
  4525. print $output;
  4526. die();
  4527. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4528. } // if ($iassign_submission_currents)
  4529. else
  4530. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  4531. $output .= '<table width=50% border=0>';
  4532. $output .= '<tr valign="top"><td>';
  4533. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  4534. $output .= '</td><td>';
  4535. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4536. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4537. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  4538. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4539. $output .= "</form>\n";
  4540. $output .= '</td><td>';
  4541. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4542. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4543. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4544. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4545. $output .= "</form>\n";
  4546. $output .= '</td></tr></table>' . "\n";
  4547. $output .= $OUTPUT->box_end();
  4548. $output .= $OUTPUT->footer();
  4549. print $output;
  4550. } // function delete($return)
  4551. /// Function for confirm the delete of activity
  4552. // @param String $return Url of return
  4553. // @param Object $iassign Object content an activity
  4554. function deleteyes ($return, $iassign) {
  4555. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4556. $msg = '';
  4557. if (!empty($this->activity->id)) {
  4558. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4559. if ($iassign_submission_currents) {
  4560. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4561. foreach ($iassign_submission_currents as $iassign_submission)
  4562. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4563. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4564. } // if ($iassign_submission_currents)
  4565. }
  4566. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4567. // Remove all files associated to this activity:
  4568. $fs = get_file_storage();
  4569. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4570. $this->delete_calendar($this->activity->id);
  4571. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4572. iassign::update_grade_iassign($this->activity->iassignid);
  4573. if ($delete_iassign_current) {
  4574. $iassign->return_home_course('confirm_delete_iassign');
  4575. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4576. } else {
  4577. $iassign->return_home_course('error_confirm_delete_iassign');
  4578. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4579. }
  4580. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4581. }
  4582. } // function deleteyes($return, $iassign)
  4583. // Change fields 'iassign_statement.position' between 2 activities
  4584. // @calledby : class this->move_iassign($move_action, $target, $return)
  4585. // @calledby : class iassign show_iassign($title, $iassign_array, $total_of_activities) - this is used only to fix 'position' erros (e.g. {1,2,2,3} to {1,2,3,4})
  4586. static function move_change_activity_position ($DB, $idFrom, $idTo, $posFrom, $posTo) { //1
  4587. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4588. $newentry->id = $idFrom; // ID of the "source activity" //1 $this->activity->id -> $idFrom
  4589. $newentry->position = $posFrom; // final position to source //1 $final_position_source -> $posFrom
  4590. //D echo "mover: id=" . $idFrom . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4591. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4592. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4593. print_error('error_update_move_iassign', 'iassign');
  4594. }
  4595. else if ($idFrom != $idTo) { // first update performed successfully - change second only if they are different
  4596. $newentry->id = $idTo; //1 $iassign_target->id -> $idTo
  4597. $newentry->position = $posTo; //1 $final_position_target -> $posTo
  4598. if (!$DB->update_record('iassign_statement', $newentry))
  4599. print_error('error_update_move_iassign', 'iassign');
  4600. }
  4601. }
  4602. /// Changes position of activities (between those inside a group of interactive activities)
  4603. // @param $move_action = must be "up" or "down"
  4604. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4605. function move_iassign ($move_action, $target, $return) {
  4606. global $DB, $OUTPUT;
  4607. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4608. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4609. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4610. if ($move_action=="firstdown") {
  4611. $final_position_source = 2;
  4612. $final_position_target = 1;
  4613. }
  4614. else
  4615. if ($move_action=="down") {
  4616. $final_position_target = $this->activity->position;
  4617. $final_position_source = $final_position_target + 1;
  4618. }
  4619. else
  4620. if ($move_action=="up") {
  4621. $final_position_target = $this->activity->position;
  4622. $final_position_source = $final_position_target - 1;
  4623. }
  4624. else { // error:
  4625. print_error('error_update_move_iassign', 'iassign');
  4626. exit;
  4627. }
  4628. activity::move_change_activity_position($DB, $this->activity->id, $iassign_target->id, $final_position_source, $final_position_target); // efectively exchange 'position'
  4629. redirect($return);
  4630. } // function move_iassign($move_action, $target, $return)
  4631. /// Enable or disable the display of interactive activities
  4632. function visible_iassign ($return) {
  4633. global $DB;
  4634. $newentry = new stdClass();
  4635. $newentry->id = $this->activity->id;
  4636. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4637. if (!$DB->update_record('iassign_statement', $newentry))
  4638. print_error('error_update_visible_iassign', 'iassign');
  4639. redirect($return);
  4640. }
  4641. /// Add news interactive activities (register in table 'iassign_statement')
  4642. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4643. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4644. function new_iassign ($param) {
  4645. global $DB;
  4646. $newentry = new stdClass();
  4647. $newentry->iassignid = $param->iassignid;
  4648. $newentry->name = $param->name;
  4649. $newentry->type_iassign = $param->type_iassign;
  4650. $newentry->store_all_submissions = $param->store_all_submissions;
  4651. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4652. $proposition = $param->proposition;
  4653. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4654. else $proposition_text = $proposition;
  4655. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4656. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4657. //TODO Then get it directly from the form data $_POST!
  4658. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4659. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4660. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4661. $newentry->author_name = $param->author_name;
  4662. $newentry->author_modified_name = $param->author_modified_name;
  4663. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4664. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4665. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4666. $newentry->grade = $param->grade;
  4667. $newentry->timemodified = time();
  4668. $newentry->timecreated = time();
  4669. if ($param->type_iassign == 1) {
  4670. $newentry->timedue = 0;
  4671. $newentry->timeavailable = 0;
  4672. } // if ($param->type_iassign == 1)
  4673. else {
  4674. $newentry->timedue = $param->timedue;
  4675. $newentry->timeavailable = $param->timeavailable;
  4676. }
  4677. $newentry->preventlate = $param->preventlate;
  4678. $newentry->test = $param->test;
  4679. $newentry->special_param1 = $param->special_param1;
  4680. $newentry->visible = $param->visible;
  4681. $newentry->position = $param->position;
  4682. $newentry->max_experiment = $param->max_experiment;
  4683. $newentry->dependency = $param->dependency;
  4684. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4685. $newentry->show_answer = $param->show_answer;
  4686. $id = $DB->insert_record("iassign_statement", $newentry);
  4687. if ($id) {
  4688. $component = 'mod_iassign';
  4689. $filearea = 'exercise';
  4690. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4691. $file = $fs->get_file_by_id($param->file);
  4692. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4693. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4694. //$itemid = $id;
  4695. // File already inserted in other context!
  4696. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4697. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4698. $updateentry = new stdClass();
  4699. $updateentry->id = $id;
  4700. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4701. $updateentry->filesid = $newfile->get_itemid();
  4702. if (!$DB->update_record("iassign_statement", $updateentry))
  4703. print_error('error_add', 'iassign');
  4704. if ($param->type_iassign == 3)
  4705. iassign::update_grade_iassign($param->iassignid);
  4706. //TODO iLM_HTML5 :: //MOOC2014
  4707. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4708. //D if ($iassign_ilm_configs) {
  4709. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4710. //D if ($iassign_ilm_config->param_type != 'static') {
  4711. //D $newentry = new stdClass();
  4712. //D $newentry->iassign_statementid = $id;
  4713. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4714. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4715. //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});
  4716. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4717. //D print_error('error_add_param', 'iassign');
  4718. //D }
  4719. //D }
  4720. //D }
  4721. // log event --------------------------------------------------------------------------------------
  4722. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4723. // log event --------------------------------------------------------------------------------------
  4724. return $id;
  4725. }
  4726. else
  4727. print_error('error_add', 'iassign');
  4728. } // function new_iassign($param)
  4729. /// Add the calendar entries for this iassign
  4730. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4731. // @return bool
  4732. static function add_calendar ($iassignid) {
  4733. global $DB, $CFG;
  4734. require_once($CFG->dirroot . '/calendar/lib.php');
  4735. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4736. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4737. $event = new stdClass();
  4738. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4739. $event->description = $iassign_statement_activity_item->name;
  4740. $event->courseid = $iassign->course;
  4741. $event->groupid = 0;
  4742. $event->userid = 0;
  4743. $event->modulename = 'iassign';
  4744. $event->instance = $iassign->id;
  4745. $event->eventtype = 'due';
  4746. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4747. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4748. calendar_event::create($event);
  4749. }
  4750. /// Update the calendar entries for this iassign
  4751. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4752. // @return bool
  4753. function update_calendar ($iassignid, $olddescription) {
  4754. global $DB, $CFG;
  4755. require_once($CFG->dirroot . '/calendar/lib.php');
  4756. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4757. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4758. $event = new stdClass();
  4759. $event->id = 0;
  4760. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4761. if ($events) {
  4762. foreach ($events as $value) {
  4763. if ($value->description == $olddescription) {
  4764. $event->id = $value->id;
  4765. }
  4766. }
  4767. }
  4768. if ($event->id != 0) {
  4769. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4770. $event->description = $iassign_statement_activity_item->name;
  4771. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4772. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4773. $calendarevent = calendar_event::load($event->id);
  4774. $calendarevent->update($event);
  4775. } else
  4776. $this->add_calendar($iassignid);
  4777. }
  4778. /// Update the calendar entries for this iassign
  4779. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4780. // @return bool
  4781. function delete_calendar ($iassignid) {
  4782. global $DB, $CFG;
  4783. require_once($CFG->dirroot . '/calendar/lib.php');
  4784. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4785. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4786. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4787. if ($events) {
  4788. foreach ($events as $value) {
  4789. if ($value->description == $iassign_statement_activity_item->name) {
  4790. $DB->delete_records('event', array('id' => $value->id));
  4791. }
  4792. }
  4793. }
  4794. }
  4795. /// Update interactive activities
  4796. function update_iassign ($param) {
  4797. global $DB;
  4798. $component = 'mod_iassign';
  4799. $filearea = 'exercise';
  4800. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4801. $file = $fs->get_file_by_id($param->file);
  4802. $fileold = $fs->get_file_by_id($param->fileold);
  4803. if ($param->file != $param->fileold) {
  4804. if ($fileold) {
  4805. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4806. foreach ($fileoldarea as $value) {
  4807. $value->delete();
  4808. }
  4809. }
  4810. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4811. $itemid = $file->get_itemid() + $param->iassign_id;
  4812. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4813. $param->file = $newfile->get_itemid();
  4814. }
  4815. else
  4816. $param->file = $file->get_itemid();
  4817. }
  4818. else {
  4819. $param->file = $file->get_itemid();
  4820. }
  4821. $newentry = new stdClass();
  4822. $newentry->id = $param->iassign_id;
  4823. $newentry->name = $param->name;
  4824. $newentry->type_iassign = $param->type_iassign;
  4825. $newentry->store_all_submissions = $param->store_all_submissions;
  4826. //2019 $newentry->proposition = $param->proposition;
  4827. $proposition = $param->proposition;
  4828. if (is_array($proposition))
  4829. $proposition_text = $proposition['text'];
  4830. else
  4831. $proposition_text = $proposition;
  4832. $newentry->proposition = $proposition_text;
  4833. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4834. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4835. $newentry->grade = $param->grade;
  4836. $newentry->author_modified_name = $param->author_modified_name;
  4837. $newentry->timemodified = time();
  4838. if ($param->type_iassign == 1) {
  4839. $newentry->timedue = 0;
  4840. $newentry->timeavailable = 0;
  4841. } // if ($param->type_iassign == 1)
  4842. else {
  4843. $newentry->timedue = $param->timedue;
  4844. $newentry->timeavailable = $param->timeavailable;
  4845. }
  4846. $newentry->preventlate = $param->preventlate;
  4847. $newentry->test = $param->test;
  4848. if (isset($param->special_param1))
  4849. $newentry->special_param1 = $param->special_param1;
  4850. else
  4851. $newentry->special_param1 = NULL;
  4852. $newentry->visible = $param->visible;
  4853. $newentry->max_experiment = $param->max_experiment;
  4854. $newentry->dependency = $param->dependency;
  4855. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4856. $newentry->show_answer = $param->show_answer;
  4857. if (!$DB->update_record("iassign_statement", $newentry))
  4858. print_error('error_update', 'iassign');
  4859. if ($param->type_iassign == 3) {
  4860. iassign::update_grade_iassign($param->iassignid);
  4861. }
  4862. //$id = $newentry->id; // MOOC 2016 --- inicio
  4863. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4864. //if ($iassign_activity_item_configs) {
  4865. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4866. // $newentry = new stdClass();
  4867. // $newentry->id = $iassign_activity_item_config->id;
  4868. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4869. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4870. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4871. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4872. // print_error('error_edit_param', 'iassign');
  4873. // }
  4874. // } // MOOC 2016 --- final
  4875. // log event --------------------------------------------------------------------------------------
  4876. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4877. // log event --------------------------------------------------------------------------------------
  4878. return $newentry->id;
  4879. // if ($param->type_iassign==3)
  4880. // $this->update_grade_iassign($param->iassignid);
  4881. } // function update_iassign($param)
  4882. /// Show information of activity
  4883. function show_info_iassign () {
  4884. global $DB, $OUTPUT;
  4885. $output = '';
  4886. if ($this->activity->type_iassign == 3) {
  4887. if ($this->activity->dependency == 0) {
  4888. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4889. } else {
  4890. $dependencys = explode(';', $this->activity->dependency);
  4891. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4892. foreach ($dependencys as $dependency) {
  4893. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4894. if ($dependencyiassign)
  4895. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4896. } // foreach ($dependencys as $dependency)
  4897. } // if ($iassign_statement_activity_item->dependency == 0)
  4898. if ($this->activity->max_experiment == 0)
  4899. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4900. else
  4901. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4902. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4903. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4904. $output .= $this->toggle_columns_script();
  4905. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4906. print $OUTPUT->box($output);
  4907. } // function show_info_iassign()
  4908. /// Provide script to toggle columns
  4909. static function toggle_columns_script () {
  4910. $output = "";
  4911. $output .= '<script>
  4912. function toLeft () {
  4913. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4914. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4915. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4916. document.getElementById("columnsbutton").style.color = "#1da075";
  4917. }
  4918. function toDefault () {
  4919. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4920. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4921. document.getElementById("fullscreen").style.marginTop = "0";
  4922. document.getElementById("columnsbutton").style.color = "#343a40";
  4923. }
  4924. var activate = false;
  4925. function toggleColumns () {
  4926. if (activate) {
  4927. activate = false;
  4928. toDefault();
  4929. } else {
  4930. activate = true;
  4931. toLeft();
  4932. }
  4933. }
  4934. </script>'; // '
  4935. $output .= '<span tabindex="0" data-toggle="tooltip" title="'.get_string('enable_disable_columns', 'iassign').'" style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>';
  4936. return $output;
  4937. }
  4938. static function get_latest_array_item ($DB, $iassignid, $position) { //TODO: may be search for the gratest grade?
  4939. $iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'position' => $position));
  4940. $item = NULL;
  4941. foreach ($iassign_statement as $item) ; // get the last item!
  4942. if ($item) return $item; // return the last one
  4943. return NULL;
  4944. }
  4945. /// Shows date of opening and closing activities
  4946. function view_dates () {
  4947. global $USER, $CFG, $DB, $OUTPUT;
  4948. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4949. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4950. $status_iassign = "";
  4951. $status_iassign1 = "";
  4952. $status_iassign2 = "";
  4953. if ($this->activity->type_iassign == 1) // activity of type example
  4954. $type_iassign = get_string('example_iassign', 'iassign');
  4955. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4956. $type_iassign = get_string('test_iassign', 'iassign');
  4957. if ($this->activity->timeavailable > time()) {
  4958. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4959. } elseif ($this->activity->timedue < time()) {
  4960. $status_iassign = get_string('last_timedue', 'iassign');
  4961. }
  4962. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4963. $type_iassign = get_string('exercise_iassign', 'iassign');
  4964. if ($this->activity->timeavailable > time()) {
  4965. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4966. } elseif ($this->activity->timedue < time()) { // after delivery
  4967. $status_iassign = get_string('last_timedue', 'iassign');
  4968. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4969. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4970. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4971. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4972. if ($this->activity->test == 1) // allowed to test after of deadline
  4973. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4974. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4975. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4976. } // elseif ($iassign_statement_activity_item->test == 0)
  4977. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4978. } // elseif ($iassign_statement_activity_item->timedue < time())
  4979. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4980. $output = '<table width=100% >' . "\n";
  4981. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4982. $output .= '<tr>' . "\n";
  4983. //leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4984. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4985. //leo $output .= '<td width=80%>' . $type_iassign;
  4986. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4987. // $output .= '</td>' . "\n";
  4988. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4989. // Link (with icon) to report survey (to present all interactivy exercises inside this block)
  4990. $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>";
  4991. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4992. }
  4993. else {
  4994. // Get all previous/next solution sent by this student (present link to his last answer)
  4995. // $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4996. $iassign_previous = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position-1); // previous activity of this student inside this block
  4997. // $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4998. $iassign_next = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position+1); // next activity of this student inside this block
  4999. $link_next = "";
  5000. $link_previous = "";
  5001. if ($iassign_previous) { // previous_activity
  5002. $url_previous = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_previous->id;
  5003. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>\n";
  5004. }
  5005. if ($iassign_next) { // next_activity
  5006. $url_next = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_next->id;
  5007. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>\n";
  5008. }
  5009. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  5010. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  5011. $output .= '</tr></table>' . "\n";
  5012. $output .= '<table width=100% >' . "\n";
  5013. if ($this->activity->type_iassign > 1) {
  5014. if ($this->activity->timeavailable)
  5015. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  5016. if ($this->activity->timedue)
  5017. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  5018. } // if ($iassign_statement_activity_item->type_iassign > 1)
  5019. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  5020. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  5021. $output .= '</table>' . "\n";
  5022. print $OUTPUT->box($output);
  5023. } // function view_dates()
  5024. } // class activity
  5025. /// Class to manage Interactive Learning Module (iLM)
  5026. class ilm {
  5027. var $ilm;
  5028. /// Constructor of class
  5029. // @param int $id Id of iLM
  5030. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  5031. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  5032. function __construct ($id) {
  5033. global $DB;
  5034. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  5035. if (empty($this->ilm))
  5036. $this->ilm = null;
  5037. }
  5038. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  5039. // @calledby view_iassign_current()
  5040. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  5041. global $USER, $CFG, $DB;
  5042. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  5043. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5044. $typec = strtolower($iassign_ilm->type);
  5045. require_once 'ilm_handlers/' . $typec . '.php';
  5046. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  5047. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  5048. return $retorno;
  5049. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  5050. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  5051. // @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);
  5052. // @param int $iassign_statement_activity_itemid Id of iassign statement
  5053. // @param Object $file File in use in activity
  5054. // @return int Return the id of log
  5055. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  5056. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  5057. $newentry = new stdClass();
  5058. $newentry->iassign_statementid = $iassign_activity_itemid;
  5059. $newentry->userid = $USER->id;
  5060. $newentry->filesid = $content_or_id_from_ilm_security;
  5061. $newentry->timecreated = time();
  5062. $newentry->view = 1;
  5063. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  5064. if (!$id_iLM_security) {
  5065. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  5066. } // from (!$DB->insert_record("iassign_security", $newentry))
  5067. return $id_iLM_security;
  5068. }
  5069. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  5070. // @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);
  5071. // @param int $userid
  5072. // @param int $iassign_activity_itemid Id of iassign statement
  5073. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  5074. global $DB;
  5075. // 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")
  5076. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  5077. }
  5078. } // class ilm
  5079. /// Class to manage settings of iLM.
  5080. class ilm_settings {
  5081. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  5082. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5083. // @param int $ilm_id Id of iLM
  5084. // @param array $options An array with options for create dynamic tag html APPLET
  5085. // @return string Return with a tag html APPLET created
  5086. static function build_ilm_tags ($ilm_id, $options = array()) {
  5087. global $DB;
  5088. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5089. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5090. $typec = strtolower($iassign_ilm->type);
  5091. require_once 'ilm_handlers/' . $typec . '.php';
  5092. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  5093. return $retorno;
  5094. } // static function build_ilm_tags($ilm_id, $options = array())
  5095. /// Function for get modified date of iLM file
  5096. // @param string $file_jar String with Ids of iLM files
  5097. // @return string Return with the filenames and modified date
  5098. static function applet_filetime ($file_jar) {
  5099. $filetime = "";
  5100. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5101. $files_jar = explode(",", $file_jar);
  5102. foreach ($files_jar as $one_file) {
  5103. $file = $fs->get_file_by_id($one_file);
  5104. if ($file)
  5105. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  5106. }
  5107. return $filetime;
  5108. }
  5109. /// Function for verify an default applet
  5110. // @param String $file_jar String containing an list de ids of applet files
  5111. // @return boolean Return true or fale if applet is default
  5112. static function applet_default ($file_jar) {
  5113. $is_default = true;
  5114. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5115. $files_jar = explode(",", $file_jar);
  5116. foreach ($files_jar as $one_file) {
  5117. $file = $fs->get_file_by_id($one_file);
  5118. if ($file)
  5119. $is_default &= ($file->get_itemid() == 0);
  5120. }
  5121. return $is_default;
  5122. }
  5123. /// Function for get form variables for add, edit, or copy iLM
  5124. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  5125. // @see settings_form.php
  5126. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  5127. // @param int $ilm_id Id of iLM
  5128. // @param string $action String with the action
  5129. // @return object Return an object with forms variables
  5130. static function add_edit_copy_ilm ($ilm_id, $action) {
  5131. global $USER, $DB, $CFG;
  5132. require_once('settings_form.php'); // put the form
  5133. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5134. $param = new stdClass();
  5135. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  5136. $param->action = $action;
  5137. $param->ilm_id = $ilm_id;
  5138. $CFG->action_ilm = $action;
  5139. $CFG->ilm_id = $ilm_id;
  5140. if ($action == 'add') {
  5141. $param->title = get_string('add_ilm', 'iassign');
  5142. $param->name = "";
  5143. $param->version = "";
  5144. $param->url = "";
  5145. $param->description = "";
  5146. $param->extension = "";
  5147. $param->author = $USER->id;
  5148. $param->file_jar = "";
  5149. $param->file_jar_static = "";
  5150. $param->file_class = "";
  5151. $param->width = 800;
  5152. $param->height = 600;
  5153. $param->enable = 0; // 0 - hide / 1 - show
  5154. $param->timecreated = time();
  5155. $param->timemodified = time();
  5156. $param->evaluate = 0;
  5157. $param->parent = 0;
  5158. }
  5159. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  5160. if ($iassign_ilm) {
  5161. $description = json_decode($iassign_ilm->description);
  5162. $param->title = get_string('edit_ilm', 'iassign');
  5163. $param->id = $iassign_ilm->id;
  5164. $param->name_ilm = $iassign_ilm->name;
  5165. $param->name = $iassign_ilm->name;
  5166. $param->version = $iassign_ilm->version;
  5167. $param->ilm_type = $iassign_ilm->type;
  5168. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5169. $param->url = $iassign_ilm->url; // iLM official URL
  5170. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  5171. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  5172. $param->editingbehavior = $iassign_ilm->editingbehavior;
  5173. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  5174. if (!isset($description->{current_language()})) {
  5175. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  5176. else
  5177. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  5178. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  5179. }
  5180. else
  5181. $param->description = $description->{current_language()};
  5182. $param->description_lang = $iassign_ilm->description;
  5183. $param->extension = $iassign_ilm->extension;
  5184. $param->author = $iassign_ilm->author;
  5185. $param->file_jar = $iassign_ilm->file_jar;
  5186. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  5187. $param->file_class = $iassign_ilm->file_class;
  5188. $param->width = $iassign_ilm->width;
  5189. $param->height = $iassign_ilm->height;
  5190. $param->enable = $iassign_ilm->enable;
  5191. $param->timecreated = $iassign_ilm->timecreated;
  5192. $param->timemodified = time();
  5193. $param->evaluate = $iassign_ilm->evaluate;
  5194. $param->parent = $iassign_ilm->parent;
  5195. }
  5196. }
  5197. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  5198. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  5199. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5200. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  5201. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  5202. // echo "Sem dados<br/>"; exit;
  5203. return;
  5204. }
  5205. $description = json_decode($iassign_ilm->description);
  5206. if ($iassign_ilm) {
  5207. if ($iassign_ilm->parent == 0)
  5208. $iassign_ilm->parent = $ilm_id;
  5209. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  5210. $param->title = get_string('new_version_ilm', 'iassign');
  5211. $param->name_ilm = $iassign_ilm->name;
  5212. $param->name = $iassign_ilm->name;
  5213. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  5214. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  5215. $param->version = $iassign_ilm->version; // do not erase field 'version'
  5216. $param->ilm_type = $iassign_ilm->type;
  5217. $param->url = $iassign_ilm->url;
  5218. $param->description = $description->{current_language()};
  5219. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  5220. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5221. $param->extension = $iassign_ilm->extension;
  5222. $param->author = $USER->id;
  5223. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  5224. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  5225. $param->file_jar_static = '';
  5226. $param->file_class = $iassign_ilm->file_class;
  5227. $param->width = $iassign_ilm->width;
  5228. $param->height = $iassign_ilm->height;
  5229. $param->enable = 0;
  5230. $param->timecreated = time();
  5231. $param->timemodified = time();
  5232. $param->evaluate = $iassign_ilm->evaluate;
  5233. $param->parent = $iassign_ilm->parent;
  5234. }
  5235. }
  5236. elseif ($action == 'copy') {
  5237. $description = json_decode($iassign_ilm->description);
  5238. if ($iassign_ilm) {
  5239. if ($iassign_ilm->parent == 0)
  5240. $iassign_ilm->parent = $ilm_id;
  5241. $param->title = get_string('copy_ilm', 'iassign');
  5242. $param->id = $iassign_ilm->id;
  5243. $param->name_ilm = $iassign_ilm->name;
  5244. $param->name = $iassign_ilm->name;
  5245. $param->version = "";
  5246. $param->ilm_type = $iassign_ilm->type;
  5247. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5248. $param->url = $iassign_ilm->url;
  5249. $param->description = $description->{current_language()};
  5250. $param->description_lang = $iassign_ilm->description;
  5251. $param->extension = $iassign_ilm->extension;
  5252. $param->author = $USER->id;
  5253. $param->file_jar = '';
  5254. $param->file_jar_static = '';
  5255. $param->file_class = $iassign_ilm->file_class;
  5256. $param->width = $iassign_ilm->width;
  5257. $param->height = $iassign_ilm->height;
  5258. $param->enable = 0;
  5259. $param->timecreated = time();
  5260. $param->timemodified = time();
  5261. $param->evaluate = $iassign_ilm->evaluate;
  5262. $param->parent = $iassign_ilm->parent;
  5263. }
  5264. }
  5265. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  5266. //D var_dump(debug_backtrace());
  5267. //D print_r(debug_backtrace());
  5268. return $param;
  5269. } // static function add_edit_copy_ilm($ilm_id, $action)
  5270. /// Function for save iLM file in moodledata
  5271. // @param int $itemid Itemid of file save in draft (upload file)
  5272. // @param int $ilm_id Id of iLM
  5273. // @return string Return an string with ids of iLM files
  5274. static function new_file_ilm ($itemid, $iassign_ilm) {
  5275. global $CFG, $USER, $DB;
  5276. $return = null;
  5277. $file_jar = array();
  5278. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5279. $contextuser = context_user::instance($USER->id);
  5280. $contextsystem = context_system::instance();
  5281. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  5282. if ($files_ilm) {
  5283. foreach ($files_ilm as $value) {
  5284. // CHECK IF file is HTML type
  5285. if ($iassign_ilm->type == 1) {
  5286. // Check if the file extension is ZIP
  5287. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  5288. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  5289. if ((strtolower($ext) == 'zip')) {
  5290. // Coping...:
  5291. $destination = 'ilm_debug/' . $value->get_filename();
  5292. $value->copy_content_to($destination);
  5293. // Extracting content...:
  5294. $zip = new ZipArchive();
  5295. $extracted = './ilm';
  5296. $dir = "";
  5297. if ($zip->open($destination) === TRUE) {
  5298. $dir = './ilm/' . trim($zip->getNameIndex(0));
  5299. if (is_dir($dir)) {
  5300. $i = 1;
  5301. $previous = str_replace("/", "", $zip->getNameIndex(0));
  5302. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  5303. $i++;
  5304. }
  5305. $name = $previous . "_" . $i;
  5306. $dir = './ilm/' . $name . "/";
  5307. $j = 0;
  5308. while ($item_name = $zip->getNameIndex($j)) {
  5309. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  5310. $j++;
  5311. }
  5312. $zip->close();
  5313. }
  5314. $zip->open($destination);
  5315. $zip->extractTo($extracted);
  5316. $zip->close();
  5317. // After the extraction, remove it from DEBUG
  5318. unlink($destination);
  5319. } else { // Error trying to open destination...
  5320. // After the extraction error, also remove it from DEBUG
  5321. unlink($destination);
  5322. print_error('error_add_ilm_zip', 'iassign');
  5323. }
  5324. return $dir;
  5325. }
  5326. } // if ($iassign_ilm->type == 1)
  5327. if ($value->get_filename() != '.') {
  5328. $file_ilm = array(
  5329. 'userid' => $USER->id,
  5330. 'contextid' => $contextsystem->id,
  5331. 'component' => 'mod_iassign',
  5332. 'filearea' => 'ilm',
  5333. 'itemid' => rand(1, 999999999),
  5334. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  5335. 'filename' => $value->get_filename());
  5336. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  5337. array_push($file_jar, $file_ilm->get_id());
  5338. }
  5339. }
  5340. if (!empty($file_jar)) {
  5341. $return = implode(",", $file_jar);
  5342. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  5343. foreach ($old_file_jar as $value) {
  5344. $file = $fs->get_file_by_id($value);
  5345. if ($file)
  5346. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  5347. }
  5348. }
  5349. }
  5350. else // if ($files_ilm)
  5351. $return = $iassign_ilm->file_jar;
  5352. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  5353. return $return;
  5354. } // static function new_file_ilm($itemid, $iassign_ilm)
  5355. /// Function for save in database an new iLM
  5356. // @param object $param An object with iLM params
  5357. static function new_ilm ($itemid) {
  5358. global $CFG, $USER, $OUTPUT;
  5359. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5360. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5361. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5362. }
  5363. $pathtemp = $CFG->dataroot . '/temp/';
  5364. $contextuser = context_user::instance($USER->id);
  5365. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5366. $zip = new zip_packer();
  5367. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5368. foreach ($files as $file) {
  5369. if (!$file->is_directory())
  5370. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5371. }
  5372. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5373. // Verifica se o pacote possui o XML
  5374. if (!$application_xml) {
  5375. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5376. return;
  5377. } else {
  5378. $missing = "";
  5379. if (!isset($application_xml->name)) {
  5380. $missing .= "name";
  5381. }
  5382. if (!isset($application_xml->version)) {
  5383. $missing .= ", version";
  5384. }
  5385. if (!isset($application_xml->type)) {
  5386. $missing .= ", type";
  5387. }
  5388. if (!isset($application_xml->extension)) {
  5389. $missing .= ", extension";
  5390. }
  5391. if (!isset($application_xml->file_jar)) {
  5392. $missing .= ", file_jar";
  5393. }
  5394. if (!isset($application_xml->file_class)) {
  5395. $missing .= ", file_class";
  5396. }
  5397. if (!isset($application_xml->width)) {
  5398. $missing .= ", width";
  5399. }
  5400. if (!isset($application_xml->height)) {
  5401. $missing .= ", height";
  5402. }
  5403. if (!isset($application_xml->evaluate)) {
  5404. $missing .= ", evaluate";
  5405. }
  5406. if (strlen($missing) > 2) {
  5407. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5408. return;
  5409. }
  5410. }
  5411. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5412. $typec = strtolower($application_xml->type);
  5413. require_once 'ilm_handlers/' . $typec . '.php';
  5414. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5415. return $retorno;
  5416. } // static function new_ilm($itemid)
  5417. /// Function for save in database an iLM edit
  5418. // @param object $param An object with iLM params
  5419. static function edit_ilm ($param, $itemid) {
  5420. // Descobrir o tipo de iLM:
  5421. global $DB, $USER, $CFG;
  5422. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5423. $pathtemp = $CFG->dataroot . '/temp/';
  5424. $contextuser = context_user::instance($USER->id);
  5425. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5426. $zip = new zip_packer();
  5427. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5428. $files_extract = null;
  5429. foreach ($files as $file) {
  5430. if (!$file->is_directory())
  5431. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5432. }
  5433. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5434. $typec = strtolower($iassign_t->type);
  5435. require_once 'ilm_handlers/' . $typec . '.php';
  5436. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5437. }
  5438. /// Function for register the new iLM (in database and in the directory)
  5439. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5440. // @param object $param An object with iLM params
  5441. static function copy_new_version_ilm ($param) {
  5442. global $DB, $CFG, $USER;
  5443. $itemid = $param->file;
  5444. $pathtemp = $CFG->dataroot . '/temp/';
  5445. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5446. //D echo "pathtemp=$pathtemp<br/>";
  5447. $contextuser = context_user::instance($USER->id);
  5448. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5449. $zip = new zip_packer();
  5450. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5451. $files_extract = null;
  5452. foreach ($files as $file) {
  5453. if (!$file->is_directory())
  5454. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5455. }
  5456. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5457. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5458. $typec = strtolower($iassign_t->type);
  5459. require_once 'ilm_handlers/' . $typec . '.php';
  5460. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5461. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5462. } // static function copy_new_version_ilm($param)
  5463. //VER::
  5464. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5465. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5466. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5467. /// Function for change visibility of iLM
  5468. // @param int $ilm_id Id of iLM
  5469. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5470. static function visible_ilm ($ilm_id, $status) {
  5471. global $DB;
  5472. if ($status == 0)
  5473. $visible = 1;
  5474. else
  5475. $visible = 0;
  5476. $newentry = new stdClass();
  5477. $newentry->id = $ilm_id;
  5478. $newentry->enable = $visible;
  5479. if (!$DB->update_record("iassign_ilm", $newentry))
  5480. error(get_string('error_edit_ilm', 'iassign'));
  5481. }
  5482. /// Function for confirm change default iLM
  5483. // @param int $ilm_id Id of iLM
  5484. // @param int $ilm_parent Id of parent iLM
  5485. // @return string Return with an string for create default page confirmation
  5486. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5487. global $OUTPUT, $DB;
  5488. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5489. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5490. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5491. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5492. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5493. return $return;
  5494. }
  5495. /// Function for change the default iLM
  5496. // @see settings_ilm.php
  5497. // @param int $ilm_id Id of iLM
  5498. // @return int Return Id of default iLM
  5499. static function default_ilm ($ilm_id) {
  5500. global $DB;
  5501. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5502. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5503. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5504. $iassign_ilm_default->id = $iassign_ilm->id;
  5505. $iassign_ilm_default->parent = 0;
  5506. $iassign_ilm->parent = $iassign_ilm_default->id;
  5507. $iassign_ilm->id = 0;
  5508. $iassign_ilm_default->enable = 1;
  5509. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5510. print_error('error_edit_ilm', 'iassign');
  5511. }
  5512. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5513. if (!$inserted) {
  5514. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5515. print_error($msg_error);
  5516. //xx print_error('error_add_ilm', 'iassign');
  5517. }
  5518. return $iassign_ilm_default->id;
  5519. } // static function default_ilm ($ilm_id)
  5520. /// Function for confirm delete iLM
  5521. // @param int $ilm_id Id of iLM
  5522. // @param int $ilm_parent Id of parent iLM
  5523. // @return string Return with an string for create delete page confirmation
  5524. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5525. global $OUTPUT, $DB;
  5526. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5527. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5528. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5529. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5530. }
  5531. /// Function for delete directory where the iLM is allocated.
  5532. // @param string $dirPath
  5533. // @throws InvalidArgumentException
  5534. public static function delete_dir ($dirPath) {
  5535. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5536. $dirPath .= '/';
  5537. }
  5538. $files = glob($dirPath . '*', GLOB_MARK);
  5539. foreach ($files as $file) {
  5540. if (is_dir($file)) {
  5541. ilm_settings::delete_dir($file);
  5542. } else {
  5543. unlink($file);
  5544. }
  5545. }
  5546. rmdir($dirPath);
  5547. }
  5548. /// Function for delete iLM
  5549. // @param int $ilm_id Id of iLM
  5550. // @return int Return Id of parent iLM
  5551. static function delete_ilm ($ilm_id) {
  5552. global $DB;
  5553. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5554. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5555. $typec = strtolower($iassign_ilm->type);
  5556. require_once 'ilm_handlers/' . $typec . '.php';
  5557. $retorno = $typec::delete_ilm($ilm_id);
  5558. return $retorno;
  5559. }
  5560. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5561. // @param int $ilm_id Id of iLM
  5562. static function export_ilm ($ilm_id) {
  5563. global $DB;
  5564. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5565. if (!$iassign_ilm) return; // security debug...
  5566. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5567. $typec = strtolower($iassign_ilm->type);
  5568. if (!$typec) $typec = "html5"; // security debug...
  5569. require_once 'ilm_handlers/' . $typec . '.php';
  5570. $typec::export_ilm($ilm_id);
  5571. } // static function export_ilm($ilm_id)
  5572. //TODO iLM_HTML5 :: //MOOC 2016
  5573. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5574. // @param int $ilm_id Id of iLM
  5575. static function export_update_ilm ($ilm_id) {
  5576. global $DB, $CFG;
  5577. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5578. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5579. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5580. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5581. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5582. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5583. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5584. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5585. $upgrade_descriptor .= '</upgrade>' . "\n";
  5586. file_put_contents($xml_filename, $upgrade_descriptor);
  5587. header("Pragma: public");
  5588. header("Expires: 0");
  5589. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5590. header("Cache-Control: private", false);
  5591. header('Content-Type: application/xml; charset=utf-8');
  5592. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5593. header("Content-Length: " . @filesize($xml_filename));
  5594. set_time_limit(0);
  5595. @readfile("$xml_filename") || die("File not found.");
  5596. unlink($xml_filename);
  5597. exit;
  5598. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5599. /// Function for save iLM from XML descriptor
  5600. // @param array $application_xml Data of XML descriptor
  5601. // @param array $files_extract Filenames of extract files
  5602. // @return array Return an array content id of JAR files
  5603. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5604. global $CFG, $USER;
  5605. // Tratamento diferenciado se for do tipo HTML5:
  5606. $source = "";
  5607. $diretorio = "";
  5608. if (strtolower($application_xml->type) == 'html5') {
  5609. $i = 0;
  5610. foreach ($files_extract as $key => $value) {
  5611. $file = $CFG->dataroot . '/temp/' . $key;
  5612. // Verifica se já existe a pasta no diretório dos iLM:
  5613. if ($i == 0) {
  5614. $source = $file;
  5615. if (file_exists("ilm/" . basename($file))) {
  5616. $j = 1;
  5617. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5618. $j++;
  5619. }
  5620. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5621. // mkdir($diretorio, 0777, true);
  5622. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5623. }
  5624. else {
  5625. $diretorio = 'ilm/' . basename($file);
  5626. // mkdir($diretorio, 0777, true);
  5627. mkdir($diretorio, 0755, true);
  5628. }
  5629. break;
  5630. }
  5631. $i++;
  5632. }
  5633. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5634. if ($item->isDir()) {
  5635. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5636. }
  5637. else {
  5638. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5639. }
  5640. }
  5641. ilm_settings::delete_dir($source);
  5642. return "./" . $diretorio;
  5643. }
  5644. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5645. $file_jar = array();
  5646. $files_ilm = explode(",", $application_xml->file_jar);
  5647. $contextsystem = context_system::instance();
  5648. foreach ($files_ilm as $value) {
  5649. $file_ilm = array(
  5650. 'userid' => $USER->id,
  5651. 'contextid' => $contextsystem->id,
  5652. 'component' => 'mod_iassign',
  5653. 'filearea' => 'ilm',
  5654. 'itemid' => rand(1, 999999999),
  5655. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5656. 'filename' => $value);
  5657. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5658. array_push($file_jar, $file_ilm->get_id());
  5659. }
  5660. foreach ($files_extract as $key => $value) {
  5661. $file = $CFG->dataroot . '/temp/' . $key;
  5662. if (file_exists($file))
  5663. unlink($file);
  5664. }
  5665. return $file_jar;
  5666. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5667. /// Function for import the iLM from an package
  5668. // @param int $itemid Itemid of zip file
  5669. static function import_ilm ($itemid) {
  5670. global $CFG, $USER, $OUTPUT;
  5671. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5672. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5673. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5674. }
  5675. $pathtemp = $CFG->dataroot . '/temp/';
  5676. $contextuser = context_user::instance($USER->id);
  5677. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5678. $zip = new zip_packer();
  5679. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5680. foreach ($files as $file) {
  5681. if (!$file->is_directory())
  5682. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5683. }
  5684. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5685. // Verifica se o pacote possui o XML
  5686. if (!$application_xml) {
  5687. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5688. return;
  5689. } else {
  5690. $missing = "";
  5691. if (!isset($application_xml->name)) {
  5692. $missing .= "name";
  5693. }
  5694. if (!isset($application_xml->version)) {
  5695. $missing .= ", version";
  5696. }
  5697. if (!isset($application_xml->type)) {
  5698. $missing .= ", type";
  5699. }
  5700. if (!isset($application_xml->extension)) {
  5701. $missing .= ", extension";
  5702. }
  5703. if (!isset($application_xml->file_jar)) {
  5704. $missing .= ", file_jar";
  5705. }
  5706. if (!isset($application_xml->file_class)) {
  5707. $missing .= ", file_class";
  5708. }
  5709. if (!isset($application_xml->width)) {
  5710. $missing .= ", width";
  5711. }
  5712. if (!isset($application_xml->height)) {
  5713. $missing .= ", height";
  5714. }
  5715. if (!isset($application_xml->evaluate)) {
  5716. $missing .= ", evaluate";
  5717. }
  5718. if (strlen($missing) > 2) {
  5719. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5720. return;
  5721. }
  5722. }
  5723. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5724. $typec = strtolower($application_xml->type);
  5725. require_once 'ilm_handlers/' . $typec . '.php';
  5726. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5727. } // static function import_ilm($itemid)
  5728. /// Function for list iLM defaults
  5729. // @return string Return an string with a table of iLM
  5730. static function list_ilm () {
  5731. global $DB, $OUTPUT;
  5732. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5733. $str = '';
  5734. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5735. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5736. if ($iassign_ilm) {
  5737. foreach ($iassign_ilm as $ilm) {
  5738. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5739. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5740. $str .= '<tr><td>';
  5741. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5742. $str .= '<tr>';
  5743. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5744. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5745. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5746. $str .= '</tr>';
  5747. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5748. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5749. $str .= '</table>';
  5750. $str .= '</td></tr>';
  5751. }
  5752. }
  5753. $str .= '</table>';
  5754. return $str;
  5755. }
  5756. /// Function for download and install an upgrade of an iLM
  5757. // @param int $ilm_id Id of iLM
  5758. static function upgrade_ilm ($ilm_id) {
  5759. global $DB, $CFG, $USER;
  5760. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5761. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5762. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5763. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5764. if (!$result)
  5765. print_error('error_upgrade_ilm', 'iassign');
  5766. else {
  5767. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5768. $extension = explode(".", $zip_filename);
  5769. if ($extension[count($extension) - 1] != 'ipz') {
  5770. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5771. die;
  5772. }
  5773. $zip = new zip_packer();
  5774. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5775. $contextuser = context_user::instance($USER->id);
  5776. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5777. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5778. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5779. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5780. if (file_exists($zip_filename))
  5781. unlink($zip_filename);
  5782. if (empty($file_jar)) {
  5783. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5784. print_error($msg_error);
  5785. //xx print_error('error_add_ilm', 'iassign');
  5786. }
  5787. else {
  5788. $newentry = new stdClass();
  5789. $newentry->name = (String) $application_xml->name;
  5790. $newentry->version = (String) $application_xml->version;
  5791. $newentry->url = (String) $application_xml->url;
  5792. $newentry->description = $description_str;
  5793. $newentry->extension = strtolower((String) $application_xml->extension);
  5794. $newentry->file_jar = implode(",", $file_jar);
  5795. $newentry->file_class = (String) $application_xml->file_class;
  5796. $newentry->width = (String) $application_xml->width;
  5797. $newentry->height = (String) $application_xml->height;
  5798. $newentry->enable = 0;
  5799. $newentry->timemodified = time();
  5800. $newentry->author = $USER->id;
  5801. $newentry->timecreated = time();
  5802. $newentry->evaluate = (String) $application_xml->evaluate;
  5803. $newentry->parent = $ilm_id;
  5804. }
  5805. }
  5806. return $iassign_ilm->id;
  5807. } // static function upgrade_ilm($ilm_id)
  5808. //MOOC2014 -- inicio
  5809. //TODO: REVIEW
  5810. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5811. // static function move_iassign($ilm_id)
  5812. //MOOC2014 -- final
  5813. /// Function for list iLM versions with all informations, under "admin" plugin view: .../mod/iassign/settings_ilm.php?action=view&ilm_id=".$ilmid."&from=admin
  5814. // @return string Return an string with a table of iLM
  5815. static function view_ilm ($ilmid, $from) {
  5816. global $DB;
  5817. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5818. // Get the iLM type and calls its correpondent handler ('Java' or 'HTML5')
  5819. $typec = strtolower($iassign_ilm->type);
  5820. require_once 'ilm_handlers/' . $typec . '.php';
  5821. $retorno = $typec::view_ilm($ilmid, $from);
  5822. return $retorno;
  5823. }
  5824. /// Function for get form variables for add, edit, or copy iLM params
  5825. // @param int $ilm_param_id Id of iLM param
  5826. // @param string $action String with the action
  5827. // @return object Return an object with forms variables
  5828. static function add_edit_copy_param ($ilm_param_id, $action) {
  5829. global $DB;
  5830. require_once('params_form.php');
  5831. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5832. $param = new stdClass();
  5833. $param->action = $action;
  5834. $param->ilm_param_id = $ilm_param_id;
  5835. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5836. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5837. $type = $iassign_ilm_config->param_type;
  5838. if ($action == 'add') {
  5839. $param->title = get_string('add_ilm', 'iassign');
  5840. $param->iassign_ilmid = $ilm_param_id;
  5841. $param->param_name = "";
  5842. $param->param_value = "";
  5843. $param->description = "";
  5844. $param->visible = 1;
  5845. }
  5846. elseif ($action == 'edit') {
  5847. if ($iassign_ilm_config) {
  5848. $param->title = get_string('edit_ilm', 'iassign');
  5849. $param->id = $iassign_ilm_config->id;
  5850. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5851. $param->param_type = $type; //MOOC2014
  5852. $param->param_name = $iassign_ilm_config->param_name;
  5853. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5854. $param->param_value = $iassign_ilm_config->param_value;
  5855. else //MOOC2014
  5856. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5857. $param->param_value = $iassign_ilm_config->param_value;
  5858. $param->description = $iassign_ilm_config->description;
  5859. $param->visible = $iassign_ilm_config->visible;
  5860. }
  5861. }
  5862. elseif ($action == 'copy') {
  5863. if ($iassign_ilm_config) {
  5864. $param->title = get_string('copy_ilm', 'iassign');
  5865. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5866. $param->param_type = $type; //MOOC2014
  5867. $param->param_name = $iassign_ilm_config->param_name;
  5868. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5869. $param->param_value = $iassign_ilm_config->param_value;
  5870. else //MOOC2014
  5871. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5872. $param->description = $iassign_ilm_config->description;
  5873. $param->visible = $iassign_ilm_config->visible;
  5874. }
  5875. }
  5876. return $param;
  5877. } // static function add_edit_copy_param($ilm_param_id, $action)
  5878. /// Function for change visibility of iLM param
  5879. // @param int $ilm_param_id Id of iLM param
  5880. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5881. static function visible_param ($ilm_param_id, $status) {
  5882. global $DB, $CFG;
  5883. if ($status == 0)
  5884. $visible = 1;
  5885. else
  5886. $visible = 0;
  5887. $newentry = new stdClass();
  5888. $newentry->id = $ilm_param_id;
  5889. $newentry->visible = $visible;
  5890. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5891. error(get_string('error_edit_param', 'iassign'));
  5892. }
  5893. /// Function for save in database an new iLM param
  5894. // @param object $param An object with iLM params
  5895. static function add_param ($param) {
  5896. global $DB;
  5897. $newentry = new stdClass();
  5898. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5899. //MOOC2014 $newentry->param_name = $param->param_name;
  5900. $newentry->param_type = $param->param_type; //MOOC2014
  5901. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5902. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5903. $newentry->param_value = $param->param_value;
  5904. else //MOOC2014
  5905. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5906. $newentry->description = $param->description;
  5907. $newentry->visible = $param->visible;
  5908. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5909. if (!$newentry->id) {
  5910. print_error('error_add_param', 'iassign');
  5911. }
  5912. }
  5913. /// Function for save in database a iLM param edit
  5914. // @param object $param An object with iLM params
  5915. static function edit_param ($param) {
  5916. global $DB;
  5917. $updentry = new stdClass();
  5918. $updentry->id = $param->id;
  5919. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5920. $updentry->param_type = $param->param_type; //MOOC2014
  5921. // $updentry->param_name = $param->param_name;
  5922. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5923. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5924. $updentry->param_value = $param->param_value;
  5925. else //MOOC2014
  5926. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5927. $updentry->description = $param->description;
  5928. $updentry->visible = $param->visible;
  5929. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5930. error(get_string('error_edit_param', 'iassign'));
  5931. }
  5932. }
  5933. /// Function for save in database a iLM param copy
  5934. // @param object $param An object with iLM params
  5935. static function copy_param ($param) {
  5936. global $DB;
  5937. $newentry = new stdClass();
  5938. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5939. //$newentry->param_name = $param->param_name;
  5940. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5941. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5942. $newentry->param_value = $param->param_value;
  5943. else //MOOC2014
  5944. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5945. $newentry->description = $param->description;
  5946. $newentry->visible = $param->visible;
  5947. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5948. if (!$newentry->id) {
  5949. print_error('error_add_param', 'iassign');
  5950. }
  5951. }
  5952. /// Function for delete iLM param of database
  5953. // @param int $param_id Id of iLM param
  5954. static function delete_param ($param_id) {
  5955. global $DB;
  5956. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5957. print_error('error_delete_param', 'iassign');
  5958. }
  5959. }
  5960. } // class ilm_settings
  5961. /// Class for manage iLM files (editor).
  5962. class ilm_manager {
  5963. var $id; // course id
  5964. var $url;
  5965. var $from;
  5966. /// Constructor for the base ilm_manager class
  5967. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5968. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5969. function __construct ($id, $url, $from) {
  5970. $this->id = $id; // course id
  5971. $this->url = $url;
  5972. $this->from = $from;
  5973. }
  5974. /// Function to get iAssign content file in Moodle data (exercise)
  5975. // @calledby x function preview_ilm($iassign_ilm) :
  5976. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5977. function get_file_ilm () {
  5978. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5979. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5980. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5981. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5982. $md_file = $fs->get_file_by_id($fileid);
  5983. $ilm_content_file = $md_file->get_content();
  5984. return $ilm_content_file;
  5985. }
  5986. /// Function for creating a new file from the iLM online editor
  5987. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5988. function ilm_editor_new () {
  5989. global $CFG, $DB, $OUTPUT, $PAGE;
  5990. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5991. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5992. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5993. $context = context_course::instance($this->id);
  5994. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5995. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5996. if (!$iassign) {
  5997. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5998. die();
  5999. }
  6000. $temp = explode(",", $iassign->extension);
  6001. $extension = $temp[0]; // default extension for this iLM
  6002. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  6003. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6004. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  6005. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  6006. if ($stringArchiveContent != NULL) {
  6007. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  6008. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6009. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  6010. $filename = optional_param('filename', NULL, PARAM_RAW);
  6011. //Leo $filename = iassign_utils::format_filename($filename); //
  6012. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  6013. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  6014. //2019/02 $arrayfilename = explode(".", $filename);
  6015. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  6016. //2019/02 $count_dots = count($arrayfilename);
  6017. //2019/02 if ($count_dots > 0) { // at least one dot mark
  6018. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  6019. //2019/02 if ($last_name != $extension)
  6020. //2019/02 $filename = $filename . '.' . $extension;
  6021. //2019/02 }
  6022. //2019/02 else { // no extension...
  6023. //2019/02 $filename = $filename . '.' . $extension;
  6024. //2019/02 }
  6025. // Store the name of recent created file
  6026. $_SESSION['file_name'] = $filename;
  6027. //$this->write_file_iassign($string, $filename);
  6028. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  6029. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  6030. die();
  6031. }
  6032. else { // if ($stringArchiveContent != NULL)
  6033. // iLM On-line editor
  6034. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6035. $str_get_iLM = "window.frames.iLM";
  6036. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6037. }
  6038. else { // otherwise it is JAR named 'iLM'
  6039. $str_get_iLM = "document.iLM";
  6040. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6041. }
  6042. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6043. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  6044. $files_array = '';
  6045. foreach ($files as $value) {
  6046. if ($value->get_filename() != ".")
  6047. $files_array .= "'" . $value->get_filename() . "',";
  6048. }
  6049. $files_array .= "''";
  6050. $file = null;
  6051. $ia_content = "";
  6052. $filename = "";
  6053. $error_files_exists = get_string('error_file_exists', 'iassign');
  6054. $output = "<script type='text/javascript'>
  6055. //<![CDATA[
  6056. //D alert('locallib.php: ilm_editor_new');
  6057. function submit_iLM_Answer () {
  6058. var docFormOnLineEditor = document.formEnvio;
  6059. var resposta_exerc = new Array(3);
  6060. var valor_resposta = new Array(3);
  6061. var sessao = new Array(3);
  6062. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6063. resposta_exerc[0] = doc_iLM.getAnswer();
  6064. valor_resposta[0] = doc_iLM.getEvaluation();
  6065. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  6066. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  6067. var files = new Array(" . $files_array . ");
  6068. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  6069. if (docFormOnLineEditor.filename.value=='') {
  6070. // ERROR: the file name is empty
  6071. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  6072. return false;
  6073. }
  6074. // }
  6075. for (i=0; i<files.length; i++) {
  6076. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  6077. alert('" . $error_files_exists . "');
  6078. return false;
  6079. }
  6080. }
  6081. docFormOnLineEditor.submit();
  6082. return true;
  6083. }
  6084. //]]>
  6085. </script>\n";
  6086. $output .= "
  6087. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6088. $output .= $OUTPUT->box_start();
  6089. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  6090. $output .= "
  6091. <table width='100%' cellpadding='20'>
  6092. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  6093. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  6094. </tr>
  6095. </table>\n";
  6096. $output .= $OUTPUT->box_end();
  6097. $output .= "<center>\n";
  6098. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  6099. // Since it is the activity file, it is not necessary to use 'ilm_security'
  6100. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  6101. $output .= $output_ilm;
  6102. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  6103. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  6104. </center>
  6105. </form>\n";
  6106. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6107. $PAGE->navbar->add($title);
  6108. $PAGE->set_title($title);
  6109. $PAGE->set_heading($title); // insert title above the navigation bar
  6110. print $OUTPUT->header();
  6111. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6112. print $output;
  6113. print $OUTPUT->footer();
  6114. }
  6115. die();
  6116. } // function ilm_editor_new()
  6117. /// Function for editing an file in online editor
  6118. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  6119. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  6120. global $CFG, $DB, $OUTPUT, $PAGE;
  6121. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6122. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6123. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6124. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6125. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6126. // If iLM is not registered, error!
  6127. if (!$iassign) {
  6128. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  6129. die;
  6130. }
  6131. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  6132. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  6133. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  6134. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  6135. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6136. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6137. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  6138. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  6139. if ($stringArchiveContent != NULL) {
  6140. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  6141. die();
  6142. } else { // if ($stringArchiveContent != NULL)
  6143. $end_file = '';
  6144. if ($content_file) {
  6145. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  6146. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  6147. }
  6148. $temp = explode(",", $iassign->extension);
  6149. $extension = $temp[0]; // default extension for this iLM
  6150. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6151. $str_get_iLM = "window.frames.iLM";
  6152. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6153. } else { // otherwise it is JAR named 'iLM'
  6154. $str_get_iLM = "document.iLM";
  6155. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6156. }
  6157. $output = "<script type='text/javascript'>
  6158. //<![CDATA[
  6159. function submit_iLM_Answer () {
  6160. var docFormEditor = document.formEnvio;
  6161. var activityAnswer; // to get activity answer (text)
  6162. var activityValue; // to get activity answer value (float)
  6163. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6164. //activityAnswer = doc_iLM.getAnswer();
  6165. //activityValue = doc_iLM.getEvaluation();
  6166. activityAnswer = " . $str_get_iLM . ".getAnswer();
  6167. activityValue = " . $str_get_iLM . ".getEvaluation();
  6168. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  6169. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  6170. docFormEditor.submit();
  6171. return true;
  6172. }
  6173. //]]>
  6174. </script>\n";
  6175. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  6176. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  6177. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  6178. // return true;
  6179. // }
  6180. $output .= "
  6181. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6182. $output .= $OUTPUT->box_start();
  6183. $output .= "
  6184. <table width='100%' cellpadding='20'>
  6185. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  6186. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  6187. <input type='hidden' name='filename' value='$filename'/></td>
  6188. <td>
  6189. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  6190. </tr>
  6191. </table>\n";
  6192. $output .= $OUTPUT->box_end();
  6193. $output .= " <center>\n";
  6194. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  6195. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  6196. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  6197. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  6198. </center>
  6199. </form>\n";
  6200. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6201. $PAGE->navbar->add($title);
  6202. $PAGE->set_title($title);
  6203. $PAGE->set_heading($title); // insert title above the navigation bar
  6204. print $OUTPUT->header();
  6205. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6206. print $output;
  6207. print $OUTPUT->footer();
  6208. } // else if ($stringArchiveContent != NULL)
  6209. die();
  6210. } // function ilm_editor_update()
  6211. /// Function for write iAssign file in Moodle data (exercise)
  6212. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  6213. // @param string $stringArchiveContent Content of iassign file
  6214. // @param string $filename Filename of iassign file
  6215. function write_file_iassign ($stringArchiveContent, $filename) {
  6216. global $USER;
  6217. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6218. $context = context_course::instance($this->id);
  6219. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6220. $dirid = $this->get_dir_ilm('dirid');
  6221. $dir = $fs->get_file_by_id($dirid);
  6222. $fileinfo = array('contextid' => $context->id, // ID of course
  6223. 'component' => 'mod_iassign', // usually = table name
  6224. 'filearea' => 'activity', // usually = table name
  6225. 'itemid' => 0, // usually = ID of row in table
  6226. 'filepath' => '/', // any path beginning and ending whith '/'
  6227. 'userid' => $USER->id,
  6228. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6229. 'filename' => $filename); // any filename
  6230. // Create file containing text. '$stringArchiveContent'
  6231. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6232. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  6233. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  6234. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  6235. // 'Activité interactive enregistrée avec succès sous le nom:';
  6236. // 'Atividade interativa gravada com sucesso sob o nome:'
  6237. $output = "
  6238. <script type='text/javascript'>
  6239. //<![CDATA[
  6240. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  6241. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6242. //]]>
  6243. </script>";
  6244. print $output;
  6245. die();
  6246. }
  6247. /// Function for write iAssign file in Moodle data (exercise)
  6248. // @param string $stringArchiveContent Content of iassign file
  6249. // @param string $filename Filename of iassign file
  6250. // @param int $itemid Itemid of iassign file
  6251. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  6252. global $OUTPUT, $USER;
  6253. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6254. $context = context_course::instance($this->id);
  6255. $dirid = $this->get_dir_ilm('dirid');
  6256. if ($stringArchiveContent != (-1)) {
  6257. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6258. $file = $fs->get_file_by_id($fileid);
  6259. if (!$file) {
  6260. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  6261. die;
  6262. }
  6263. $fileinfo = array('contextid' => $context->id, // ID of context
  6264. 'component' => 'mod_iassign', // usually = table name
  6265. 'filearea' => 'activity', // usually = table name
  6266. 'itemid' => 0, // usually = ID of row in table
  6267. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  6268. 'userid' => $USER->id,
  6269. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6270. 'license' => 'allrightsreserved', // allrightsreserved
  6271. 'timecreated' => $file->get_timecreated(),
  6272. 'filename' => $file->get_filename()); // any filename
  6273. $file->delete();
  6274. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6275. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  6276. }
  6277. $output = "<script type='text/javascript'>
  6278. //<![CDATA[
  6279. alert('" . get_string('sucess_update', 'iassign') . "');\n
  6280. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6281. //]]>
  6282. </script>";
  6283. print $output;
  6284. die();
  6285. }
  6286. /// Function for create an tag for iAssign filter
  6287. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  6288. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6289. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  6290. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6291. // @param int $fileid Id of file
  6292. // @return string Return an string with an tag of iassign filter
  6293. function tag_ilm ($fileid) {
  6294. global $DB;
  6295. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6296. $width = '600';
  6297. $height = '400';
  6298. $file = $fs->get_file_by_id($fileid);
  6299. $filetype = explode(".", $file->get_filename());
  6300. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  6301. foreach ($iassign_ilm as $value) {
  6302. $extensions = explode(",", $value->extension);
  6303. if (in_array($filetype[1], $extensions)) {
  6304. $width = $value->width;
  6305. $height = $value->height;
  6306. }
  6307. }
  6308. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  6309. }
  6310. /// Function for delete iAssign file in Moodle data (exercise)
  6311. function delete_file_ilm () {
  6312. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6313. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6314. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  6315. $file = $fs->get_file_by_id($fileid);
  6316. if ($file)
  6317. $file->delete();
  6318. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6319. die();
  6320. }
  6321. /// Function for delete selected iAssign file in Moodle data (exercise)
  6322. function delete_selected_ilm () {
  6323. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6324. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6325. $context = context_course::instance($this->id);
  6326. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6327. $dirid = $this->get_dir_ilm('dirid');
  6328. foreach ($files_id as $file_id) {
  6329. $file = $fs->get_file_by_id($file_id);
  6330. if ($file) {
  6331. if (!$file->is_directory())
  6332. $file->delete();
  6333. else {
  6334. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6335. foreach ($files_delete as $value)
  6336. $value->delete();
  6337. $file->delete();
  6338. }
  6339. }
  6340. }
  6341. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6342. die();
  6343. }
  6344. /// Function for duplicate iAssign file from "online" edition
  6345. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  6346. function duplicate_file_ilm () {
  6347. global $USER, $COURSE;
  6348. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6349. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6350. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6351. $filename = optional_param('filename', NULL, PARAM_RAW);
  6352. $file = $fs->get_file_by_id($fileid);
  6353. $context = context_course::instance($this->id);
  6354. $fileinfo = array(
  6355. 'contextid' => $context->id, // ID of context
  6356. 'component' => 'mod_iassign', // usually = table name
  6357. 'filearea' => 'activity', // usually = table name
  6358. 'itemid' => 0, // usually = ID of row in table
  6359. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  6360. 'userid' => $USER->id,
  6361. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6362. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  6363. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  6364. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  6365. die();
  6366. }
  6367. /// Function for rename iAssign file
  6368. function rename_file_ilm () {
  6369. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6370. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6371. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6372. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6373. $file = $fs->get_file_by_id($fileid);
  6374. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  6375. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  6376. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6377. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  6378. die();
  6379. }
  6380. /// Function for get iassign file for iassign form
  6381. function add_ilm () {
  6382. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6383. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6384. $output = "
  6385. <script type='text/javascript'>
  6386. //<![CDATA[
  6387. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  6388. iassign_file_link.innerHTML = '$filename';
  6389. window.opener.document.forms['mform1'].file.value='$fileid';
  6390. window.opener.document.forms['mform1'].filename.value='$filename';
  6391. window.close();
  6392. //]]>
  6393. </script>";
  6394. print $output;
  6395. die();
  6396. }
  6397. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  6398. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  6399. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  6400. function preview_ilm ($courseid, $iassign_ilm) {
  6401. global $OUTPUT, $CFG, $USER;
  6402. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6403. $title = get_string('modulename', 'iassign'); // iAssign
  6404. print $OUTPUT->header();
  6405. print $OUTPUT->box_start();
  6406. $javascript = "
  6407. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  6408. <script type='text/javascript'>
  6409. //<![CDATA[
  6410. function submit_close () {
  6411. window.opener.location.reload();
  6412. window.close();
  6413. }
  6414. //]]>
  6415. </script>\n";
  6416. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6417. // to the complete "applet" tag
  6418. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6419. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6420. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6421. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6422. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6423. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6424. if ($ilm_name != "ivprog") {
  6425. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6426. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6427. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6428. } else {
  6429. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6430. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6431. $timecreated = time();
  6432. $token = md5($timecreated);
  6433. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6434. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6435. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6436. $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)
  6437. }
  6438. $html = "
  6439. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6440. <table border='1'>
  6441. <tr><td>
  6442. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6443. <!-- iLM calls : end -->
  6444. </td></tr>
  6445. </table>
  6446. <table>
  6447. <tr>
  6448. <td align='center'>
  6449. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6450. </td></tr>
  6451. </table>
  6452. </form>\n";
  6453. print $javascript . $html;
  6454. print $OUTPUT->box_end();
  6455. //NAO echo format_string($html); // Moodle 3.X
  6456. die();
  6457. } // function preview_ilm($courseid, $iassign_ilm)
  6458. //r_ function preview_ilm ($iassign_ilm)
  6459. //r_ /// Function for preview iassign file from iassign filter.
  6460. //r_ function preview_ilm() {
  6461. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6462. //r_ $tag_filter = $this->tag_ilm($fileid);
  6463. //r_ $javascript = "<script type='text/javascript'>
  6464. //r_ //<![CDATA[
  6465. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6466. //r_ //]]>
  6467. //r_ </script>";
  6468. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6469. //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>
  6470. //r_ </table></form></body></html>";
  6471. //r_ echo $javascript . format_text($html);
  6472. //r_ die;
  6473. //r_ }
  6474. /// Function for export an package (zip) of iassign files
  6475. function export_files_ilm () {
  6476. global $CFG;
  6477. $context = context_course::instance($this->id);
  6478. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6479. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6480. $zip = new zip_archive();
  6481. $zip->open($zip_filename);
  6482. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6483. foreach ($files_id as $file_id) {
  6484. $file = $fs->get_file_by_id($file_id);
  6485. if (!$file->is_directory())
  6486. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6487. else {
  6488. $zip->add_directory($file->get_filepath());
  6489. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6490. foreach ($files_zip as $value) {
  6491. if (!$value->is_directory())
  6492. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6493. else
  6494. $zip->add_directory($value->get_filepath());
  6495. }
  6496. }
  6497. }
  6498. $zip->close();
  6499. header("Pragma: public");
  6500. header("Expires: 0");
  6501. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6502. header("Cache-Control: private", false);
  6503. header("Content-Type: application/zip");
  6504. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6505. header("Content-Transfer-Encoding: binary");
  6506. header("Content-Length: " . @filesize($zip_filename));
  6507. set_time_limit(0);
  6508. @readfile("$zip_filename") || die("File not found.");
  6509. unlink($zip_filename);
  6510. exit;
  6511. }
  6512. /// Function of execute a command in button editor tinymce
  6513. // @param int $fileid Id of file
  6514. function tinymce_ilm ($fileid) {
  6515. $tag_filter = $this->tag_ilm($fileid);
  6516. $output = "<script type='text/javascript'>
  6517. //<![CDATA[
  6518. var tag_filter = '$tag_filter';
  6519. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6520. // all right, insert it
  6521. } else {
  6522. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6523. }
  6524. // window.close();
  6525. //]]>
  6526. </script>\n";
  6527. print $output;
  6528. die();
  6529. }
  6530. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6531. /// Function to add content to the Editor Window
  6532. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6533. // @param int $fileid Id of file
  6534. function editor_ilm ($fileid, $editor) {
  6535. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6536. $output1 = "<script type='text/javascript'>
  6537. //<![CDATA[
  6538. var tag_filter = '$tag_filter';\n";
  6539. if ($editor == 'atto') {
  6540. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6541. } elseif ($editor == 'tinyMCE') {
  6542. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6543. } else
  6544. $output2 = "";
  6545. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6546. window.close();
  6547. //]]>
  6548. </script>\n";
  6549. //D var_dump($output);
  6550. print $output1 . $output2 . $output3;
  6551. die();
  6552. }
  6553. /// Function to add content to the Atto Editor Window
  6554. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6555. // @param int $fileid Id of file
  6556. function atto_ilm ($fileid) {
  6557. global $CFG, $DB;
  6558. $tag_filter = $this->tag_ilm($fileid);
  6559. $output = "<script type='text/javascript'>
  6560. //<![CDATA[
  6561. var tag_filter = '$tag_filter';
  6562. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6563. // all right, insert iLM tag to this editor
  6564. } else {
  6565. // error trying to insert
  6566. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6567. }
  6568. //window.close();
  6569. //]]>
  6570. </script>\n";
  6571. print $output;
  6572. die();
  6573. }
  6574. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6575. // @param string $key Key for return information
  6576. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6577. function get_dir_ilm ($key) {
  6578. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6579. $context = context_course::instance($this->id);
  6580. $dirid = optional_param('dirid', 0, PARAM_INT);
  6581. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6582. if ($dirid == 0) {
  6583. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6584. $dirid = $dir->get_id();
  6585. }
  6586. else {
  6587. $dir = $fs->get_file_by_id($dirid);
  6588. $dir_base = $dir->get_filepath();
  6589. }
  6590. $dir_parent = $dir->get_parent_directory();
  6591. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6592. return $data[$key];
  6593. }
  6594. /// Function for create an new dir
  6595. function new_dir_ilm () {
  6596. global $USER;
  6597. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6598. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6599. $dir_base = $this->get_dir_ilm('dir_base');
  6600. $context = context_course::instance($this->id);
  6601. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6602. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6603. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6604. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6605. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6606. }
  6607. /// Function for delete an dir
  6608. function delete_dir_ilm () { //
  6609. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6610. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6611. $context = context_course::instance($this->id);
  6612. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6613. $dir_parent = $this->get_dir_ilm('dir_parent');
  6614. if ($dir) {
  6615. if ($dir->is_directory()) {
  6616. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6617. foreach ($files_delete as $value)
  6618. $value->delete();
  6619. $dir->delete();
  6620. }
  6621. }
  6622. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6623. die();
  6624. }
  6625. /// Function for rename an dir
  6626. function rename_dir_ilm () {
  6627. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6628. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6629. $context = context_course::instance($this->id);
  6630. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6631. $dir_parent = $this->get_dir_ilm('dir_parent');
  6632. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6633. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6634. if ($dir->is_directory()) {
  6635. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6636. foreach ($files_rename_path as $value)
  6637. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6638. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6639. }
  6640. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6641. die();
  6642. }
  6643. /// Function for move an dir and your content for other dir
  6644. function selected_move_ilm () {
  6645. global $PAGE, $OUTPUT, $CFG;
  6646. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6647. $context = context_course::instance($this->id);
  6648. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6649. $dirid = $this->get_dir_ilm('dirid');
  6650. $dir_base = $this->get_dir_ilm('dir_base');
  6651. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6652. $code_javascript_ilm = "
  6653. <script type='text/javascript'>
  6654. //<![CDATA[
  6655. function getRadiobutton () {
  6656. var radioButtons = document.getElementsByTagName('input');
  6657. var param = '';
  6658. for (var counter=0; counter < radioButtons.length; counter++) {
  6659. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6660. param = radioButtons[counter].value;
  6661. }
  6662. return param;
  6663. }
  6664. function move_selected_ilm () {
  6665. var msgAnswer;
  6666. if (getRadiobutton() != '') {
  6667. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6668. if (msgAnswer)
  6669. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6670. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6671. }
  6672. else
  6673. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6674. }
  6675. function cancel_selected_ilm () {
  6676. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6677. }
  6678. //]]>
  6679. </script>\n";
  6680. $title = get_string('move_files', 'iassign');
  6681. $PAGE->set_title($title);
  6682. $PAGE->set_pagelayout('base');
  6683. print $OUTPUT->header();
  6684. print $OUTPUT->heading($title);
  6685. $dir_paths = array();
  6686. print $OUTPUT->box_start();
  6687. print "<center>";
  6688. foreach ($files_id as $file_id) {
  6689. $file = $fs->get_file_by_id($file_id);
  6690. if ($file) {
  6691. if (!$file->is_directory())
  6692. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6693. else {
  6694. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6695. array_push($dir_paths, $file->get_filepath());
  6696. }
  6697. }
  6698. }
  6699. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6700. if ($dir_base != '/') {
  6701. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6702. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6703. }
  6704. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6705. foreach ($files_tree as $file) {
  6706. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6707. $is_parent = false;
  6708. foreach ($dir_paths as $dir) {
  6709. $path = explode("/", $dir);
  6710. array_pop($path);
  6711. $path[count($path) - 1] = '';
  6712. $path = implode("/", $path);
  6713. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6714. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6715. }
  6716. if ($is_parent == false) {
  6717. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6718. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6719. }
  6720. }
  6721. }
  6722. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6723. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6724. print "</center>";
  6725. print $OUTPUT->box_end();
  6726. print $OUTPUT->footer();
  6727. print $code_javascript_ilm;
  6728. die;
  6729. }
  6730. /// Function for move files for an dir
  6731. function move_files_ilm () {
  6732. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6733. $context = context_course::instance($this->id);
  6734. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6735. $dirid = $this->get_dir_ilm('dirid');
  6736. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6737. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6738. foreach ($files_id as $file_id) {
  6739. $file = $fs->get_file_by_id($file_id);
  6740. if ($file) {
  6741. if ($file->is_directory()) {
  6742. $pathname = explode("/", $file->get_filepath());
  6743. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6744. foreach ($files_move_path as $value) {
  6745. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6746. $value->rename($path_move, $value->get_filename());
  6747. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6748. }
  6749. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6750. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6751. $file->rename($path_move, $file->get_filename());
  6752. } else {
  6753. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6754. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6755. }
  6756. }
  6757. }
  6758. //die;
  6759. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6760. die();
  6761. } // function move_files_ilm()
  6762. /// Function for recover files in use on all activities of a course
  6763. function recover_files_ilm () {
  6764. global $DB, $USER;
  6765. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6766. $courseid = optional_param('id', NULL, PARAM_INT);
  6767. $dirid = $this->get_dir_ilm('dirid');
  6768. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6769. $contextfile = context_course::instance($this->id);
  6770. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6771. foreach ($iassigns as $iassign) {
  6772. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6773. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6774. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6775. $context = context_module::instance($cm->id);
  6776. // Before associtaion 'files.id' with 'iassign_statement.iassign_ilmid': $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6777. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
  6778. if ($files) {
  6779. foreach ($files as $value) {
  6780. $extension = explode(".", $value->get_filename());
  6781. if (!$value->is_directory()) {
  6782. $fileinfo = array('contextid' => $contextfile->id,
  6783. 'component' => 'mod_iassign',
  6784. 'filearea' => 'activity',
  6785. 'itemid' => 0,
  6786. 'filepath' => $this->get_dir_ilm('dir_base'),
  6787. 'userid' => $USER->id,
  6788. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6789. 'license' => 'allrightsreserved',
  6790. 'timecreated' => time(),
  6791. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6792. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6793. }
  6794. }
  6795. } // if ($files)
  6796. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6797. } // foreach ($iassigns as $iassign)
  6798. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6799. die();
  6800. } // function recover_files_ilm()
  6801. /// Auxiliary function the get all files in a given context
  6802. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6803. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6804. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6805. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6806. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6807. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6808. // (NAO s_iassign_statement.file = s_files.id)
  6809. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6810. $dir_base = $this->get_dir_ilm('dir_base');
  6811. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6812. $countf = 0;
  6813. $array_files_id = array(); // all files from this context
  6814. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6815. //$filename = $item_fc->get_filename();
  6816. //$filepath = $item_fc->get_filepath();
  6817. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6818. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6819. // $array_files_aux[] = $item_fc;
  6820. $itemid = $item_fc->get_id();
  6821. if (!in_array($itemid, $array_files_id)) {
  6822. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6823. if ($fileuserid == $userid)
  6824. $filesfrommine[] = $item_fc;
  6825. else
  6826. $filesfromothers[] = $item_fc;
  6827. $array_files_id[] = $itemid;
  6828. $countf++;
  6829. }
  6830. }
  6831. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6832. return $countf;
  6833. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6834. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6835. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6836. function get_all_ilm_files_by_fileid ($fileid) {
  6837. global $DB, $USER;
  6838. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6839. //TODO Criar coluna 'authorid'
  6840. $str_query = "SELECT * FROM {iassign_statement} " .
  6841. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6842. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6843. return $array_iassign_ilm;
  6844. }
  6845. //NN
  6846. // Build string with JavaScript code with function to edit/remove/double iLM files
  6847. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6848. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6849. global $CFG;
  6850. $error_files_exists = get_string('error_file_exists', 'iassign');
  6851. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6852. $code_javascript_ilm = "
  6853. <script type='text/javascript'>
  6854. //<![CDATA[
  6855. function preview_ilm (fileid, ilmid) { //JavaScript function
  6856. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6857. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6858. }
  6859. function update_ilm (ilmid, fileid) { //JavaScript function
  6860. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6861. }
  6862. function delete_ilm (ilmid, fileid) { //JavaScript function
  6863. var msgAnswer;
  6864. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6865. if (msgAnswer) {
  6866. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6867. }
  6868. }
  6869. function delete_selected_ilm () { //JavaScript function
  6870. var msgAnswer;
  6871. var param = getCheckbox();
  6872. if (param.join() != '') {
  6873. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6874. if (msgAnswer)
  6875. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6876. }
  6877. else
  6878. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6879. }
  6880. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6881. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6882. }
  6883. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6884. var filenamecopy;
  6885. var i;
  6886. var files = new Array(" . $files_array . ");
  6887. do {
  6888. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6889. } while (filenamecopy == '');
  6890. if (filenamecopy == null)
  6891. return false;\n
  6892. else {
  6893. for (i=0;i<files.length;i++) {
  6894. if (files[i]==filenamecopy) {
  6895. alert('" . $error_files_exists . "');
  6896. return false;\n
  6897. }
  6898. }\n" .
  6899. // @see: function 'duplicate_file_ilm()' above
  6900. "
  6901. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6902. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6903. } // else
  6904. }
  6905. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6906. var filenamecopy;
  6907. var i;
  6908. var files = new Array($files_array);
  6909. do {
  6910. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6911. } while (filenamecopy == '');
  6912. if (filenamecopy == null)
  6913. return false;
  6914. else {
  6915. for (i=0;i<files.length;i++) {
  6916. if (files[i]==filenamecopy) {
  6917. alert('" . $error_files_exists . "');
  6918. return false;
  6919. }
  6920. }
  6921. 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;
  6922. }
  6923. }
  6924. function export_files_ilm () { //JavaScript function
  6925. var param = getCheckbox();
  6926. if (param.join() != '')
  6927. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6928. else
  6929. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6930. }
  6931. function select_all_ilm () { //JavaScript function
  6932. var checkBoxes = document.getElementsByTagName('input');
  6933. var selectAll = document.getElementById('select_all');
  6934. for (var counter=0; counter < checkBoxes.length; counter++) {
  6935. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6936. checkBoxes[counter].checked = selectAll.checked;
  6937. }
  6938. }
  6939. function getCheckbox () { //JavaScript function
  6940. var checkBoxes = document.getElementsByTagName('input');
  6941. var param = new Array();
  6942. for (var counter=0; counter < checkBoxes.length; counter++) {
  6943. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6944. param.push(checkBoxes[counter].value);
  6945. }
  6946. return param;
  6947. }
  6948. function new_dir_ilm () { //JavaScript function
  6949. var dirname = '';
  6950. var i;
  6951. var dirs = new Array(" . $dirs_array . ");
  6952. do {
  6953. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6954. } while (dirname == '');
  6955. if (dirname == null)
  6956. return false;\n
  6957. else {
  6958. for (i=0;i<dirs.length;i++) {
  6959. if (dirs[i]==dirname) {
  6960. alert('" . $error_dir_exists . "');
  6961. return false;\n
  6962. }
  6963. }
  6964. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6965. }
  6966. }
  6967. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6968. var msgAnswer;
  6969. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6970. if (msgAnswer) {
  6971. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6972. }
  6973. }
  6974. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6975. var dirnamecopy;
  6976. var i;
  6977. var dirs = new Array($dirs_array);
  6978. do {
  6979. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6980. } while (dirnamecopy == '');
  6981. if (dirnamecopy == null)
  6982. return false;\n
  6983. else {
  6984. for (i=0;i<dirs.length;i++) {
  6985. if (dirs[i]==dirnamecopy) {
  6986. alert('" . $error_dir_exists . "');
  6987. return false;\n
  6988. }
  6989. }
  6990. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6991. }
  6992. }
  6993. function move_selected_ilm (ilmid) { //JavaScript function
  6994. var param = getCheckbox();
  6995. if (param.join() != '')
  6996. 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();
  6997. else
  6998. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6999. }
  7000. function recover_files_ilm () { //JavaScript function
  7001. var msgAnswer;
  7002. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7003. if (msgAnswer) {
  7004. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7005. }
  7006. }
  7007. window.onload = function() { //JavaScript function
  7008. var xPosition = 0;
  7009. var yPosition = 0;
  7010. element=document.getElementById('new_file');
  7011. while(element) {
  7012. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7013. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7014. element = element.offsetParent;
  7015. }
  7016. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7017. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7018. location.hash = '#new_file';
  7019. };
  7020. //]]>
  7021. </script>\n"; // end of $code_javascript_ilm
  7022. return $code_javascript_ilm;
  7023. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  7024. /// List iassign files from course directory
  7025. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  7026. function view_files_ilm ($iassign_ilm_class, $extension) {
  7027. global $CFG, $DB, $USER, $OUTPUT;
  7028. $fs = get_file_storage();
  7029. $context = context_course::instance($this->id);
  7030. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  7031. $dirid = $this->get_dir_ilm('dirid');
  7032. $dir_base = $this->get_dir_ilm('dir_base');
  7033. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  7034. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  7035. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  7036. $files_array = '';
  7037. foreach ($files_course as $value) {
  7038. if (!$value->is_directory())
  7039. $files_array .= "'" . $value->get_filename() . "',";
  7040. }
  7041. $files_array .= "''";
  7042. $error_files_exists = get_string('error_file_exists', 'iassign');
  7043. $dirs_array = '';
  7044. foreach ($files_course as $value) {
  7045. if ($value->is_directory()) {
  7046. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  7047. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  7048. }
  7049. }
  7050. $dirs_array .= "''";
  7051. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  7052. //TODO: Rever o 'preview', pois so' apresenta uma vez!
  7053. $code_javascript_ilm = "
  7054. <script type='text/javascript'>
  7055. //<![CDATA[
  7056. function preview_ilm (fileid, ilmid) {
  7057. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  7058. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  7059. }
  7060. function update_ilm (ilmid, fileid) {
  7061. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7062. }
  7063. function delete_ilm (ilmid, fileid) {
  7064. var msgAnswer;
  7065. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  7066. if (msgAnswer) {
  7067. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7068. }
  7069. }
  7070. function delete_selected_ilm () {
  7071. var msgAnswer;
  7072. var param = getCheckbox();
  7073. if (param.join() != '') {
  7074. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  7075. if (msgAnswer)
  7076. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  7077. }
  7078. else
  7079. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  7080. }
  7081. function add_ilm_iassign (ilmid, filename, fileid) {
  7082. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  7083. }
  7084. function duplicate_ilm (ilmid, filename, fileid) {
  7085. var filenamecopy;
  7086. var i;
  7087. var files = new Array($files_array);
  7088. do {
  7089. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  7090. } while (filenamecopy == '');
  7091. if (filenamecopy == null)
  7092. return false;\n
  7093. else {
  7094. for (i=0;i<files.length;i++) {
  7095. if (files[i]==filenamecopy) {
  7096. alert('$error_files_exists');
  7097. return false;\n
  7098. }
  7099. }\n" .
  7100. // @see: function 'duplicate_file_ilm()' above
  7101. "
  7102. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  7103. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  7104. } // else
  7105. }
  7106. function rename_ilm (ilmid, filename, fileid) {
  7107. var filenamecopy;
  7108. var i;
  7109. var files = new Array($files_array);
  7110. do {
  7111. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  7112. } while (filenamecopy == '');
  7113. if (filenamecopy == null)
  7114. return false;
  7115. else {
  7116. for (i=0;i<files.length;i++) {
  7117. if (files[i]==filenamecopy) {
  7118. alert('$error_files_exists');
  7119. return false;
  7120. }
  7121. }
  7122. 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;
  7123. }
  7124. }
  7125. function export_files_ilm () {
  7126. var param = getCheckbox();
  7127. if (param.join() != '')
  7128. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  7129. else
  7130. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  7131. }
  7132. function select_all_ilm () {
  7133. var checkBoxes = document.getElementsByTagName('input');
  7134. var selectAll = document.getElementById('select_all');
  7135. for (var counter=0; counter < checkBoxes.length; counter++) {
  7136. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  7137. checkBoxes[counter].checked = selectAll.checked;
  7138. }
  7139. }
  7140. function getCheckbox () {
  7141. var checkBoxes = document.getElementsByTagName('input');
  7142. var param = new Array();
  7143. for (var counter=0; counter < checkBoxes.length; counter++) {
  7144. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  7145. param.push(checkBoxes[counter].value);
  7146. }
  7147. return param;
  7148. }
  7149. function new_dir_ilm () {
  7150. var dirname = '';
  7151. var i;
  7152. var dirs = new Array($dirs_array);
  7153. do {
  7154. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  7155. } while (dirname == '');
  7156. if (dirname == null)
  7157. return false;\n
  7158. else {
  7159. for (i=0;i<dirs.length;i++) {
  7160. if (dirs[i]==dirname) {
  7161. alert('$error_dir_exists');
  7162. return false;\n
  7163. }
  7164. }
  7165. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  7166. }
  7167. }
  7168. function delete_dir_ilm (ilmid, dirid) {
  7169. var msgAnswer;
  7170. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7171. if (msgAnswer) {
  7172. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7173. }
  7174. }
  7175. function rename_dir_ilm (ilmid, dirname, dirid) {
  7176. var dirnamecopy;
  7177. var i;
  7178. var dirs = new Array($dirs_array);
  7179. do {
  7180. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7181. } while (dirnamecopy == '');
  7182. if (dirnamecopy == null)
  7183. return false;\n
  7184. else {
  7185. for (i=0;i<dirs.length;i++) {
  7186. if (dirs[i]==dirnamecopy) {
  7187. alert('$error_dir_exists');
  7188. return false;\n
  7189. }
  7190. }
  7191. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7192. }
  7193. }
  7194. function move_selected_ilm (ilmid) {
  7195. var param = getCheckbox();
  7196. if (param.join() != '')
  7197. 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();
  7198. else
  7199. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7200. }
  7201. function recover_files_ilm () {
  7202. var msgAnswer;
  7203. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7204. if (msgAnswer) {
  7205. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7206. }
  7207. }
  7208. window.onload = function() {
  7209. var xPosition = 0;
  7210. var yPosition = 0;
  7211. element=document.getElementById('new_file');
  7212. while(element) {
  7213. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7214. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7215. element = element.offsetParent;
  7216. }
  7217. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7218. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7219. location.hash = '#new_file';
  7220. };
  7221. //]]>
  7222. </script>\n";
  7223. $output = "";
  7224. $select_all = "";
  7225. $count_files = 0;
  7226. $extensions_allow = array();
  7227. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  7228. foreach ($iassign_ilm as $item_iassign_ilm)
  7229. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  7230. foreach ($files_course as $value) {
  7231. $filename = $value->get_filename();
  7232. $filepath = $value->get_filepath();
  7233. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  7234. $pathname = $pathname[count($pathname) - 1];
  7235. $fileid = $value->get_id();
  7236. $tmp = explode(".", $filename);
  7237. if (count($tmp)>1) // avoid error if the file has no extension
  7238. $filetype = $tmp[1];
  7239. else // probably error...
  7240. $filetype = '';
  7241. $author = $value->get_author();
  7242. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  7243. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  7244. $extensions = explode(",", $extension);
  7245. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  7246. $count_files++;
  7247. // buscar fileid nas tabelas do iassign
  7248. $list_filein_use = "";
  7249. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  7250. if ($iassign_statement_activity_list) {
  7251. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  7252. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  7253. }
  7254. }
  7255. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  7256. if (!$iassign_ilm) {
  7257. $iassign_ilm = new stdClass();
  7258. $iassign_ilm->id = $ilmid;
  7259. }
  7260. // Do not use $var inside "..." - problem with some "unusual" operational system
  7261. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  7262. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  7263. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  7264. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  7265. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7266. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7267. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7268. $check_select = "";
  7269. $link_rename = "";
  7270. $link_delete = "";
  7271. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7272. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7273. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7274. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  7275. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7276. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7277. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7278. if ($value->get_userid() == $USER->id) {
  7279. if ($iassign_statement_activity_list) {
  7280. $check_select = "";
  7281. $link_edit = iassign_icons::insert('edit_iassign_disable');
  7282. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  7283. $link_rename = "";
  7284. } else {
  7285. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  7286. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  7287. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  7288. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  7289. }
  7290. }
  7291. if (!in_array($filetype, $extensions_allow)) {
  7292. $link_edit = "";
  7293. $link_add_ilm_iassign = "";
  7294. $link_add_ilm_tinymce = "";
  7295. $link_add_ilm_atto = "";
  7296. $link_filter = "";
  7297. }
  7298. if ($value->is_directory()) {
  7299. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  7300. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  7301. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  7302. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  7303. <td><center>$author</center></td>
  7304. <td><center>$timecreated</center></td>
  7305. <td><center>$timemodified</center></td></tr>\n";
  7306. }
  7307. else if ($this->from == 'iassign') {
  7308. $new_id = "";
  7309. $new_class = "";
  7310. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  7311. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  7312. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  7313. }
  7314. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  7315. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7316. <td><center>$author</center></td>
  7317. <td><center>$timecreated</center></td>
  7318. <td><center>$timemodified</center></td></tr>\n";
  7319. }
  7320. else if ($this->from == 'block') {
  7321. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  7322. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7323. <td><center>$author</center></td>
  7324. <td><center>$timecreated</center></td>
  7325. <td><center>$timemodified</center></td></tr>\n";
  7326. }
  7327. else if ($this->from == 'tinymce') {
  7328. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  7329. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7330. <td><center>$author</center></td>
  7331. <td><center>$timecreated</center></td>
  7332. <td><center>$timemodified</center></td></tr>\n";
  7333. }
  7334. else if ($this->from == 'atto') {
  7335. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  7336. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7337. <td><center>$author</center></td>
  7338. <td><center>$timecreated</center></td>
  7339. <td><center>$timemodified</center></td></tr>\n";
  7340. }
  7341. }
  7342. }
  7343. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  7344. $dir_base = "";
  7345. $header = "";
  7346. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  7347. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  7348. foreach ($basename as $value) {
  7349. $dir_base .= $value . "/";
  7350. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  7351. if ($dir_id) {
  7352. if ($value == "") {
  7353. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7354. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  7355. } else {
  7356. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7357. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  7358. }
  7359. }
  7360. } // foreach ($basename as $value)
  7361. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  7362. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  7363. $html .= "
  7364. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  7365. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  7366. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  7367. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  7368. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  7369. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  7370. </table>\n";
  7371. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  7372. $html .= "<table width='100%'><tr>\n";
  7373. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  7374. if ($count_files != 0) {
  7375. $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";
  7376. $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";
  7377. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  7378. }
  7379. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  7380. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  7381. $html .= "</form>\n";
  7382. print $code_javascript_ilm;
  7383. print $html;
  7384. } // function view_files_ilm($extension)
  7385. } // class ilm_manager
  7386. /// Class to insert of icons
  7387. class iassign_icons {
  7388. static function insert ($icon) {
  7389. global $CFG;
  7390. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  7391. return $string;
  7392. }
  7393. }
  7394. /// Class with util functions for plugin manage
  7395. class iassign_utils {
  7396. /// Function to return the filename extension
  7397. // @param string The $filename as an string
  7398. // @return string Return an string (last group after '.')
  7399. static function filename_extension ($filename) {
  7400. if ($filename == null || $filename == '') {
  7401. return null;
  7402. }
  7403. $itens = explode('.', $filename);
  7404. $num = count($itens);
  7405. if ($num < 2) {
  7406. return null;
  7407. }
  7408. return $itens[$num - 1];
  7409. }
  7410. /// Use the PHP class/package ZipArchive to create a Zip file
  7411. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  7412. // 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
  7413. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  7414. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  7415. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7416. $zip = new zip_archive(); //2
  7417. $res = $zip->open($full_path_zip_filename);
  7418. $total_vet = count($vet_student_filename);
  7419. for ($ii=0; $ii<$total_vet; $ii++) {
  7420. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7421. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7422. }
  7423. $ret = $zip->close();
  7424. iassign_utils::download_file($full_path_zip_filename);
  7425. $filenameZip = $zip->filename;
  7426. return array($ret, $zip);
  7427. }
  7428. static function download_file ($zip_filename) {
  7429. header("Pragma: public");
  7430. header("Expires: 0");
  7431. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7432. header("Cache-Control: private", false);
  7433. header("Content-Type: application/zip");
  7434. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7435. header("Content-Transfer-Encoding: binary");
  7436. header("Content-Length: " . @filesize($zip_filename));
  7437. set_time_limit(0);
  7438. @readfile("$zip_filename") || die("File not found.");
  7439. unlink($zip_filename);
  7440. }
  7441. /// Function for format filename remove special caracters
  7442. // @param string $text String for clean
  7443. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7444. // @return string Return an string in clean format
  7445. static function format_filename ($text) {
  7446. if ($text != '.') {
  7447. //D $text = htmlspecialchars(urldecode($text));
  7448. //D echo "locallib.php: format_filename: $text<br/>";
  7449. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7450. $text = json_decode($text)->{current_language()};
  7451. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7452. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7453. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7454. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7455. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7456. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7457. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7458. // E.g. text = "exerc_midpoint.course.geo"
  7459. // 0123456789012345678901234
  7460. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7461. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7462. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7463. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7464. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7465. //$ext = strrpos($text, ".");
  7466. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7467. //$text = str_replace($array1, $array2, $text);
  7468. }
  7469. return $text;
  7470. }
  7471. /// Function to filter characters to the file name to iLM content
  7472. // @param string $text String for clean
  7473. // @param string $ext String ot the extension of the iLM
  7474. // @return string Return an string in clean format
  7475. static function filter_filename_extension ($filename, $ext) {
  7476. if ($filename != '.') {
  7477. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7478. $arrTo = array("_","","","","","","","","","","","","");
  7479. $filename = str_replace($arrFrom, $arrTo, $filename);
  7480. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7481. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7482. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7483. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7484. $index_lastposition = strlen($filenameF);
  7485. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7486. $text = str_replace(".", "_", $text); // erase all other "."
  7487. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7488. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7489. }
  7490. else
  7491. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7492. return $filenameF;
  7493. }
  7494. /// Function for format pathname remove special caracters
  7495. // @param string $text String for clean
  7496. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7497. // @return string Return an string in clean format
  7498. static function format_pathname ($text, $is_lowercase = true) {
  7499. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7500. $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", "-", "_", "", "", "");
  7501. $text = str_replace($array1, $array2, $text);
  7502. if ($is_lowercase)
  7503. $text = strtolower($text);
  7504. return $text;
  7505. }
  7506. /// Function for format file name from iLM original name
  7507. // @param string $text String to build the file neam
  7508. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7509. // @return string Return an string in clean format
  7510. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7511. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7512. $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", "-", "_", "", "", "");
  7513. $index_firstposition_blank = strpos($ilm_name, " ");
  7514. if ($index_firstposition_blank) { // truncate the name!
  7515. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7516. }
  7517. $index_firstposition_dots = strpos($ilm_name, ":");
  7518. if ($index_firstposition_dots) { // truncate the name!
  7519. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7520. }
  7521. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7522. if ($is_lowercase)
  7523. $namefiltered = strtolower($namefiltered);
  7524. return $namefiltered;
  7525. }
  7526. /// Function for insert version in the filename
  7527. // @param string $filename Name of file
  7528. // @return string Return the filename with version
  7529. static function version_filename ($filename) {
  7530. $array_filename = explode('.', $filename);
  7531. if (count($array_filename) > 1)
  7532. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7533. else
  7534. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7535. return $filename;
  7536. }
  7537. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7538. static function remove_code_message ($string) {
  7539. $array = explode("&lt;ia_uc&gt;", $string);
  7540. return $array[0];
  7541. }
  7542. }
  7543. // class iassign_utils
  7544. /// Class with language functions for plugin manage
  7545. class iassign_language {
  7546. /// Function for return text in language or get default language (en)
  7547. // @param string $lang Code of language
  7548. // @param string $description JSON text content all languages
  7549. // @return string Return an string in the language selected
  7550. static function get_description_lang ($lang, $descriptions) {
  7551. $description_lang = "";
  7552. $description = json_decode($descriptions);
  7553. if ($description == null) {
  7554. $description_lang = $descriptions;
  7555. }
  7556. else {
  7557. if (isset($description->{$lang}))
  7558. $description_lang = $description->{$lang};
  7559. else
  7560. if (isset($description->en)) //MOOC2014
  7561. $description_lang = $description->en;
  7562. else //MOOC2014
  7563. $description_lang = "en"; //MOOC2014
  7564. }
  7565. return $description_lang;
  7566. }
  7567. /// Function for return all language supported by iLM
  7568. // @param string $descriptions JSON text content all languages
  7569. // @return string Return as string with all languages
  7570. static function get_all_lang ($descriptions) {
  7571. $langs = "";
  7572. $description = json_decode($descriptions);
  7573. if ($description) {
  7574. foreach ($description as $key => $value) {
  7575. $langs .= $key . " ; ";
  7576. }
  7577. $langs = substr($langs, 0, strlen($langs) - 3);
  7578. }
  7579. return $langs;
  7580. }
  7581. /// Function for convert json in xml //MOOC2014
  7582. // @param string $json JSON text
  7583. // @return string Return as string with xml tags
  7584. static function json_to_xml ($json) {
  7585. $xml = "";
  7586. $json = json_decode($json);
  7587. foreach ($json as $key => $value) {
  7588. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7589. }
  7590. return $xml;
  7591. }
  7592. }
  7593. // class iassign_language
  7594. /// Class with log functions for plugin manage.
  7595. class iassign_log {
  7596. /// Function for insert log event
  7597. // @param string $action Code action of event
  7598. // @param string $information Text for describe action of event
  7599. // @param int $cmid Id of context module
  7600. // @param int $ilmid Id of iLM
  7601. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7602. global $COURSE, $CFG, $USER, $DB;
  7603. $newentry = new stdClass();
  7604. $newentry->time = time();
  7605. $newentry->userid = $USER->id;
  7606. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7607. $newentry->course = $COURSE->id;
  7608. $newentry->cmid = $cmid;
  7609. $newentry->ilmid = $ilmid;
  7610. $newentry->action = $action;
  7611. $newentry->info = $information;
  7612. $newentry->language = current_language();
  7613. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7614. if (ini_get("browscap") && function_exists('get_browse')) {
  7615. $browser = get_browse(null, true);
  7616. $newentry->javascript = $browser['javascript'];
  7617. $newentry->java = $browser['javaapplets'];
  7618. }
  7619. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7620. print_error('error_add_log', 'iassign');
  7621. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7622. } // class iassign_log