locallib.php 364 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.4 2020/05/28
  7. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  8. *
  9. * - v 4.9.3 2020/01/16
  10. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  11. *
  12. * - v 4.9.2 2019/03/13
  13. * + Several fixes to allow iLM under HTML stack
  14. *
  15. * - v 4.9.1 2017/11/02
  16. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  17. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  18. *
  19. * - v 4.9 2017/03/13
  20. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  21. *
  22. * - v 4.8 2016/05/12
  23. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  24. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  25. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  26. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  27. * replaced by
  28. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  29. * - v 4.7 2016/02/17
  30. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  31. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  32. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  33. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  34. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  35. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  36. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  37. *
  38. * --------------- (code bellow was used at our MOOC 2014)
  39. * - v 4.6 2014/02/25
  40. * + Fix bugs in filter function for open applets.
  41. * - v 4.5 2014/02/24
  42. * + Fix bugs in params.
  43. * + Insert new param type.
  44. * - v 4.4 2014/01/24
  45. * + Allow select type of params.
  46. * + Insert the use of applet params specific for activities.
  47. * - v 4.3 2014/01/23
  48. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  49. * - v 4.2 2016/02/13
  50. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  51. * --------------- (above code used at our MOOC 2014)
  52. *
  53. * - v 4.1 2013/12/13
  54. * + Insert log in iAssign actions.
  55. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  56. * + Insert class for Log actions in system.
  57. * - v 4.0 2013/10/31
  58. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  59. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  60. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  61. * - v 3.9 2013/10/25
  62. * + Insert support of upgrade iLM.
  63. * + Insert support for more than one extension in iLM.
  64. * + Fix bugs in verion control.
  65. * - v 3.8 2013/09/19
  66. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  67. * - v 3.7 2013/09/12
  68. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  69. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  70. * - v 3.6 2013/09/05
  71. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  72. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  73. * + Change tag APPLET in function ilm_settings::view_ilm.
  74. * - v 3.5 2013/08/26
  75. * + Fix bug in download package iassign without answers (iassign::report).
  76. * - v 3.4 2013/08/23
  77. * + Fix bug in export package iassign.
  78. * - v 3.3 2013/08/22
  79. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  80. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  81. * - v 3.2 2013/08/21
  82. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  83. * + Change functions for import files for ilm_manager.php.
  84. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  85. * - v 3.1 2013/08/15
  86. * + Change return file selected (ilm_manager::add_ilm).
  87. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  88. * - v 3.0 2013/08/02
  89. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  90. * - v 2.9 2013/08/01
  91. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  92. * - v 2.8 2013/07/25
  93. * + Insert the activity name in header of view (activity::view_dates).
  94. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  95. * - v 2.7 2013/07/24
  96. * + Create link previous and next for student view in one activity (activity::view_dates).
  97. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  98. * - v 2.6 2013/07/23
  99. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  100. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  101. * - v 2.5 2013/07/12
  102. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  103. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  104. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  105. *
  106. * @author Patricia Alves Rodrigues
  107. * @author Leônidas O. Brandão
  108. * @contributor Igor Moreira Félix (2018-)
  109. * @contributor Márcio de Lima Passos (2014)
  110. * @version v 4.9.2 2019/03/13
  111. * @version v 4.8 2016/05/12
  112. * @package mod_iassign_lib
  113. * @since 2010/09/27
  114. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  115. *
  116. * <b>License</b>
  117. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  118. */
  119. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  120. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  121. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  122. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  123. /**
  124. * Standard base class for all iAssign
  125. */
  126. class iassign {
  127. var $cm;
  128. var $course;
  129. var $iassign;
  130. var $striassign;
  131. var $striassigns;
  132. var $context;
  133. var $activity;
  134. var $iassign_up;
  135. var $iassign_down;
  136. var $action;
  137. var $iassign_submission_current;
  138. var $userid_iassign;
  139. var $bottonPost;
  140. var $write_solution;
  141. var $view_iassign;
  142. // 3.1 update PHP 7.0 compatibility for all moodle versions
  143. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  144. /// Constructor for the base iassign class
  145. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  146. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  147. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  148. function __construct ($iassign, $cm, $course) {
  149. global $COURSE, $CFG, $USER, $DB;
  150. $botton = optional_param('botton', NULL, PARAM_TEXT);
  151. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  152. if (!is_null($botton))
  153. $USER->iassignEdit = $botton;
  154. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  155. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  156. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  157. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  158. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  159. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  160. $this->action = optional_param('action', NULL, PARAM_TEXT);
  161. $this->cm = $cm;
  162. $this->context = context_module::instance($this->cm->id);
  163. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  164. $this->userid_iassign = $USER->id;
  165. if ($course) {
  166. $this->course = $course;
  167. }
  168. else if ($this->cm->course == $COURSE->id) {
  169. $this->course = $COURSE;
  170. }
  171. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  172. print_error('invalidid', 'iassign');
  173. }
  174. $this->coursecontext = context_course::instance($this->course->id);
  175. if ($iassign) {
  176. $this->iassign = $iassign;
  177. }
  178. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  179. print_error('invalidid', 'iassign');
  180. }
  181. $USER->context = context_module::instance($this->cm->id);
  182. $USER->cm = $this->cm->id;
  183. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  184. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  185. $this->context = context_module::instance($this->cm->id);
  186. $this->striassign = get_string('modulename', 'iassign');
  187. $this->striassigns = get_string('modulenameplural', 'iassign');
  188. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  189. $this->bottonPost = 0;
  190. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  191. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  192. $this->view();
  193. } // function __construct($iassign, $cm, $course)
  194. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  195. // This method provides the page to view each iLM with any interactive activity
  196. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  197. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  198. global $USER, $DB, $OUTPUT;
  199. // $iassign_statementid = $this->iassign->iassign_statementid;
  200. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  201. $iassign_statementid = $this->activity->get_activity()->id;
  202. else
  203. $iassign_statementid = "";
  204. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  205. // If this user has no capability to View 'iassign': stop here
  206. require_capability('mod/iassign:view', $this->context);
  207. // Trigger module view event
  208. $event = \mod_iassign\event\course_module_viewed::create(array(
  209. 'objectid' => $this->iassign->id,
  210. 'context' => $this->context
  211. ));
  212. $event->add_record_snapshot('course', $this->course);
  213. $event->trigger();
  214. if ($this->action) { // when student do/redo activity or teacher see student solution
  215. $this->action(); // calls '$this->view_iLM();'
  216. }
  217. else {
  218. print $OUTPUT->header();
  219. $this->view_iassigns(); // show the iLM with the content
  220. print $OUTPUT->footer();
  221. }
  222. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  223. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  226. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  229. //D else echo "Apagou!<br/>";
  230. die();
  231. } // function view()
  232. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  233. function action () {
  234. global $USER;
  235. // action:
  236. // up - move up activity (mover atividade para cima)
  237. // down - move down activity (mover atividade para baixo)
  238. // visible - view/hide activity (exibir/ocultar atividade)
  239. // delete - delete activity (excluir atividade)
  240. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  241. // deleteno - does not erase activity (não apaga atividade)
  242. // add - add activity (adicionar atividade)
  243. // edit - edit activity (modificar atividade)
  244. $action_iassign = array(
  245. 'newcomment' => '$this->add_comment();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();');
  253. $action_iassign_limit = array(
  254. 'view' => '$this->view_iassign_current();',
  255. //'newcomment' => '$this->get_answer();',
  256. 'viewsubmission' => '$this->view_iassign_current();',
  257. 'edit_status' => '$this->edit_status();',
  258. 'edit_grade' => '$this->edit_grade();',
  259. 'export_csv' => '$this->export_csv();',
  260. 'report' => '$this->report();',
  261. 'print' => '$this->report();',
  262. 'stats' => '$this->stats();',
  263. 'printstats' => '$this->stats();');
  264. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  265. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  266. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  267. 'visible' => '$this->activity->visible_iassign($this->return);',
  268. 'delete' => '$this->activity->delete($this->return);',
  269. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  270. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  271. 'add' => '$this->add_edit_iassign();',
  272. 'edit' => '$this->add_edit_iassign();',
  273. 'get_answer' => '$this->get_answer();',
  274. 'duplicate_activity' => '$this->duplicate_activity();',
  275. 'move_activity' => '$this->move_activity();',
  276. 'auto_evaluate' => '$this->auto_evaluate();',
  277. 'all_submissions' => '$this->all_submissions();',
  278. 'get_student_submission' => '$this->get_student_submission();',
  279. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  280. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  281. );
  282. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  283. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  284. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  285. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  286. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  287. }
  288. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  289. eval($action_iassign_limit[$this->action]);
  290. }
  291. else { // Student reaches this point
  292. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  293. // Arrive here with: "get_answer"; "view"
  294. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  295. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  296. }
  297. } // function action()
  298. /// This method prints the student submission to a specific exercise
  299. function get_student_submission () {
  300. global $DB;
  301. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  302. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  303. if (!$student || !$exercise) exit;
  304. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  305. if ($iassign_submission)
  306. print($iassign_submission->answer);
  307. die();
  308. }
  309. /// This method prints the teacher exercise
  310. function get_teacher_exercise () {
  311. global $DB, $COURSE;
  312. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  313. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  314. $fs = get_file_storage(); // Get reference to all files in Moodle data
  315. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  316. foreach ($files as $file) {
  317. if ($file->get_filename() != ".") {
  318. print($file->get_content());
  319. }
  320. }
  321. die();
  322. }
  323. /// This method receives the data from auto_eval event
  324. /// @see auto_evaluate()
  325. function post_auto_eval_result () {
  326. global $COURSE, $CFG, $USER, $DB;
  327. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  328. exit;
  329. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  330. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  331. $student = optional_param('student', -1, PARAM_INT);
  332. $grade = optional_param('grade', 0, PARAM_FLOAT);
  333. // 1: Recuperar a nota atual:
  334. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  335. // 2: Atualizar a tabela:
  336. $update_entry = new stdClass();
  337. $update_entry->id = $actual->id;
  338. $update_entry->previous_grade = $actual->grade;
  339. $update_entry->grade = $grade;
  340. // Update the iassign_submission
  341. $DB->update_record("iassign_submission", $update_entry);
  342. }
  343. /// Manage all submissions in exercises to table iassign_allsubmissions
  344. function all_submissions () {
  345. }
  346. /// This method runs activities auto evaluation in teacher area
  347. function auto_evaluate () {
  348. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  349. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  350. exit;
  351. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  352. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  353. // Get list of exercises in the instance:
  354. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  355. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  356. // Get list of enrolled students:
  357. $params = array('shortname' => 'student');
  358. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  359. $context = context_course::instance($this->course->id);
  360. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  361. $students_list = $DB->get_records_sql(
  362. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  363. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  364. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  365. print $OUTPUT->header();
  366. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  367. print '<ul style="list-style-type: none; margin: 1em;">';
  368. foreach ($exercises_list as $exercise) {
  369. $matches = [];
  370. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  371. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  372. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  373. if ($matches[0][0]) {
  374. 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>';
  375. } else {
  376. 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>';
  377. }
  378. } else {
  379. if ($matches[0][0]) {
  380. 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>';
  381. } else {
  382. 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>';
  383. }
  384. }
  385. }
  386. print '</ul>
  387. <center>
  388. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  389. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  390. <div id="evaluate_message" style="color: red"></div>
  391. <div id="evaluate_alerts"></div>
  392. <div>
  393. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  394. <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>
  395. </div>
  396. </center>'; // close "
  397. print ' </div>' + "\n";
  398. print ' <script>';
  399. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  400. print ' var submissions = [';
  401. // Get list of student id have submit for each exercise:
  402. foreach ($exercises_list as $exercise) {
  403. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  404. print '
  405. {
  406. "exerciseid": "' . $exercise->id . '",
  407. "grade": ' . $exercise->grade . ',
  408. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  409. "submited": ['; // "
  410. $params = array('iassign_statementid' => $exercise->id);
  411. $submited = $DB->get_records_sql( // Get userid and his grade
  412. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  413. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  414. foreach ($submited as $ss) {
  415. print($ss->userid . ',');
  416. }
  417. print '],';
  418. print '"allgrades": [';
  419. foreach ($submited as $ss) {
  420. print( $ss->grade . ',');
  421. }
  422. print ']
  423. },'; // close "
  424. } // foreach ($exercises_list as $exercise)
  425. print " ];\n";
  426. print '
  427. var total_submissions = 0;
  428. var selected_exercises;
  429. var count_steps;
  430. var value_by_step;
  431. var stoped = false;
  432. var time_interval = 5000;
  433. var var_interval;
  434. function add_hover_th (id_th, id_li) {
  435. $("#" + id_th).hover(function() {
  436. $("#" + id_li).css("background-color", "#d9d8d8");
  437. $(this).css("background-color", "#d9d8d8");
  438. }, function() {
  439. $("#" + id_li).css("background-color", "");
  440. $(this).css("background-color", "");
  441. });
  442. }
  443. function start_evaluation () {
  444. stoped = false;
  445. $("#progress_bar").css("display", "none");
  446. $("#evaluate_message").text("");
  447. $("#evaluate_alerts").text("");
  448. $(".added-col").remove();
  449. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  450. selected_exercises = [];
  451. var c = 0;
  452. for (var i = 0; i < exercises.length; i++) {
  453. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  454. selected_exercises[c++] = exercises[i];
  455. }
  456. }
  457. if (selected_exercises.length == 0) {
  458. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  459. return;
  460. } else {
  461. $("input:checkbox").attr("disabled", true);
  462. for (var i = 0; i < selected_exercises.length; i++) {
  463. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  464. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  465. $("#table-results tbody tr").each(function(e) {
  466. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  467. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  468. });
  469. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  470. }
  471. $("#button_start").prop("disabled", true);
  472. $("#button_stop").prop("disabled", false);
  473. $("#progress_bar").css("display", "block");
  474. }
  475. total_submissions = selected_exercises.length * students.length;
  476. count_steps = 0;
  477. value_by_step = 100/total_submissions;
  478. actual_exercise = 0;
  479. actual_student = 0;
  480. actual_submission = 0;
  481. get_original_propositions();
  482. var_interval = setInterval(verifyBreak, time_interval);
  483. } // function start_evaluation()
  484. var actual_exercise;
  485. var actual_student;
  486. var actual_submission;
  487. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  488. function run_individual_evaluation () {
  489. if (stoped) return;
  490. // Verify if student really sent his answer
  491. var found = false;
  492. for (var j = 0; j < submissions.length; j++) {
  493. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  494. for (var k = 0; k < submissions[j].submited.length; k++) {
  495. if (students[actual_student] == submissions[j].submited[k]) {
  496. found = true;
  497. break;
  498. }
  499. }
  500. break;
  501. }
  502. }
  503. if (found == false) {
  504. postResultAutoEval();
  505. } else {
  506. // If it was sent, search it...
  507. var final_url = "";
  508. 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];
  509. for (var j = 0; j < submissions.length; j++) {
  510. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  511. final_url = submissions[j].ilm;
  512. break;
  513. }
  514. }
  515. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  516. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  517. window.frames["ifrm"].location=final_url;
  518. }
  519. } // function run_individual_evaluation()
  520. var break_student = -1;
  521. var break_exercise = -1;
  522. function verifyBreak () {
  523. if (actual_student == break_student && actual_exercise == break_exercise) {
  524. postResultAutoEval(-6);
  525. break_student = -1;
  526. break_exercise = -1;
  527. return;
  528. } else {
  529. break_student = actual_student;
  530. break_exercise = actual_exercise;
  531. }
  532. }
  533. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  534. function getStudentAnswerURL () {
  535. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  536. }
  537. // This function is called by the iLM!!!
  538. function getAutoEvalOriginalData () {
  539. return original_propositions[actual_exercise];
  540. }
  541. function updateProgressBar () {
  542. if (stoped) return;
  543. var temp = (count_steps * value_by_step)|0;
  544. count_steps ++;
  545. temp = temp > 100 ? 100 : temp;
  546. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  547. if (temp >= 100) {
  548. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  549. $("#button_start").prop("disabled", false);
  550. $("#button_stop").prop("disabled", true);
  551. $("input:checkbox").attr("disabled", false);
  552. clearInterval(var_interval);
  553. }
  554. }
  555. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  556. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  557. function postResultAutoEval (grade = null) {
  558. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  559. if (grade == null) {
  560. $("#"+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>\');
  561. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  562. } else {
  563. // Verify if the re-evaluation grade is the of that one registered:
  564. var actual_value = 0;
  565. var actual_student_grade = 0;
  566. for (var k = 0; k < submissions.length; k++) {
  567. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  568. actual_value = submissions[k].grade;
  569. for (var h = 0; h < submissions[k].submited.length; h++) {
  570. if (submissions[k].submited[h] == students[actual_student]) {
  571. actual_student_grade = submissions[k].allgrades[h];
  572. break;
  573. }
  574. }
  575. break;
  576. }
  577. }
  578. // @FeedbackConvention
  579. if (grade < 0) {
  580. switch (grade) {
  581. case -1:
  582. // Test-cases are empty:
  583. $("#"+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>\');
  584. var mm = actual_exercise;
  585. $("#"+id_t).find(".details-button").click(function(e) {
  586. $(".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>\');
  587. });
  588. break;
  589. case -2:
  590. // Test-cases were manually altered by the student (fraud!):
  591. $("#"+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>\');
  592. var mm = actual_exercise;
  593. $("#"+id_t).find(".details-button").click(function(e) {
  594. $(".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>");
  595. });
  596. $.ajax({
  597. dataType: "html",
  598. 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",
  599. success: function(d) {}
  600. });
  601. break;
  602. case -5:
  603. // Execution failed:
  604. $("#"+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>\');
  605. var mm = actual_exercise;
  606. $("#"+id_t).find(".details-button").click(function(e) {
  607. $(".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>\');
  608. });
  609. break;
  610. case -6: // iLM not answering was detected in "verifyBreak()"
  611. // The iLM are not answering:
  612. $("#"+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>\');
  613. $("#"+id_t).find(".details-button").click(function(e) {
  614. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  615. });
  616. break;
  617. }
  618. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  619. } else {
  620. console.log((grade), (actual_student_grade));
  621. if ((grade) == (actual_student_grade)) {
  622. $("#"+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>\');
  623. } else { // Notas diferem:
  624. $("#"+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>\');
  625. var mm = actual_exercise;
  626. $("#"+id_t).find(".details-button").click(function(e) {
  627. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;">'.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>\');
  628. });
  629. // Send to the endpoint the post_auto_eval_result to verify:
  630. $.ajax({
  631. dataType: "html",
  632. 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),
  633. success: function(d) {}
  634. });
  635. }
  636. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  637. }
  638. }
  639. updateProgressBar();
  640. // Does it must continue in the same exercise or stop?
  641. if (actual_student < students.length) {
  642. actual_student ++;
  643. run_individual_evaluation();
  644. } else {
  645. actual_student = 0;
  646. // Does it go to next exercise or is it finished?
  647. if (actual_exercise < selected_exercises.length) {
  648. actual_exercise++;
  649. run_individual_evaluation();
  650. } else {
  651. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  652. }
  653. }
  654. }
  655. var original_propositions;
  656. function get_original_propositions () {
  657. original_propositions = [];
  658. var count = 0;
  659. for (var i = 0; i < exercises.length; i++) {
  660. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  661. $.ajax({
  662. dataType: "html",
  663. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  664. success: function(d) { // variable "d" has the iLM content
  665. original_propositions[count] = d; // exercise original content
  666. count ++;
  667. if (count == selected_exercises.length) {
  668. run_individual_evaluation();
  669. }
  670. }
  671. });
  672. }
  673. }
  674. }
  675. function stop_evaluation () {
  676. stoped = true;
  677. $("#button_start").prop("disabled", false);
  678. $("#button_stop").prop("disabled", true);
  679. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  680. $("input:checkbox").attr("disabled", false);
  681. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  682. clearInterval(var_interval);
  683. }
  684. var exercises = [ '; // '
  685. foreach ($exercises_list as $exercise) {
  686. print $exercise->id . ',';
  687. }
  688. print ' ];';
  689. print ' var students = [ ';
  690. foreach ($students_list as $student) {
  691. print $student->userid . ',';
  692. }
  693. print '];';
  694. print ' var ilms = [';
  695. foreach ($exercises_list as $exercise) {
  696. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  697. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  698. }
  699. print ']';
  700. print '</script>';
  701. print '
  702. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  703. <div class="modal-dialog modal-dialog-centered" role="document">
  704. <div class="modal-content">
  705. <div class="modal-header">
  706. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  707. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  708. <span aria-hidden="true">&times;</span>
  709. </button>
  710. </div>
  711. <div class="modal-body">
  712. ...
  713. </div>
  714. <div class="modal-footer">
  715. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  716. </div>
  717. </div>
  718. </div>
  719. </div>'; //
  720. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  721. print '<table id="table-results" class="table table-hover m-t-1">
  722. <thead>
  723. <tr id="cols-exercises">
  724. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  725. </tr>
  726. </thead>
  727. <tbody>'; // "
  728. foreach ($students_list as $student) {
  729. $user = $DB->get_record('user', array('id' => $student->userid));
  730. $avatar = new user_picture($user);
  731. $avatar->courseid = $COURSE->id;
  732. $avatar->link = true;
  733. print
  734. '<tr data-student="'.$student->userid.'">
  735. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  736. </tr>'; // "
  737. }
  738. print '</tbody>
  739. </table>'; // "
  740. print $OUTPUT->footer();
  741. } // function auto_evaluate()
  742. /// This method moves an iAssign activity
  743. function move_activity () {
  744. global $USER, $CFG, $DB, $COURSE;
  745. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  746. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  747. $update_entry_new_iassign = new stdClass();
  748. $update_entry_new_iassign->id = $iassign_id;
  749. $update_entry_new_iassign->iassignid = $iassign_destiny;
  750. // Update the iassign_statement
  751. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  752. // Update file context
  753. $c_i = context_module::instance($this->cm->id);
  754. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  755. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  756. $path_module = context_course::instance($COURSE->id);
  757. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  758. if ($context_file) {
  759. $id_context = $context_file->id;
  760. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  761. $fs = get_file_storage(); // Get reference to all files in Moodle data
  762. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  763. foreach ($files as $value) {
  764. if ($value->get_filename() != ".") {
  765. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  766. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  767. $updateentry = new stdClass();
  768. $updateentry->id = $iassign_id;
  769. $updateentry->file = $newfile->get_itemid();
  770. $DB->update_record("iassign_statement", $updateentry);
  771. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  772. break;
  773. }
  774. }
  775. }
  776. $this->return_home_course('moved_activity');
  777. exit;
  778. }
  779. /// This method duplicates an iAssign activity
  780. function duplicate_activity () {
  781. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  782. $id = $this->cm->id;
  783. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  784. $context = context_module::instance($this->cm->id);
  785. $contextuser = context_user::instance($USER->id);
  786. // Get the the iAssign acitivity to be duplicated
  787. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  788. // Remove the current id of activity
  789. $iassign_statement->id=0;
  790. // Get the information about current author, and add this information in author_modified field
  791. $author = $DB->get_record("user", array('id' => $USER->id));
  792. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  793. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  794. // Store the activity in the table
  795. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  796. // Duplicate activity file
  797. $fs = get_file_storage(); // Get reference to all files in Moodle data
  798. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  799. foreach ($files as $value) {
  800. if ($value->get_filename() != ".") {
  801. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  802. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  803. $updateentry = new stdClass();
  804. $updateentry->id = $id_;
  805. $updateentry->file = $newfile->get_itemid();
  806. // Update the duplicated iLM iAssign with new file id
  807. $DB->update_record("iassign_statement", $updateentry);
  808. }
  809. }
  810. }
  811. // log event --------------------------------------------------------------------------------------
  812. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  813. $this->return_home_course('duplicated_activity');
  814. exit;
  815. }
  816. // / This method gets the content from comment and register it
  817. function add_comment () {
  818. global $USER, $DB;
  819. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  820. $comment = false;
  821. if ($submission_comment)
  822. $comment = $this->write_comment_submission();
  823. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  824. if (!$id_submission) {
  825. $iassign_submission =
  826. $DB->get_record("iassign_submission",
  827. array(
  828. "iassign_statementid" => $this->activity->get_activity()->id,
  829. "userid" => $USER->id
  830. )
  831. );
  832. if ($iassign_submission) {
  833. $id_submission = $iassign_submission->id;
  834. }
  835. }
  836. echo $this->search_comment_submission($id_submission);
  837. }
  838. /// This method gets the content from the iLM and register it
  839. // It could be the "exercise template" (teacher) or an answer (student)
  840. function get_answer () {
  841. global $USER, $CFG, $DB, $OUTPUT;
  842. $id = $this->cm->id;
  843. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  844. $comment = false;
  845. if ($submission_comment)
  846. $comment = $this->write_comment_submission();
  847. // receives data of iLM using the current activity
  848. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  849. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  850. // receives data of submission of current activity
  851. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  852. // receives post and get
  853. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  854. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  855. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  856. $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)
  857. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  858. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  859. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  860. $msg = '';
  861. if ($this->activity->get_activity()->store_all_submissions == 1) {
  862. $newentry = new stdClass();
  863. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  864. $newentry->userid = $this->userid_iassign;
  865. $newentry->timecreated = time();
  866. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  867. $newentry->answer = $iLM_PARAM_ArchiveContent;
  868. $DB->insert_record("iassign_allsubmissions", $newentry);
  869. }
  870. // Feedback
  871. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  872. $str_action = "view"; // repeat
  873. if (strtolower($iassign_ilm->name) == "igeom") {
  874. }
  875. $title = get_string('evaluate_iassign', 'iassign');
  876. print $OUTPUT->header();
  877. print $OUTPUT->box_start();
  878. // Action = { view ; repeat ; viewsubmission }
  879. // * '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")
  880. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  881. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  882. $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;
  883. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  884. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  885. print '<table width=100% >';
  886. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  887. //TODO alterar aqui???
  888. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  889. // empty_answer_post = No solution was posted.
  890. if ($comment)
  891. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  892. else
  893. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  894. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  895. } else {
  896. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  897. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  898. // Correct answer!!
  899. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  900. $this->write_solution = 1; //
  901. $status = 3;
  902. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  903. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  904. // log record
  905. $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;
  906. // Trigger module viewed event.
  907. $event = \mod_iassign\event\submission_created::create(array(
  908. 'objectid' => $this->iassign->id,
  909. 'context' => $this->context,
  910. 'other' => $info
  911. ));
  912. $event->add_record_snapshot('course', $this->course);
  913. $event->trigger();
  914. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  915. // Wrong answer...: get_answer_incorrect
  916. $status = 2;
  917. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  918. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  919. // log record
  920. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  921. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  922. // Trigger module viewed event.
  923. $event = \mod_iassign\event\submission_created::create(array(
  924. 'objectid' => $this->iassign->id,
  925. 'context' => $this->context,
  926. 'other' => $info
  927. ));
  928. $event->add_record_snapshot('course', $this->course);
  929. $event->trigger();
  930. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  931. // Presents to the learner the result of the automatic evaluate?
  932. if ($this->activity->get_activity()->show_answer == 0) { // no...
  933. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  934. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  935. print '<tr>';
  936. // log record
  937. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  938. // Trigger module viewed event.
  939. $event = \mod_iassign\event\submission_created::create(array(
  940. 'objectid' => $this->iassign->id,
  941. 'context' => $this->context,
  942. 'other' => $info
  943. ));
  944. $event->add_record_snapshot('course', $this->course);
  945. $event->trigger();
  946. } else { // yes!!!
  947. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  948. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  949. print '<tr>';
  950. print $msg;
  951. }
  952. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  953. $status = 1;
  954. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  955. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  956. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  957. print '<tr>';
  958. // log record
  959. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  960. $event = \mod_iassign\event\submission_created::create(array(
  961. 'objectid' => $this->iassign->id,
  962. 'context' => $this->context,
  963. 'other' => $info
  964. ));
  965. $event->add_record_snapshot('course', $this->course);
  966. $event->trigger();
  967. } // if ($iassign_ilm->evaluate == 1)
  968. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  969. print '</tr></table>';
  970. print $OUTPUT->box_end();
  971. // add or update evaluate
  972. if ($this->write_solution == 1) {
  973. $timenow = time();
  974. // new record
  975. if (!$iassign_submission) {
  976. $newentry = new stdClass();
  977. $newentry->userid = $this->userid_iassign;
  978. // $newentry->userid = $USER->id;
  979. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  980. $newentry->timecreated = $timenow;
  981. $newentry->timemodified = $timenow;
  982. $newentry->answer = $iLM_PARAM_ArchiveContent;
  983. $newentry->grade = round($grade_student, 2);
  984. $newentry->status = $status;
  985. $newentry->experiment = 1;
  986. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  987. print_error('error_insert', 'iassign');
  988. } else {
  989. // Trigger module viewed event.
  990. $event = \mod_iassign\event\submission_created::create(array(
  991. 'objectid' => $this->iassign->id,
  992. 'context' => $this->context
  993. ));
  994. $event->add_record_snapshot('course', $this->course);
  995. $event->trigger();
  996. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  997. }
  998. } elseif ($iassign_submission->status != 3) {
  999. $newentry = new stdClass();
  1000. $newentry->id = $iassign_submission->id;
  1001. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1002. $newentry->userid = $iassign_submission->userid;
  1003. $newentry->timecreated = $iassign_submission->timecreated;
  1004. $newentry->timemodified = $timenow;
  1005. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1006. $newentry->grade = round($grade_student, 2);
  1007. $newentry->status = $status;
  1008. $newentry->experiment = $iassign_submission->experiment + 1;
  1009. if (!$DB->update_record("iassign_submission", $newentry)) {
  1010. print_error('error_update', 'iassign');
  1011. //D depurar...
  1012. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1013. //D $fp = fopen("teste1.txt","w");
  1014. //D fwrite($fp,$stringAux);
  1015. } else {
  1016. // Trigger module viewed event.
  1017. $event = \mod_iassign\event\submission_updated::create(array(
  1018. 'objectid' => $this->iassign->id,
  1019. 'context' => $this->context
  1020. ));
  1021. $event->add_record_snapshot('course', $this->course);
  1022. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1023. }
  1024. } else {
  1025. if ($return_get_answer == 1) {
  1026. $newentry = new stdClass();
  1027. $newentry->id = $iassign_submission->id;
  1028. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1029. $newentry->userid = $iassign_submission->userid;
  1030. $newentry->timecreated = $iassign_submission->timecreated;
  1031. $newentry->timemodified = $timenow;
  1032. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1033. $newentry->grade = round($grade_student, 2);
  1034. $newentry->status = $status;
  1035. $newentry->experiment = $iassign_submission->experiment + 1;
  1036. if (!$DB->update_record("iassign_submission", $newentry))
  1037. print_error('error_update', 'iassign');
  1038. else {
  1039. $event = \mod_iassign\event\submission_updated::create(array(
  1040. 'objectid' => $this->iassign->id,
  1041. 'context' => $this->context
  1042. ));
  1043. $event->add_record_snapshot('course', $this->course);
  1044. $event->trigger();
  1045. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1046. print $OUTPUT->box_start();
  1047. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1048. print $OUTPUT->box_end();
  1049. }
  1050. } elseif ($return_get_answer == 2) {
  1051. print $OUTPUT->box_start();
  1052. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1053. print $OUTPUT->box_end();
  1054. } else {
  1055. print $OUTPUT->box_start();
  1056. print "
  1057. <script type='text/javascript'>
  1058. //<![CDATA[
  1059. function overwrite () {
  1060. document.formEnvio.return_get_answer.value = 1;
  1061. document.formEnvio.submit();
  1062. }
  1063. function nooverwrite () {
  1064. document.formEnvio.return_get_answer.value = 2;
  1065. document.formEnvio.submit();
  1066. }
  1067. //]]>
  1068. </script>";
  1069. $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;
  1070. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1071. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1072. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1073. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1074. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1075. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1076. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1077. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1078. <input type='hidden' name='return_get_answer'/> ";
  1079. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1080. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1081. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1082. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1083. print " </form>";
  1084. print $OUTPUT->box_end();
  1085. }
  1086. }
  1087. } // if ($this->write_solution == 1)
  1088. print $OUTPUT->footer();
  1089. die();
  1090. } // function get_answer()
  1091. /// Export in file the answer of student.
  1092. function export_file_answer () {
  1093. global $DB;
  1094. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1095. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1096. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1097. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1098. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1099. $extensions = explode(",", $iassign_ilm->extension);
  1100. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1101. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1102. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1103. header("Pragma: public");
  1104. header("Expires: 0");
  1105. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1106. header("Cache-Control: private", false);
  1107. header("Content-Type: document/unknown");
  1108. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1109. set_time_limit(0);
  1110. print($iassign_submission->answer);
  1111. exit;
  1112. } // function export_file_answer()
  1113. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1114. // @calledby $this->export_package_answer()
  1115. //TODO Precisa terminar! //TODO_HTML
  1116. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1117. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1118. <head>
  1119. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1120. $str_html .= " </head>
  1121. <body>\n";
  1122. $tam = sizeof($array_iassign_name);
  1123. for ($ii=0; $ii<$tam; $ii++) {
  1124. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1125. }
  1126. $str_html .= "
  1127. </body>\n</html>";
  1128. return $str_html;
  1129. }
  1130. /// Export an package (zip) with all answer of students
  1131. // @calledby $this->action()
  1132. function export_package_answer () {
  1133. global $DB, $CFG, $OUTPUT;
  1134. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1135. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1136. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1137. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1138. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1139. $userid = optional_param('userid', NULL, PARAM_INT);
  1140. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1141. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1142. //TODO_HTML echo "username=$username<br/>"; exit;
  1143. $current_date = date('Y_m_d_H');
  1144. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1145. // If temporary directory under Moodle data does not exists => create it
  1146. if (!is_dir($diretorio)) {
  1147. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1148. // created directory with permissions to be seen by everyone
  1149. }
  1150. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1151. if (!is_writable($diretorio)) { // send a highlighted message!
  1152. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1153. exit; // just in case
  1154. }
  1155. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1156. $zip = new zip_archive(); // create ZIP
  1157. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1158. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1159. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1160. $vet_student_filename = array();
  1161. $vet_student_content = array();
  1162. foreach ($iassign_statements as $iassign_statement) {
  1163. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1164. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1165. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1166. $extensions = explode(",", $iassign_ilm->extension);
  1167. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1168. if ($iassign_submission) {
  1169. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1170. $student_content = $iassign_submission->answer;
  1171. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1172. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1173. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1174. if ($resp) {
  1175. $vet_student_filename[] = $student_filename;
  1176. $vet_student_content[] = $student_content;
  1177. }
  1178. else { // send a highlighted message!
  1179. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1180. exit; // just in case
  1181. }
  1182. }
  1183. }
  1184. $zip->close(); // close the ZIP file
  1185. if (count($vet_student_filename)>0) {
  1186. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1187. $result_tf = $vet_result[0];
  1188. $filenameZip = $vet_result[1]->filename;
  1189. }
  1190. iassign_utils::download_file($zip_filename); // download the ZIP file
  1191. exit;
  1192. } // function export_package_answer()
  1193. /// Editing status of interactive activities
  1194. function edit_status () {
  1195. global $USER, $DB, $OUTPUT;
  1196. $newentry = new stdClass();
  1197. $newentry->id = $this->iassign_submission_current;
  1198. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1199. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1200. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1201. $newentry->status = $iassign_submission->status;
  1202. $newentry->teacher = $USER->id;
  1203. if (!$DB->update_record('iassign_submission', $newentry))
  1204. print_error('error_update', 'iassign');
  1205. else {
  1206. // Trigger module viewed event.
  1207. $event = \mod_iassign\event\submission_updated::create(array(
  1208. 'objectid' => $this->iassign->id,
  1209. 'context' => $this->context
  1210. ));
  1211. $event->add_record_snapshot('course', $this->course);
  1212. $event->trigger();
  1213. $this->action = 'viewsubmission';
  1214. $this->view_iassign_current();
  1215. } // if (!$DB->update_record('iassign_submission', $newentry))
  1216. } // function edit_status()
  1217. /// Editing grade of interactive activities
  1218. function edit_grade () {
  1219. global $USER, $DB, $OUTPUT;
  1220. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1221. if ($newgrade && $newgrade >= 0) {
  1222. $newentry = new stdClass();
  1223. $newentry->id = $this->iassign_submission_current;
  1224. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1225. $newentry->teacher = $USER->id;
  1226. if (!$DB->update_record('iassign_submission', $newentry))
  1227. print_error('error_update', 'iassign');
  1228. else {
  1229. // Trigger module viewed event.
  1230. $event = \mod_iassign\event\submission_updated::create(array(
  1231. 'objectid' => $this->iassign->id,
  1232. 'context' => $this->context
  1233. ));
  1234. $event->add_record_snapshot('course', $this->course);
  1235. $event->trigger();
  1236. }
  1237. } // if ($newgrade >= 0)
  1238. $this->action = 'viewsubmission';
  1239. $this->view_iassign_current();
  1240. }
  1241. /// Add or Edit interactive activities
  1242. // @calledby $this->action()
  1243. function add_edit_iassign () {
  1244. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1245. require_once('iassign_form.php');
  1246. $id = $this->cm->id;
  1247. $iassignid = $this->iassign->id;
  1248. $param = new stdClass();
  1249. $param->action = $this->action; // oculto
  1250. $param->id = $id; // oculto
  1251. $COURSE->cm = $id;
  1252. $COURSE->iassignid = $iassignid;
  1253. $COURSE->iassign_file_id = NULL;
  1254. $context = context_module::instance($this->cm->id);
  1255. $contextuser = context_user::instance($USER->id);
  1256. $component = 'mod_iassign';
  1257. $filearea = 'exercise';
  1258. if (!empty($this->iassign_current))
  1259. $COURSE->iassign_id = $this->iassign_current;
  1260. else
  1261. $COURSE->iassign_id = 0;
  1262. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1263. if ($this->action == 'add') {
  1264. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1265. $params = array('iassignid' => $iassignid);
  1266. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1267. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1268. $total_of_activities = count($iassign_statement);
  1269. $param->iassignid = $iassignid;
  1270. $param->name = "";
  1271. $param->oldname = "";
  1272. $param->type_iassign = 3;
  1273. $param->proposition = "";
  1274. $author = $DB->get_record("user", array("id" => $USER->id));
  1275. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1276. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1277. $param->author = $param->author_name;
  1278. $param->author_modified = $param->author_modified_name;
  1279. $COURSE->iassign_list = array();
  1280. $param->iassign_list = array();
  1281. if ($iassign_statement) {
  1282. foreach ($iassign_statement as $iassign) {
  1283. $iassignid = $iassign->id;
  1284. $param->iassign_list[$iassignid] = 0;
  1285. $COURSE->iassign_list[$iassignid] = new stdClass();
  1286. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1287. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1288. $COURSE->iassign_list[$iassignid]->enable = 1;
  1289. } // foreach ($iassign_statement as $iassign)
  1290. }
  1291. $param->iassign_ilmid = 0;
  1292. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1293. $param->file = 0;
  1294. $param->fileold = 0;
  1295. $param->filename = "";
  1296. $param->grade = $iassign_data->grade;
  1297. $param->timemodified = time();
  1298. $param->timecreated = time();
  1299. $param->timeavailable = $iassign_data->timeavailable;
  1300. $param->timedue = $iassign_data->timedue;
  1301. $param->preventlate = $iassign_data->preventlate;
  1302. $param->test = $iassign_data->test;
  1303. $param->special_param1 = 0;
  1304. $param->visible = 1;
  1305. $param->max_experiment = $iassign_data->max_experiment;
  1306. $param->dependency = 0;
  1307. $param->automatic_evaluate = 1;
  1308. $param->show_answer = 1;
  1309. } // if ($this->action == 'add')
  1310. elseif ($this->action == 'edit') {
  1311. $COURSE->iassign_list = array();
  1312. $this_activity = $this->activity->get_activity();
  1313. if ($this_activity != null) {
  1314. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1315. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1316. $param->iassign_id = $iassign_statement_current->id; // oculto
  1317. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1318. $param->name = $iassign_statement_current->name;
  1319. $param->oldname = $iassign_statement_current->name;
  1320. $param->type_iassign = $iassign_statement_current->type_iassign;
  1321. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1322. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1323. //2019 $param->proposition = $iassign_statement_current->proposition;
  1324. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1325. $param->author_name = $iassign_statement_current->author_name; // oculto
  1326. $param->author = $iassign_statement_current->author_name;
  1327. $author = $DB->get_record("user", array('id' => $USER->id));
  1328. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1329. $param->author_modified = $param->author_modified_name;
  1330. $dependency = explode(';', $iassign_statement_current->dependency);
  1331. $param->iassign_list = array();
  1332. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1333. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1334. $array_dependency = array();
  1335. $subdependency = "";
  1336. $sub_subdependency = "";
  1337. // dependent on this exercise
  1338. if ($iassign_statement_dependency) {
  1339. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1340. // to whom this exercise depends
  1341. foreach ($inter as $tmp)
  1342. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1343. $list_dependency = $subdependency . $sub_subdependency;
  1344. $array_dependency = explode(";", $list_dependency);
  1345. }
  1346. // Get all activity with the same iLM - iassignid
  1347. $str_query = "SELECT id, name FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' ORDER BY s.position ASC";
  1348. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1349. $total_of_activities = count($all_others_iassign_statement) + 1;
  1350. $inter = array();
  1351. if ($all_others_iassign_statement) {
  1352. foreach ($all_others_iassign_statement as $iassign)
  1353. if (in_array($iassign->id, $dependency))
  1354. $inter[] = $iassign->id;
  1355. }
  1356. if ($all_others_iassign_statement) {
  1357. foreach ($all_others_iassign_statement as $iassign) {
  1358. $iassignid = $iassign->id;
  1359. $COURSE->iassign_list[$iassignid] = new stdClass();
  1360. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1361. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1362. if (in_array($iassignid, $dependency))
  1363. $param->iassign_list[$iassignid] = 1;
  1364. else
  1365. $param->iassign_list[$iassignid] = 0;
  1366. if (in_array($iassignid, $array_dependency))
  1367. $COURSE->iassign_list[$iassignid]->enable = 0;
  1368. else
  1369. $COURSE->iassign_list[$iassignid]->enable = 1;
  1370. } // foreach ($all_others_iassign_statement as $iassign)
  1371. }
  1372. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1373. $param->fileold = 0;
  1374. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1375. $param->filename = '';
  1376. $param->grade = $iassign_statement_current->grade;
  1377. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1378. $param->timeavailable = $iassign_statement_current->timeavailable;
  1379. $param->timedue = $iassign_statement_current->timedue;
  1380. $param->preventlate = $iassign_statement_current->preventlate;
  1381. $param->test = $iassign_statement_current->test;
  1382. $param->special_param1 = $iassign_statement_current->special_param1;
  1383. $param->position = $iassign_statement_current->position; // oculto
  1384. $param->visible = $iassign_statement_current->visible;
  1385. $param->max_experiment = $iassign_statement_current->max_experiment;
  1386. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1387. $param->show_answer = $iassign_statement_current->show_answer;
  1388. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1389. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1390. if ($files) {
  1391. foreach ($files as $file) {
  1392. if ($file->get_filename() != '.') {
  1393. $param->filename = $file->get_filename();
  1394. $param->file = $file->get_id();
  1395. $param->fileold = $file->get_id();
  1396. $COURSE->iassign_file_id = $file->get_id();
  1397. }
  1398. }
  1399. }
  1400. //TODO //MOOC2014 -- inicio
  1401. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1402. //D if ($iassign_ilm_configs) {
  1403. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1404. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1405. //D } //MOOC2014 -- fim
  1406. } // if ($this_activity != null)
  1407. } // elseif ($this->action == 'edit')
  1408. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1409. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1410. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1411. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1412. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1413. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1414. $param->position = $total_of_activities;
  1415. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1416. $mform->set_data($param);
  1417. if ($mform->is_cancelled()) {
  1418. $this->return_home_course('iassign_cancel');
  1419. exit;
  1420. }
  1421. else { // if ($mform->is_cancelled())
  1422. $result = $mform->get_data();
  1423. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1424. if ($result) {
  1425. $result->context = $context;
  1426. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1427. $result->grade = 0;
  1428. if ($result->type_iassign == 1) {
  1429. $result->automatic_evaluate = 0;
  1430. $result->show_answer = 0;
  1431. }
  1432. elseif ($result->automatic_evaluate == 0)
  1433. $result->show_answer = 0;
  1434. // $_POST['iassign_list']
  1435. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1436. if ($result->iassign_list) {
  1437. foreach ($result->iassign_list as $key => $value)
  1438. $result->dependency .= $key . ';';
  1439. }
  1440. else
  1441. $result->dependency = 0;
  1442. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1443. //TODO Then get it directly from the form data $_POST!
  1444. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1445. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1446. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1447. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1448. if ($this->action == 'add') {
  1449. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1450. if ($iassign_statement_name) {
  1451. $this->return_home_course('error_iassign_name');
  1452. die();
  1453. }
  1454. // Really insert the new iActivity in table '*_iassign_statement'
  1455. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1456. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1457. // Trigger module viewed event.
  1458. $event = \mod_iassign\event\iassign_created::create(array(
  1459. 'objectid' => $iassignid,
  1460. 'context' => $context
  1461. ));
  1462. $event->add_record_snapshot('course', $this->course);
  1463. $event->trigger();
  1464. $this->return_home_course('iassign_add');
  1465. } // if ($this->action == 'add')
  1466. elseif ($this->action == 'edit') {
  1467. $iassignid = $this->activity->update_iassign($result);
  1468. $this->activity->update_calendar($iassignid, $result->oldname);
  1469. // Trigger module viewed event.
  1470. $event = \mod_iassign\event\iassign_updated::create(array(
  1471. 'objectid' => $iassignid,
  1472. 'context' => $context
  1473. ));
  1474. $event->add_record_snapshot('course', $this->course);
  1475. $event->trigger();
  1476. $this->return_home_course('iassign_update');
  1477. } // elseif ($this->action == 'edit')
  1478. die();
  1479. } // if ($result)
  1480. } // else if ($mform->is_cancelled())
  1481. print $OUTPUT->header();
  1482. $mform->display();
  1483. print $OUTPUT->footer();
  1484. die();
  1485. } // function add_edit_iassign()
  1486. /// Search for dependencies
  1487. function search_dependency ($search_iassing_id, $iassign_statement) {
  1488. global $DB, $OUTPUT;
  1489. $dependency = "";
  1490. if ($iassign_statement)
  1491. foreach ($iassign_statement as $iassign) {
  1492. $inter_dependency = explode(';', $iassign->dependency);
  1493. if (in_array($search_iassing_id, $inter_dependency)) {
  1494. $dependency .= $iassign->id . ";";
  1495. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1496. } // if (in_array($search_iassing_id, $inter_dependency))
  1497. } // foreach ($iassign_statement as $iassign)
  1498. return $dependency;
  1499. }
  1500. /// Search for "sub"dependency
  1501. function search_sub_dependency ($search_iassing_id) {
  1502. global $DB, $OUTPUT;
  1503. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1504. $dependency = "";
  1505. if ($iassign_statement) {
  1506. $inter_dependency = explode(';', $iassign_statement->dependency);
  1507. foreach ($inter_dependency as $tmp) {
  1508. if ($tmp != 0)
  1509. $dependency .= $tmp . ";";
  1510. $dependency .= $this->search_sub_dependency($tmp);
  1511. } // foreach ($inter_dependency as $tmp)
  1512. } // if ($iassign_statement)
  1513. return $dependency;
  1514. }
  1515. // Warning message
  1516. static function warning_message_iassign ($strcode) {
  1517. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1518. }
  1519. /// Update grade of iAssign
  1520. // Called always any iAssign activity is created
  1521. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1522. static function update_grade_iassign ($iassignid) {
  1523. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1524. require_once($CFG->libdir . '/gradelib.php');
  1525. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1526. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1527. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1528. // Each iAssign item is associated with one item on the "gradebook"
  1529. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1530. //$sum_grade = 0;
  1531. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1532. //foreach($grade as $tmp) {
  1533. // $sum_grade += $tmp->grade;
  1534. // }
  1535. //1 Solution 1
  1536. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1537. //1 $sum_grade = 0; //1
  1538. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1539. //2 Solution 2
  1540. $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
  1541. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1542. if (key($array_sum_grade))
  1543. $sum_grade = key($array_sum_grade); //2
  1544. else
  1545. $sum_grade = 0; //2
  1546. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1547. $grades = NULL;
  1548. $params = array('itemname' => $grade_iassign->name);
  1549. $params['iteminstance'] = $iassignid;
  1550. $params['gradetype'] = GRADE_TYPE_VALUE;
  1551. //2016 if ($sum_grade != 0) {
  1552. $params['grademax'] = $sum_grade;
  1553. $params['rawgrademax'] = $sum_grade;
  1554. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1555. $params['grademin'] = 0;
  1556. // @calls /lib/gradelib.php: call to grade_item->insert()
  1557. //TODO: is there any error here in Moodle version 3.0?
  1558. //TODO: Incorrect property 'grademax' found when inserting grade object
  1559. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1560. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1561. }
  1562. /// Update grade of student
  1563. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1564. global $CFG, $DB, $OUTPUT;
  1565. require_once($CFG->libdir . '/gradelib.php');
  1566. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1567. // Review all the student submission for this iAssign activity
  1568. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1569. $total_grade = 0;
  1570. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1571. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1572. if ($iassign_submission)
  1573. $total_grade += $iassign_submission->grade;
  1574. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1575. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1576. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1577. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1578. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1579. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1580. $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
  1581. if (key($array_sum_grade))
  1582. $sum_grade = key($array_sum_grade); //2
  1583. else
  1584. $sum_grade = 0; //2
  1585. $grades['userid'] = $userid;
  1586. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1587. $params = array('itemname' => $grade_iassign->name);
  1588. $params['iteminstance'] = $iassignid;
  1589. $params['gradetype'] = GRADE_TYPE_VALUE;
  1590. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1591. $params['grademax'] = $sum_grade;
  1592. $params['rawgrademax'] = $sum_grade;
  1593. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1594. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1595. }
  1596. /// Display caption of icons
  1597. function view_legend_icons () {
  1598. global $USER, $CFG, $DB, $OUTPUT;
  1599. $id = $this->cm->id;
  1600. if ($this->action == 'print')
  1601. print '<table border=1 width=100%><tr>';
  1602. else
  1603. print '<table width=100%><tr>';
  1604. print '<td >';
  1605. if ($this->action != 'print')
  1606. print $OUTPUT->help_icon('legend', 'iassign');
  1607. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1608. // $imagetext = '');
  1609. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1610. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1611. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1612. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1613. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1614. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1615. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1616. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1617. print '</td>' . "\n";
  1618. if ($this->action != 'print') {
  1619. $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>";
  1620. $link_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=stats&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('results') . '&nbsp;' . get_string('graphic', 'iassign') . "</a>";
  1621. $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>";
  1622. $link_auto_evaluate = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=auto_evaluate&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('correct') . '&nbsp;' . get_string('auto_evaluate_reprocess', 'iassign') . "</a>";
  1623. $link_all_submissions_manager = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=all_submissions&iassignid=" . $this->iassign->id . "'><i class='fa fa-files-o' aria-hidden='true' style='color: red'></i>&nbsp;" . get_string('all_submissions_manager', 'iassign') . "</a>";
  1624. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1625. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1626. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1627. print '<td width=15% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  1628. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1629. } // if ($this->action != 'print')
  1630. print '</tr></table>' . "\n";
  1631. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1632. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1633. $link_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=stats_student&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('results') . '&nbsp;' . get_string('results', 'iassign') . "</a>";
  1634. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1635. print '</tr></table>' . "\n";
  1636. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1637. else
  1638. print '</td></tr></table>' . "\n";
  1639. } // function view_legend_icons()
  1640. /// Display activity current
  1641. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1642. function view_iassign_current () {
  1643. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1644. $id = $this->cm->id;
  1645. $iassignid = $this->iassign->id;
  1646. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1647. $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
  1648. // 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 ...
  1649. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1650. if (!$iassign_statement_activity_item) {
  1651. print $OUTPUT->header();
  1652. \core\notification::error(get_string('activity_not_found', 'iassign'));
  1653. print $OUTPUT->footer();
  1654. exit;
  1655. }
  1656. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1657. $ilm_name = '';
  1658. if ($ilm->ilm)
  1659. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1660. // 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
  1661. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1662. // log record
  1663. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1664. //Trigger module viewed event.
  1665. $event = \mod_iassign\event\submission_viewed::create(array(
  1666. 'objectid' => $iassign->id,
  1667. 'context' => $this->context,
  1668. 'other' => $info
  1669. ));
  1670. $event->add_record_snapshot('course', $this->course);
  1671. $event->trigger();
  1672. // Search of iLM data used in the current activity
  1673. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1674. // Add actual activity to navbar:
  1675. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1676. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1677. print $OUTPUT->header();
  1678. if ($this->action == 'viewsubmission') {
  1679. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1680. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1681. else
  1682. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1683. } else {
  1684. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1685. }
  1686. if ($iassign_submission)
  1687. $this->update_comment($iassign_submission->id);
  1688. $file = $iassign_statement_activity_item->file;
  1689. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1690. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1691. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1692. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1693. $this->bottonPost = 0; // hide submit button
  1694. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1695. $this->view_iassign = false; // disable visualization of activity
  1696. $repeat = "";
  1697. $last_iassign = "";
  1698. $student_answer = "";
  1699. $comment = "";
  1700. // *** Teacher access (view learner's submission)
  1701. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1702. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1703. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1704. // ---> access teacher for test
  1705. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1706. $this->bottonPost = 1;
  1707. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1708. $this->activity->view_dates();
  1709. $USER->iassignEdit = $this->bottonPost;
  1710. $this->activity->show_info_iassign();
  1711. if ($iassign_submission) {
  1712. //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;
  1713. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1714. } else {
  1715. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1716. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1717. }
  1718. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1719. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1720. // Prepare tags to present the iLM
  1721. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1722. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1723. // *** (end) Teacher access (view the activity)
  1724. // *** Teacher access (view learner's submission to the activity)
  1725. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1726. // It is teacher or 'nonediting teacher' that can evaluate
  1727. // ----> area teacher evaluate
  1728. $row = optional_param('row', 0, PARAM_INT);
  1729. $column = optional_param('column', 0, PARAM_INT);
  1730. $link_next = iassign_icons::insert('right_disable');
  1731. $link_previous = iassign_icons::insert('left_disable');
  1732. $link_up = iassign_icons::insert('up_disable');
  1733. $link_down = iassign_icons::insert('down_disable');
  1734. // next_activity
  1735. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1736. $url_next = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column + 1]->iassign_submission_current . "&userid_iassign=$this->userid_iassign&iassign_current=" . $USER->matrix_iassign[$row][$column]->iassign_next . "&view_iassign=report&row=" . ($row) . "&column=" . ($column + 1);
  1737. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1738. }
  1739. // previous_activity
  1740. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1741. $url_previous = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column - 1]->iassign_submission_current . "&userid_iassign=$this->userid_iassign&iassign_current=" . $USER->matrix_iassign[$row][$column]->iassign_previous . "&view_iassign=report&row=" . ($row) . "&column=" . ($column - 1);
  1742. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1743. }
  1744. // previous_student
  1745. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1746. $url_down = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row + 1][$column]->iassign_submission_current . "&userid_iassign=" . $USER->matrix_iassign[$row][$column]->user_next . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row + 1) . "&column=" . ($column);
  1747. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1748. }
  1749. // next_student
  1750. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1751. $url_up = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row - 1][$column]->iassign_submission_current . "&userid_iassign=" . $USER->matrix_iassign[$row][$column]->user_previous . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row - 1) . "&column=" . ($column);
  1752. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1753. }
  1754. if ($iassign_submission) {
  1755. $student_answer = $iassign_submission->answer;
  1756. }
  1757. $last_iassign = get_string('last_iassign', 'iassign');
  1758. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1759. // Messages related to due date (and user role)
  1760. $this->activity->view_dates();
  1761. print $OUTPUT->box_start();
  1762. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1763. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1764. print $OUTPUT->user_picture($user_data);
  1765. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1766. print '</td>' . "\n";
  1767. print '<td width=20% align=right>' . "\n";
  1768. print '<table width=50 cellpadding="0">';
  1769. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1770. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1771. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1772. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1773. print '</table>' . "\n";
  1774. print '</td></tr></table>' . "\n";
  1775. print $OUTPUT->box_end();
  1776. print $OUTPUT->box_start();
  1777. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1778. print '<td width=60% valign="top">' . "\n";
  1779. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1780. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1781. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1782. $resp = get_string('yes');
  1783. else
  1784. $resp = get_string('no');
  1785. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1786. if ($iassign_statement_activity_item->show_answer == 1)
  1787. $resp = get_string('yes');
  1788. else
  1789. $resp = get_string('no');
  1790. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1791. print '</td>';
  1792. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1793. print '<td width=40% valign="top" align="left">';
  1794. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1795. // check status of solution sent by the student
  1796. if ($iassign_submission) {
  1797. switch ($iassign_submission->status) {
  1798. case 3 :
  1799. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1800. break;
  1801. case 2 :
  1802. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1803. break;
  1804. case 1 :
  1805. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1806. break;
  1807. default :
  1808. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1809. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1810. } // switch ($iassign_submission->status)
  1811. }
  1812. else { // if ($iassign_submission)
  1813. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1814. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1815. }
  1816. // update_status
  1817. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1818. $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);
  1819. print " <script type='text/javascript'>
  1820. //<![CDATA[
  1821. function overwriteStatus (newstatus) {
  1822. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1823. document.formEditStatus.return_status.value=newstatus;
  1824. document.formEditStatus.submit();
  1825. }
  1826. else
  1827. document.formEditStatus.return_status.value=-1;
  1828. }
  1829. //]]>
  1830. </script>";
  1831. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1832. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1833. 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";
  1834. print " <input type='hidden' name='return_status'>\n";
  1835. print "</form>\n";
  1836. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1837. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1838. $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);
  1839. print "
  1840. <script type='text/javascript'>
  1841. //<![CDATA[
  1842. function overwriteGrade (newgrade,maxgrade) {
  1843. if (newgrade<0 || newgrade>maxgrade) {
  1844. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1845. document.formEditGrade.return_grade.value=-1;
  1846. document.formEditGrade.submit();
  1847. }
  1848. else {
  1849. document.formEditGrade.return_grade.value=newgrade;
  1850. document.formEditGrade.submit();
  1851. }
  1852. }
  1853. //]]>
  1854. </script>";
  1855. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1856. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1857. print " <input type='text' name='grade' size='6'>";
  1858. print " <input type='hidden' name='return_grade'> ";
  1859. 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";
  1860. print "</form>";
  1861. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1862. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1863. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1864. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1865. if ($teacher)
  1866. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1867. } // if ($iassign_submission->experiment > 0)
  1868. print '</td>';
  1869. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1870. print '</tr></table>';
  1871. print $OUTPUT->box_end();
  1872. $USER->iassignEdit = $this->bottonPost;
  1873. if ($iassign_submission && $allow_resubmission) {
  1874. // Put the iLM to
  1875. print $OUTPUT->box_start();
  1876. print '<p><strong>' . $last_iassign . '</strong></p>';
  1877. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1878. $enderecoPOST = "";
  1879. // Prepare tags to present the iLM
  1880. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1881. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1882. print $OUTPUT->box_end();
  1883. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1884. // ATTENTION: exception used by iGeom (exercise with "script")
  1885. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1886. if (substr($ilm_name, 0, 5)=="igeom") {
  1887. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1888. $loadTeacherActivity = true;
  1889. }
  1890. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1891. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1892. // Prepare tags to present the iLM
  1893. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1894. }
  1895. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1896. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1897. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1898. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1899. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1900. // *** (end) Teacher access (view learner's submission to the activity)
  1901. // *** Student access (view the activity)
  1902. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1903. // It could be the learner (he could send or resend the activity)
  1904. // ---> access student
  1905. $time_now = time();
  1906. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1907. // activity of type example - not submit button for submission
  1908. $this->view_iassign = true;
  1909. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1910. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1911. // activity of type test - iLM automatic evaluator - submit button for submission
  1912. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1913. $this->bottonPost = 1;
  1914. $this->view_iassign = true;
  1915. } else
  1916. $this->view_iassign = false;
  1917. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1918. // activity of type exercise (learner can send his answer, if yet open...)
  1919. $this->view_iassign = true;
  1920. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1921. $this->view_iassign = false;
  1922. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1923. $this->bottonPost = 1; // allow the submit button
  1924. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1925. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1926. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1927. if (!$iassign_submission) {
  1928. $str_iassign_submission_id = '';
  1929. $str_iassign_submission_answer = '';
  1930. }
  1931. else {
  1932. $str_iassign_submission_id = $iassign_submission->id;
  1933. $str_iassign_submission_answer = $iassign_submission->answer;
  1934. }
  1935. if ($this->action != 'repeat') {
  1936. $repeat = "<a href='view.php?action=repeat&id="
  1937. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1938. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1939. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1940. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1941. }
  1942. $this->bottonPost = 1;
  1943. $this->write_solution = 1; // can register his submission
  1944. $student_answer = $str_iassign_submission_answer;
  1945. }
  1946. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1947. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1948. $last_iassign = get_string('last_iassign', 'iassign');
  1949. if ($iassign_submission) {
  1950. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1951. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1952. $student_answer = $iassign_submission->answer;
  1953. } else {
  1954. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1955. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1956. }
  1957. }
  1958. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1959. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1960. $this->bottonPost = 1;
  1961. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1962. } else {
  1963. $last_iassign = get_string('last_iassign', 'iassign');
  1964. if ($iassign_submission) {
  1965. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1966. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1967. $student_answer = $iassign_submission->answer;
  1968. } else {
  1969. // Symbol of "redo activity"
  1970. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1971. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1972. }
  1973. }
  1974. } // elseif ($iassign_statement_activity_item->test == 1)
  1975. elseif ($iassign_statement_activity_item->test == 0)
  1976. $this->view_iassign = false;
  1977. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1978. if ($iassign_submission)
  1979. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1980. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1981. else
  1982. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1983. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1984. $this->activity->view_dates();
  1985. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1986. print $OUTPUT->box_start();
  1987. print '<table width=100% border=0 valign="top">' . "\n";
  1988. print '<tr><td width=60% valign="top">' . "\n";
  1989. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1990. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1991. $flag_dependency = true;
  1992. if ($iassign_statement_activity_item->type_iassign == 3) {
  1993. if ($iassign_statement_activity_item->dependency == 0) {
  1994. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1995. } else {
  1996. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1997. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1998. foreach ($dependencys as $dependency) {
  1999. if ($dependency) {
  2000. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2001. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2002. if ($dependencysubmissions) {
  2003. if ($dependencysubmissions->status == 3)
  2004. $icon = iassign_icons::insert('correct');
  2005. elseif ($dependencysubmissions->status == 2) {
  2006. $icon = iassign_icons::insert('incorrect');
  2007. $flag_dependency = false;
  2008. } elseif ($dependencysubmissions->status == 1) {
  2009. $icon = iassign_icons::insert('post');
  2010. $flag_dependency = false;
  2011. } elseif ($dependencysubmissions->status == 0) {
  2012. $icon = iassign_icons::insert('not_post');
  2013. $flag_dependency = false;
  2014. }
  2015. } else {
  2016. $icon = iassign_icons::insert('not_post');
  2017. $flag_dependency = false;
  2018. } // if ($dependencysubmissions)
  2019. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2020. } // if ($dependency)
  2021. } // foreach ($dependencys as $dependency)
  2022. } // if ($iassign_statement_activity_item->dependency == 0)
  2023. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2024. if ($flag_dependency == false) {
  2025. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2026. $this->view_iassign = false;
  2027. print '</tr></table>' . "\n";
  2028. }
  2029. else {
  2030. $this->view_iassign = true;
  2031. print '</td>' . "\n";
  2032. } // if ($flag_dependency == false)
  2033. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2034. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2035. // receiver=1 - message to teacher
  2036. // receiver=2 - message to student
  2037. if ($iassign_submission) {
  2038. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2039. if ($verify_message)
  2040. $comment = iassign_icons::insert('comment_unread');
  2041. }
  2042. print '<td width=40% valign="top" align="left">';
  2043. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2044. if ($iassign_statement_activity_item->show_answer == 1) {
  2045. // check status of solution sent by the student
  2046. if ($iassign_submission) {
  2047. switch ($iassign_submission->status) {
  2048. case 3 :
  2049. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2050. break;
  2051. case 2 :
  2052. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2053. break;
  2054. case 1 :
  2055. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2056. break;
  2057. default :
  2058. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2059. $repeat = "";
  2060. $last_iassign = "";
  2061. } // switch ($iassign_submission->status)
  2062. } else {
  2063. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2064. $repeat = "";
  2065. $last_iassign = "";
  2066. }
  2067. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2068. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2069. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2070. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2071. if ($iassign_statement_activity_item->max_experiment == 0)
  2072. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2073. else {
  2074. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2075. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2076. $repeat = "";
  2077. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2078. $this->bottonPost = 0;
  2079. $this->write_solution = 0;
  2080. }
  2081. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2082. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2083. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2084. if ($teacher)
  2085. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2086. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2087. } // if ($iassign_statement_activity_item->show_answer==1)
  2088. else {
  2089. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2090. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2091. $repeat = "";
  2092. $last_iassign = "";
  2093. } elseif ($iassign_submission->status == 1) {
  2094. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2095. }
  2096. }
  2097. print '</td>';
  2098. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2099. print '</tr></table>' . "\n";
  2100. // Presents the iLM
  2101. print '<table width=100% border=0 valign="top">' . "\n";
  2102. print '<td width=80% align="left">';
  2103. 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\".
  2104. print '<td width=20% align="rigth">';
  2105. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2106. print $repeat; // symbol of "redo activity"
  2107. print '</td></tr></table>' . "\n";
  2108. //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)'
  2109. $output = '';
  2110. if (!$iassign_ilm) {
  2111. $iassign_ilm = new stdClass();
  2112. $iassign_ilm->file_jar = "";
  2113. }
  2114. $output .= $OUTPUT->box_start();
  2115. $USER->iassignEdit = $this->bottonPost;
  2116. // ---
  2117. // Presents the iLM
  2118. // Prepare tags to present the iLM
  2119. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2120. $student_answer = ""; //?
  2121. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2122. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2123. $student_answer = "";
  2124. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2125. } else {
  2126. // When student is redoing his activity
  2127. // ATTENTION: exception used by iGeom (exercise with "script")
  2128. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2129. if (substr($ilm_name, 0, 5)=="igeom") {
  2130. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2131. $loadTeacherActivity = true;
  2132. }
  2133. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2134. }
  2135. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2136. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2137. //1 $history_comment = '';
  2138. //1 if ($iassign_submission) {
  2139. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2140. //1 }
  2141. //1 if (!empty($history_comment)) {
  2142. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2143. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2144. //1 $output .= $history_comment;
  2145. //1 $output .= "</table>\n";
  2146. //1 }
  2147. //1 $output .= "</form></center>\n";
  2148. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2149. //1 }
  2150. $output .= $OUTPUT->box_end();
  2151. print $output;
  2152. } // if ($this->view_iassign)
  2153. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2154. } // if ($this->view_iassign)
  2155. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2156. else
  2157. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2158. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2159. print '<table width=100% border=0 valign="top">' . "\n";
  2160. print '<tr><td width=60% valign="top">' . "\n";
  2161. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2162. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2163. print '</tr></table>' . "\n";
  2164. $student_answer = "";
  2165. $enderecoPOST = "";
  2166. // Prepare tags to present the iLM
  2167. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2168. print $output;
  2169. }
  2170. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2171. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2172. 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
  2173. // Put a block with area to sent/answer comments
  2174. $output = '';
  2175. $history_comment = '';
  2176. $row = optional_param('row', 0, PARAM_INT);
  2177. $column = optional_param('column', 0, PARAM_INT);
  2178. if ($iassign_submission) {
  2179. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2180. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2181. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2182. }
  2183. else {
  2184. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2185. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2186. }
  2187. $output .= $OUTPUT->box_start();
  2188. //if (!empty($history_comment)) {
  2189. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2190. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2191. $output .= "</table>";
  2192. print " <script type='text/javascript'>
  2193. //<![CDATA[
  2194. function submit_comment(url) {
  2195. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2196. var formData = new FormData();
  2197. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2198. var request = new XMLHttpRequest();
  2199. request.open('POST', url);
  2200. document.getElementById('comments_history').innerHTML = '';
  2201. request.onload = function (e) {
  2202. if (request.readyState === 4) {
  2203. if (request.status === 200) {
  2204. document.getElementById('comments_history').innerHTML = request.responseText;
  2205. document.getElementById('check-message-success').style.visibility = 'visible';
  2206. setTimeout(function(){
  2207. document.getElementById('check-message-success').style.visibility = 'hidden';
  2208. }, 3000);
  2209. }
  2210. }
  2211. };
  2212. document.formEnvioComment.submission_comment.value = '';
  2213. request.send(formData);
  2214. }
  2215. //]]>
  2216. </script>";
  2217. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2218. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2219. $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";
  2220. $output .= "</form> </center>\n";
  2221. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2222. // }
  2223. $output .= $OUTPUT->box_end();
  2224. print $output;
  2225. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2226. // final block 'studant'
  2227. print $OUTPUT->footer();
  2228. die();
  2229. } // function view_iassign_current()
  2230. /// Export the data from performance report into CSV file format
  2231. function export_csv () {
  2232. global $USER, $CFG, $DB, $OUTPUT;
  2233. $str = "";
  2234. $fields = "student_id, student_name";
  2235. // Finding all iassign activities for the iassign:
  2236. $id = $this->cm->id;
  2237. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2238. $c = 1;
  2239. foreach ($iassign_list as $iassign) {
  2240. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2241. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2242. $c ++;
  2243. }
  2244. // Finding enrolled students:
  2245. $params = array('shortname' => 'student');
  2246. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2247. $context = context_course::instance($this->course->id);
  2248. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2249. $students = $DB->get_records_sql(
  2250. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2251. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2252. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2253. foreach ($students as $student) {
  2254. $str .= $student->userid . ',';
  2255. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2256. foreach ($iassign_list as $iassign) {
  2257. $str .= ',' . $iassign->id . ',';
  2258. $str .= '"' . $iassign->name . '",';
  2259. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2260. if ($student_submissions) {
  2261. $str .= $student_submissions->experiment . ',';
  2262. $str .= $student_submissions->grade . ',';
  2263. switch ($student_submissions->status) {
  2264. case 3:
  2265. $str .= '"correct",';
  2266. break;
  2267. case 2:
  2268. $str .= '"incorrect",';
  2269. break;
  2270. case 1:
  2271. $str .= '"post",';
  2272. break;
  2273. case 0:
  2274. $str .= '"not_post",';
  2275. break;
  2276. }
  2277. } else {
  2278. $str .= ',,"not_post",';
  2279. }
  2280. $str .= $iassign->iassign_ilmid . ',';
  2281. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2282. $str .= '"' . $ilm_activity->name . '"';
  2283. }
  2284. $str .= "\n";
  2285. }
  2286. $str = $fields . "\n" . $str;
  2287. header("Content-type: text/csv");
  2288. header("Content-disposition: attachment; filename=report.csv");
  2289. header("Pragma: no-cache");
  2290. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2291. header('Content-Length: ' . strlen($str));
  2292. header('Connection: close');
  2293. print $str;
  2294. flush();
  2295. } // function export_csv()
  2296. /// Display report of performance
  2297. function report () {
  2298. global $USER, $CFG, $DB, $OUTPUT;
  2299. $id = $this->cm->id;
  2300. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2301. if ($this->action != 'print') {
  2302. $title = get_string('report', 'iassign');
  2303. print $OUTPUT->header();
  2304. } // if ($this->action != 'print')
  2305. print $OUTPUT->box_start();
  2306. $this->view_legend_icons();
  2307. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2308. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2309. print $OUTPUT->box_end();
  2310. if ($this->action == 'print')
  2311. print '<table border=1 width="100%">' . "\n";
  2312. else
  2313. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2314. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2315. // $num = array();
  2316. $i = 1;
  2317. $num = array();
  2318. foreach ($iassign_list as $iassign) {
  2319. $test_exercise = "";
  2320. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2321. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2322. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2323. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2324. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2325. $num[$i] = new stdClass();
  2326. $num[$i]->name = $iassign->name;
  2327. $num[$i]->id = $i;
  2328. $num[$i]->iassignid = $iassign->id;
  2329. print ' <tr >' . "\n";
  2330. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2331. print "<td class=\"cell c0 actvity\">";
  2332. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2333. print ' </tr>' . "\n";
  2334. $i ++;
  2335. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2336. } // foreach ($iassign_list as $iassign)
  2337. print "</table>";
  2338. print "<p></p>";
  2339. if ($this->action == 'print')
  2340. print '<table border=1 width="100%">' . "\n";
  2341. else
  2342. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2343. $context = context_course::instance($this->course->id);
  2344. if ($i > 1) {
  2345. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2346. $params = array('shortname' => 'student');
  2347. $role = $DB->get_record_sql(
  2348. "SELECT s.id, s.shortname FROM {role} s " .
  2349. " WHERE s.shortname = :shortname", $params);
  2350. // $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");
  2351. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2352. $students = $DB->get_records_sql(
  2353. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2354. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2355. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2356. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2357. for ($j = 1; $j < $i; $j ++) {
  2358. $sum_iassign_correct[$j] = 0;
  2359. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2360. }
  2361. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2362. $sum_iassign = $j - 1;
  2363. print '</tr>' . "\n";
  2364. $total = 0;
  2365. $sum_student = 0;
  2366. $comment = iassign_icons::insert('comment_read');
  2367. $sum_comment = 0;
  2368. $sum_correct_iassign = array();
  2369. $sum_correct_student = array();
  2370. $USER->matrix_iassign = array();
  2371. if ($students) {
  2372. $w = 0;
  2373. foreach ($students as $tmp) {
  2374. $users_array[$w] = $tmp;
  2375. $w ++;
  2376. }
  2377. for ($x = 0; $x < $w; $x ++) {
  2378. print '<tr>' . "\n";
  2379. $sum_student ++;
  2380. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2381. print ' <td >' . $name . '</td>' . "\n";
  2382. $total_student = 0;
  2383. $tentativas = 0;
  2384. for ($j = 1; $j < $i; $j ++) {
  2385. $sum_comment = 0;
  2386. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2387. print ' <td valign="bottom" align="center">' . "\n";
  2388. if ($student_submissions) {
  2389. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2390. $tentativas = $student_submissions->experiment;
  2391. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2392. $params = array('iassign_submissionid' => $student_submissions->id);
  2393. $student_submissions_comment = $DB->get_record_sql(
  2394. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2395. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2396. if ($student_submissions_comment)
  2397. foreach ($student_submissions_comment as $tmp)
  2398. $sum_comment = $tmp;
  2399. // informations to previous activities
  2400. if ($j - 1 < 1 || $j == $i)
  2401. $iassign_previous = "-1";
  2402. else
  2403. $iassign_previous = $num[$j - 1]->iassignid;
  2404. if ($x - 1 < 0 || $x == $w)
  2405. $user_previous = "-1";
  2406. else
  2407. $user_previous = $users_array[$x - 1]->userid;
  2408. // next
  2409. if ($i - 1 > $j)
  2410. $iassign_next = $num[$j + 1]->iassignid;
  2411. else
  2412. $iassign_next = "-1";
  2413. if ($w - 1 > $x)
  2414. $user_next = $users_array[$x + 1]->userid;
  2415. else
  2416. $user_next = "-1";
  2417. $position = "&row= $x&column=$j";
  2418. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2419. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2420. $url .= $position;
  2421. // receiver=1 - message to teacher
  2422. // receiver=2 - message to student
  2423. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2424. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2425. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2426. $verify_message = $DB->get_record_sql(
  2427. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2428. "WHERE iassign_submissionid = :iassign_submissionid " .
  2429. " AND return_status= :return_status " .
  2430. " AND receiver= :receiver", $params);
  2431. if ($verify_message)
  2432. foreach ($verify_message as $tmp)
  2433. $sum_verify_message = $tmp;
  2434. if ($sum_verify_message > 0)
  2435. $comment = iassign_icons::insert('comment_unread');
  2436. else
  2437. $comment = iassign_icons::insert('comment_read');
  2438. if ($student_submissions->status == 3) {
  2439. $sum_iassign_correct[$j] ++;
  2440. $total_student ++;
  2441. $feedback = iassign_icons::insert('correct');
  2442. }
  2443. elseif ($student_submissions->status == 2) {
  2444. $feedback = iassign_icons::insert('incorrect');
  2445. }
  2446. elseif ($student_submissions->status == 1) {
  2447. $feedback = iassign_icons::insert('post');
  2448. }
  2449. elseif ($student_submissions->status == 0) {
  2450. $feedback = iassign_icons::insert('not_post');
  2451. }
  2452. if ($this->action != 'print') {
  2453. print '<table><tr>';
  2454. if ($tentativas > 0)
  2455. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2456. else
  2457. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2458. print '<td> &nbsp; </td>';
  2459. print '</tr>' . "\n";
  2460. if ($sum_comment > 0 && $sum_verify_message > 0)
  2461. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2462. else if ($sum_comment > 0)
  2463. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2464. print '</table>' . "\n";
  2465. }
  2466. if ($this->action == 'print')
  2467. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2468. } // if ($student_submissions)
  2469. else { // if ($student_submissions)
  2470. // informations to browse previous activities
  2471. if ($j - 1 < 1 || $j == $i)
  2472. $iassign_previous = "-1";
  2473. else
  2474. $iassign_previous = $num[$j - 1]->iassignid;
  2475. if ($x - 1 < 0 || $x == $w)
  2476. $user_previous = "-1";
  2477. else
  2478. $user_previous = $users_array[$x - 1]->userid;
  2479. // next
  2480. if ($i - 1 > $j)
  2481. $iassign_next = $num[$j + 1]->iassignid;
  2482. else
  2483. $iassign_next = "-1";
  2484. if ($w - 1 > $x)
  2485. $user_next = $users_array[$x + 1]->userid;
  2486. else
  2487. $user_next = "-1";
  2488. $position = "&row= $x&column=$j";
  2489. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2490. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2491. $url .= $position;
  2492. $feedback = iassign_icons::insert('not_post');
  2493. if ($this->action == 'print')
  2494. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2495. else {
  2496. print '<table><tr>';
  2497. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2498. print '<td> &nbsp; </td>';
  2499. print '</tr><tr>' . "\n";
  2500. print '<td> &nbsp;</td>';
  2501. if ($sum_comment > 0)
  2502. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2503. else
  2504. print '<td> &nbsp;</td>';
  2505. print '</tr></table>';
  2506. }
  2507. } // else if ($student_submissions)
  2508. $USER->matrix_iassign[$x][$j] = new stdClass();
  2509. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2510. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2511. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2512. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2513. if ($student_submissions)
  2514. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2515. else
  2516. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2517. print '</td>' . "\n";
  2518. } // for ($j=1; $j<$i; $j++)
  2519. $total = $total + $total_student;
  2520. $porcentagem = ($total_student / ($j - 1)) * 100;
  2521. if ($tentativas != 0 && $tentativas != null) {
  2522. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2523. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2524. }
  2525. else {
  2526. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2527. }
  2528. print '</tr>' . "\n";
  2529. $sum_correct_student[$sum_student] = new stdClass();
  2530. $sum_correct_student[$sum_student]->name = $name;
  2531. $sum_correct_student[$sum_student]->sum = $total_student;
  2532. } // for ($x = 0; $x < $w; $x ++)
  2533. for ($i = 1; $i < $j; $i ++) {
  2534. if (is_null($sum_iassign_correct[$i]))
  2535. $sum_iassign_correct[$i] = 0;
  2536. $sum_correct_iassign[$i] = new stdClass();
  2537. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2538. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2539. }
  2540. // print '</tr></table>' . "\n";
  2541. }
  2542. } // if ($i>1)
  2543. else {
  2544. print_string('no_activity', 'iassign');
  2545. }
  2546. print "</table>\n";
  2547. if ($this->action != 'print')
  2548. print $OUTPUT->footer();
  2549. die();
  2550. } // function report()
  2551. /// Display graphics of performance
  2552. function stats () {
  2553. global $USER, $CFG, $DB, $OUTPUT;
  2554. $id = $this->cm->id;
  2555. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2556. if ($this->action != 'printstats')
  2557. $title = get_string('graphic', 'iassign');
  2558. $num = array();
  2559. $sum_correct_iassign = array();
  2560. $sum_correct_student = array();
  2561. $sum_student = 0;
  2562. $i = 1;
  2563. foreach ($iassign_list as $iassign) {
  2564. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2565. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2566. $sum_iassign_correct[$i] = 0;
  2567. $num[$i] = new stdClass();
  2568. $num[$i]->name = $iassign->name;
  2569. $num[$i]->id = $i;
  2570. $num[$i]->iassignid = $iassign->id;
  2571. $i ++;
  2572. } // if ($iassign->type_iassign == 3)
  2573. } // foreach ($iassign_list as $iassign)
  2574. $sum_iassign = $i - 1;
  2575. $context = context_course::instance($this->course->id);
  2576. if ($i > 1) {
  2577. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2578. $params = array('shortname' => 'student');
  2579. $role = $DB->get_record_sql(
  2580. "SELECT s.id, s.shortname FROM {role} s " .
  2581. " WHERE s.shortname = :shortname", $params);
  2582. // $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");
  2583. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2584. $students = $DB->get_records_sql(
  2585. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2586. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2587. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2588. $total = 0;
  2589. $sum_student = 0;
  2590. $j = 0;
  2591. $sum_correct_iassign = array();
  2592. $sum_correct_student = array();
  2593. $sum_experiment = array();
  2594. if ($students) {
  2595. foreach ($students as $users) {
  2596. $sum_student ++;
  2597. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2598. // rows
  2599. $total_student = 0;
  2600. for ($j = 1; $j < $i; $j ++) {
  2601. $total_experiment = 0;
  2602. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2603. if ($student_submissions) {
  2604. if ($student_submissions->status == 3) {
  2605. $sum_iassign_correct[$j] ++;
  2606. $total_student ++;
  2607. } // if ($student_submissions->status == 3)
  2608. $total_experiment += $student_submissions->experiment;
  2609. }
  2610. $sum_experiment[$j] = $total_experiment;
  2611. } // for ($j=1; $j<$i; $j++)
  2612. $total = $total + $total_student;
  2613. $sum_correct_student[$sum_student] = new stdClass();
  2614. $sum_correct_student[$sum_student]->name = $name;
  2615. $sum_correct_student[$sum_student]->sum = $total_student;
  2616. } // foreach ($students as $users)
  2617. }
  2618. for ($i = 1; $i < $j; $i ++) {
  2619. if (is_null($sum_iassign_correct[$i]))
  2620. $sum_iassign_correct[$i] = 0;
  2621. $sum_correct_iassign[$i] = new stdClass();
  2622. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2623. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2624. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2625. } // for ($i = 1; $i < $j; $i++)
  2626. } // if ($i > 1)
  2627. if ($this->action != 'printstats') {
  2628. $title = get_string('graphic', 'iassign');
  2629. print $OUTPUT->header();
  2630. $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>";
  2631. $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>";
  2632. print '<table width=100%><tr>';
  2633. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2634. print '<td width=15% align="right">' . $link_report . '</td>';
  2635. print '</td></tr></table>' . "\n";
  2636. print "<br><br>";
  2637. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2638. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2639. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2640. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2641. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2642. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2643. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2644. print '</tr>' . "\n";
  2645. $sum_correct = 0;
  2646. if ($sum_correct_iassign) {
  2647. foreach ($sum_correct_iassign as $iassign) {
  2648. if (is_null($iassign->experiment))
  2649. $iassign->experiment = 0;
  2650. $bar = "";
  2651. $sum = $iassign->sum;
  2652. $percent = ($sum / $sum_student) * 100;
  2653. $text = number_format($percent, 1) . '%';
  2654. $sum_correct += $sum;
  2655. if ($sum > 0) {
  2656. for ($i = 1; $i < $percent * 2; $i ++)
  2657. $bar .= iassign_icons::insert('hbar_blue');
  2658. $bar .= iassign_icons::insert('hbar_blue_r');
  2659. } // if ($sum > 0)
  2660. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2661. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2662. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2663. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2664. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2665. print '</tr>' . "\n";
  2666. } // foreach ($sum_correct_iassign as $iassign)
  2667. }
  2668. print "</table>";
  2669. print "<br><br>";
  2670. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2671. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2672. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2673. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2674. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2675. print '</tr>' . "\n";
  2676. $sum_correct = 0;
  2677. foreach ($sum_correct_student as $student) {
  2678. $bar = "";
  2679. $sum = $student->sum;
  2680. $percent = ($sum / $sum_iassign) * 100;
  2681. $text = number_format($percent, 1) . '%';
  2682. $sum_correct += $sum;
  2683. if ($sum > 0) {
  2684. for ($i = 1; $i < $percent * 2; $i ++)
  2685. $bar .= iassign_icons::insert('hbar_blue');
  2686. $bar .= iassign_icons::insert('hbar_blue_r');
  2687. } // if ($sum > 0)
  2688. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2689. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2690. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2691. print '</tr>' . "\n";
  2692. } // foreach ($sum_correct_student as $student)
  2693. print "</table>\n";
  2694. print "<br><br>\n";
  2695. $var = 0;
  2696. $cv = 0;
  2697. $dv = 0;
  2698. $avg = 0;
  2699. if ($sum_correct_student) {
  2700. $avg = $sum_correct / $sum_student;
  2701. if ($avg > 0) {
  2702. foreach ($sum_correct_student as $student)
  2703. $var += pow($student->sum - $avg, 2);
  2704. $var = $var / $sum_student;
  2705. $dv = sqrt($var);
  2706. $cv = ($dv / $avg) * 100;
  2707. }
  2708. }
  2709. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2710. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2711. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2712. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2713. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2714. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2715. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2716. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2717. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2718. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2719. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2720. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2721. print "</table>\n";
  2722. print $OUTPUT->footer();
  2723. } else {
  2724. print "<STYLE TYPE='text/css'>
  2725. <!--
  2726. .boldtable {
  2727. font-family:sans-serif;
  2728. font-size:10pt;
  2729. }
  2730. -->
  2731. </STYLE>\n";
  2732. print '<table border=1 width=100%>' . "\n";
  2733. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2734. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2735. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2736. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2737. print '</tr>' . "\n";
  2738. $sum_correct = 0;
  2739. foreach ($sum_correct_iassign as $iassign) {
  2740. $bar = "";
  2741. $sum = $iassign->sum;
  2742. $percent = ($sum / $sum_student) * 100;
  2743. $text = number_format($percent, 1) . '%';
  2744. $sum_correct += $sum;
  2745. if ($sum > 0) {
  2746. for ($i = 1; $i < $percent * 2; $i ++)
  2747. $bar .= iassign_icons::insert('hbar_blue');
  2748. $bar .= iassign_icons::insert('hbar_blue_r');
  2749. } // if ($sum > 0)
  2750. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2751. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2752. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2753. print '</tr>' . "\n";
  2754. } // foreach ($sum_correct_iassign as $iassign)
  2755. print "</table>";
  2756. print "<br><br>";
  2757. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2758. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2759. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2760. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2761. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2762. print '</tr>' . "\n";
  2763. $sum_correct = 0;
  2764. foreach ($sum_correct_student as $student) {
  2765. $bar = "";
  2766. $sum = $student->sum;
  2767. $percent = ($sum / $sum_iassign) * 100;
  2768. $text = number_format($percent, 1) . '%';
  2769. $sum_correct += $sum;
  2770. if ($sum > 0) {
  2771. for ($i = 1; $i < $percent * 2; $i ++)
  2772. $bar .= iassign_icons::insert('hbar_blue');
  2773. $bar .= iassign_icons::insert('hbar_blue_r');
  2774. } // if ($sum > 0)
  2775. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2776. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2777. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2778. print '</tr>' . "\n";
  2779. } // foreach ($sum_correct_student as $student)
  2780. print "</table>\n";
  2781. print "<br/><br/>\n";
  2782. $var = 0;
  2783. $cv = 0;
  2784. $dv = 0;
  2785. $avg = 0;
  2786. if ($sum_correct_student) {
  2787. $avg = $sum_correct / $sum_student;
  2788. if ($avg > 0) {
  2789. foreach ($sum_correct_student as $student)
  2790. $var += pow($student->sum - $avg, 2);
  2791. $var = $var / $sum_student;
  2792. $dv = sqrt($var);
  2793. $cv = ($dv / $avg) * 100;
  2794. }
  2795. }
  2796. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2797. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2798. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2799. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2800. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2801. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2802. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2803. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2804. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2805. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2806. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2807. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2808. print "</table>\n";
  2809. } // if ($this->action != 'printstats')
  2810. die();
  2811. }
  2812. /// Display graphics of performance for students
  2813. function stats_students () {
  2814. global $USER, $CFG, $DB, $OUTPUT;
  2815. $id = $this->cm->id;
  2816. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2817. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2818. $title = get_string('results', 'iassign');
  2819. $sum_correct = 0;
  2820. $sum_incorrect = 0;
  2821. $sum_post = 0;
  2822. $sum_nopost = 0;
  2823. $sum_iassign = count($iassign_statement_list);
  2824. $bar_nopost = "";
  2825. $bar_correct = "";
  2826. $bar_incorrect = "";
  2827. $bar_post = "";
  2828. $text_nopost = "";
  2829. $text_correct = "";
  2830. $text_incorrect = "";
  2831. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2832. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2833. if ($iassign_submission) {
  2834. if ($iassign_submission->status == 3)
  2835. $sum_correct ++;
  2836. elseif ($iassign_submission->status == 2)
  2837. $sum_incorrect ++;
  2838. elseif ($iassign_submission->status == 1)
  2839. $sum_post ++;
  2840. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2841. $sum_nopost ++;
  2842. } // if ($iassign_submission)
  2843. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2844. if ($sum_iassign > 0) {
  2845. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2846. $text_correct = number_format($percent_correct, 1) . '%';
  2847. }
  2848. if ($sum_correct > 0) {
  2849. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2850. $bar_correct .= iassign_icons::insert('hbar_green');
  2851. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2852. } // if ($sum_correct > 0)
  2853. if ($sum_iassign > 0) {
  2854. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2855. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2856. }
  2857. if ($sum_incorrect > 0) {
  2858. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2859. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2860. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2861. } // if ($sum_incorrect > 0)
  2862. if ($sum_iassign > 0) {
  2863. $percent_post = ($sum_post / $sum_iassign) * 100;
  2864. $text_post = number_format($percent_post, 1) . '%';
  2865. }
  2866. if ($sum_post > 0) {
  2867. for ($i = 1; $i < $percent_post * 2; $i ++)
  2868. $bar_post .= iassign_icons::insert('hbar_blue');
  2869. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2870. } // if ($sum_post > 0)
  2871. if ($sum_iassign > 0) {
  2872. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2873. $text_nopost = number_format($percent_nopost, 1) . '%';
  2874. }
  2875. if ($sum_nopost > 0) {
  2876. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2877. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2878. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2879. } // if ($sum_nopost > 0)
  2880. print $OUTPUT->header();
  2881. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2882. print '<table width=100%><tr>';
  2883. print '<td align="right">' . $link_return . '</td>' . "\n";
  2884. print '</td></tr></table>' . "\n";
  2885. print "<br/><br/>\n";
  2886. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2887. print '<tr><th colspan=3 class="header c1">' . "\n";
  2888. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2889. // $imagetext = '');
  2890. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2891. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2892. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2893. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2894. print '</tr>' . "\n";
  2895. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2896. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2897. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2898. print '</tr>' . "\n";
  2899. if ($sum_post) {
  2900. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2901. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2902. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2903. print '</tr>' . "\n";
  2904. } // if ($sum_post)
  2905. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2906. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2907. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2908. print '</tr>' . "\n";
  2909. print "</table>";
  2910. print "<br><br>";
  2911. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2912. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2913. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2914. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2915. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2916. $sum_grade = 0;
  2917. $sum_grade_student = 0;
  2918. $avg = 0;
  2919. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2920. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2921. if (!$iassign_submission) {
  2922. $iassign_submission = new stdClass();
  2923. $iassign_submission->grade = 0;
  2924. }
  2925. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2926. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2927. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2928. print '</tr>' . "\n";
  2929. $sum_grade += $iassign_statement_activity_item->grade;
  2930. $sum_grade_student += $iassign_submission->grade;
  2931. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2932. if ($sum_grade > 0)
  2933. $avg = $sum_grade_student / $sum_grade * 100;
  2934. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2935. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2936. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2937. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2938. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2939. print "</table>";
  2940. print $OUTPUT->footer();
  2941. die();
  2942. } // function stats_students()
  2943. /// Display page of iAssign's activity
  2944. function view_iassigns () {
  2945. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2946. $id = $this->cm->id;
  2947. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2948. $notice = optional_param('notice', '', PARAM_TEXT);
  2949. if (strpos($notice, 'error'))
  2950. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2951. else if ($notice != '')
  2952. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2953. print $OUTPUT->box_start();
  2954. print '<table width=100% border=0><tr>' . "\n";
  2955. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2956. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2957. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2958. $link_add = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=add&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('add_iassign') . get_string('add_iassign', 'iassign') . "</a>";
  2959. $link_report = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('view_report') . get_string('report', 'iassign') . "</a>";
  2960. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2961. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2962. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2963. // Has capability to see "report": teacher or up
  2964. print '<td width=10% align="left">' . "\n";
  2965. print $link_help;
  2966. print '</td>' . "\n";
  2967. print '<td width=10% align="left">' . "\n";
  2968. print $link_report;
  2969. print '</td>' . "\n";
  2970. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2971. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2972. print '<td width=15% align="left">' . "\n";
  2973. print $link_add;
  2974. print "</td>\n";
  2975. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2976. //print '</tr></table>' . "\n";
  2977. print '<div style="float: right;">';
  2978. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2979. if ($iassign_list) {
  2980. print '<td align="right">' . "\n";
  2981. // $USER->iassignEdit == 0 view 'Turn editing off'
  2982. // $USER->iassignEdit == 1 view 'Turn editing on'
  2983. if (!isset($USER->iassignEdit))
  2984. $USER->iassignEdit = 0;
  2985. if ($USER->iassignEdit == 0) {
  2986. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2987. $botton = 1;
  2988. } // if ($USER->iassignEdit == 0)
  2989. elseif ($USER->iassignEdit == 1) {
  2990. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2991. $botton = 0;
  2992. } // elseif ($USER->iassignEdit == 1)
  2993. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2994. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2995. print " <input type=submit value='$bottonEdit_message'/>\n";
  2996. print "</form>\n";
  2997. print "</td>\n";
  2998. } // if ($iassign_list)
  2999. }
  3000. print '</tr></table>' . "\n";
  3001. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3002. // $this->view_legend_icons();
  3003. print $OUTPUT->box_end();
  3004. $iassign_array_exercise = array();
  3005. $i_exercise = 0;
  3006. $iassign_array_test = array();
  3007. $i_test = 0;
  3008. $iassign_array_example = array();
  3009. $i_example = 0;
  3010. $iassign_array_general = array();
  3011. $i_general = 0;
  3012. if ($iassign_list) {
  3013. if ($this->iassign->activity_group == 0) {
  3014. foreach ($iassign_list as $iassign) {
  3015. $iassign_array_general[$i_general] = $iassign;
  3016. $i_general ++;
  3017. }
  3018. } // if ($this->iassign->activity_group == 0)
  3019. else {
  3020. foreach ($iassign_list as $iassign) {
  3021. if ($iassign->type_iassign == 3) {
  3022. $iassign_array_exercise[$i_exercise] = $iassign;
  3023. $i_exercise ++;
  3024. } // if ($iassign->type_iassign == 3)
  3025. if ($iassign->type_iassign == 2) {
  3026. $iassign_array_test[$i_test] = $iassign;
  3027. $i_test ++;
  3028. } // if ($iassign->type_iassign == 2)
  3029. if ($iassign->type_iassign == 1) {
  3030. $iassign_array_example[$i_example] = $iassign;
  3031. $i_example ++;
  3032. } // if ($iassign->type_iassign == 1)
  3033. }
  3034. }
  3035. if ($iassign_array_exercise) {
  3036. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3037. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3038. }
  3039. if ($iassign_array_test) {
  3040. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3041. $this->show_iassign($title, $iassign_array_test, $i_test);
  3042. }
  3043. if ($iassign_array_example) {
  3044. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3045. $this->show_iassign($title, $iassign_array_example, $i_example);
  3046. }
  3047. if ($iassign_array_general) {
  3048. $title = "";
  3049. $this->show_iassign($title, $iassign_array_general, $i_general);
  3050. }
  3051. } else { // if ($iassign_list)
  3052. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3053. }
  3054. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3055. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3056. print $OUTPUT->box_start();
  3057. print '<table width=100% border=0><tr>' . "\n";
  3058. print '<td width=10% align="left">' . "\n";
  3059. print $link_report;
  3060. print '</td>' . "\n";
  3061. print '</tr></table>' . "\n";
  3062. print $OUTPUT->box_end();
  3063. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3064. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3065. print $OUTPUT->box_start();
  3066. print '<table width=100% border=0><tr>' . "\n";
  3067. print '<td align="left">' . "\n";
  3068. print $link_add;
  3069. print '</td>' . "\n";
  3070. print '</tr></table>' . "\n";
  3071. print $OUTPUT->box_end();
  3072. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3073. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3074. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3075. $this->view_legend_icons();
  3076. } // function view_iassigns()
  3077. /// Display all iAssigns
  3078. function show_iassign ($title, $iassign_array, $i) {
  3079. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3080. $id = $this->cm->id;
  3081. print $OUTPUT->box_start();
  3082. print " <script type='text/javascript'>
  3083. //<![CDATA[
  3084. function validate_move () {
  3085. var radios = document.getElementsByName('iassign_destiny');
  3086. var formValid = false;
  3087. //alert('aqui validate_move()');
  3088. var i = 0;
  3089. while (!formValid && i < radios.length) {
  3090. if (radios[i].checked) formValid = true;
  3091. i++;
  3092. }
  3093. if (!formValid) {
  3094. document.getElementById('move_dest').classList.add('alert-danger');
  3095. }
  3096. return formValid;
  3097. }
  3098. var modal;
  3099. function load_move(id_ias) {
  3100. document.form_move_activity.iassign_current.value = id_ias;
  3101. modal.style.display = 'block';
  3102. var radios = document.getElementsByName('iassign_destiny');
  3103. var i = 0;
  3104. while (i < radios.length) {
  3105. radios[i].checked = false;
  3106. i++;
  3107. }
  3108. document.getElementById('move_dest').classList.remove('alert-danger');
  3109. }
  3110. function load_modal_elements() {
  3111. modal = document.getElementById('myModal');
  3112. var span = document.getElementById('close_modal');
  3113. span.onclick = function() {
  3114. modal.style.display = 'none';
  3115. }
  3116. window.onclick = function(event) {
  3117. if (event.target == modal) {
  3118. modal.style.display = 'none';
  3119. }
  3120. }
  3121. }
  3122. window.onload = load_modal_elements;
  3123. //]]>
  3124. </script>\n";
  3125. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3126. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3127. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3128. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3129. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3130. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3131. <input type='hidden' name='iassign_current' value='' />";
  3132. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3133. $section = $course_sections[0];
  3134. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3135. for ($k = 0; $k < count($ids_sections); $k++) {
  3136. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3137. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3138. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3139. if ($c_cm) {
  3140. if ($ccm->instance == $c_cm->instance) {
  3141. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3142. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3143. }
  3144. else {
  3145. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3146. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3147. }
  3148. }
  3149. }
  3150. $radio_buttons .= "</ul>";
  3151. }
  3152. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3153. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3154. </form>
  3155. </div></div> </div></div>\n";
  3156. print " <style>.modal {
  3157. display: none;
  3158. position: fixed;
  3159. z-index: 1;
  3160. left: 0;
  3161. top: 0;
  3162. width: 100%;
  3163. height: 100%;
  3164. overflow: scroll;
  3165. background-color: rgb(0,0,0);
  3166. background-color: rgba(0,0,0,0.4);
  3167. }
  3168. .modal-content {
  3169. background-color: #fefefe;
  3170. margin: 15% auto;
  3171. padding: 10px 10px;
  3172. border: 1px solid #888;
  3173. width: 50%;
  3174. }
  3175. #close_modal {
  3176. color: #aaa;
  3177. float: right;
  3178. font-size: 28px;
  3179. font-weight: bold;
  3180. margin-top: -15px;
  3181. margin-right: -3px;
  3182. }
  3183. #close_modal:hover,
  3184. #close_modal:focus {
  3185. color: black;
  3186. text-decoration: none;
  3187. cursor: pointer;
  3188. }
  3189. #modal_title {
  3190. min-height: 3rem;
  3191. color: initial;
  3192. background: initial;
  3193. font-size: 1.5rem;
  3194. line-height: 1.5;
  3195. padding: 15px;
  3196. border-bottom: 1px solid #e5e5e5;
  3197. }
  3198. .input_move {
  3199. width: 90%;
  3200. padding: 2px;
  3201. }
  3202. .input_move:hover {
  3203. background: #eff0ef;
  3204. }
  3205. </style>";
  3206. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3207. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3208. for ($j = 0; $j < $i; $j ++) {
  3209. $iassign_current = $iassign_array[$j]->id;
  3210. // receiver=1 - message to teacher
  3211. // receiver=2 - message to student
  3212. $sum_comment = 0;
  3213. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3214. foreach ($iassign_submissions as $iassign_submission) {
  3215. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3216. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3217. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3218. if ($verify_message)
  3219. foreach ($verify_message as $tmp)
  3220. $sum_comment += $tmp;
  3221. } // foreach ($iassign_submissions as $iassign_submission)
  3222. if ($sum_comment == 0)
  3223. $comment_unread = "";
  3224. else {
  3225. $comment_unread_message = get_string('comment_unread', 'iassign');
  3226. if ($sum_comment == 1)
  3227. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3228. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3229. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3230. }
  3231. if ($j == $i - 1)
  3232. $iassign_down = $iassign_array[$j]->id;
  3233. else
  3234. $iassign_down = $iassign_array[$j + 1]->id;
  3235. if ($j > 0)
  3236. $iassign_up = $iassign_array[$j - 1]->id;
  3237. else
  3238. $iassign_up = $iassign_array[$j]->id;
  3239. if ($iassign_array[$j]->visible == 0)
  3240. $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>";
  3241. else
  3242. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3243. $links .= $comment_unread;
  3244. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3245. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3246. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3247. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3248. if ($j==0) // first activity
  3249. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3250. else
  3251. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3252. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3253. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3254. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3255. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3256. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3257. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3258. if (count($iassign_array) > 1) {
  3259. if ($j == 0)
  3260. $links .= $link_down;
  3261. elseif ($j == $i - 1)
  3262. $links .= $link_up;
  3263. else
  3264. $links .= $link_up . $link_down;
  3265. } // if (count($iassign_array) > 1)
  3266. $links .= $link_edit . $link_delete;
  3267. if ($iassign_array[$j]->visible == 0)
  3268. $links .= $link_visible_show;
  3269. else
  3270. $links .= $link_visible_hide;
  3271. $links .= $link_duplicate_activity . $link_move_activity;
  3272. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3273. print '<p>' . $links . '</p>' . "\n";
  3274. }
  3275. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3276. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3277. print '<table width=100% ><tr>' . "\n";
  3278. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3279. print '</tr></table>' . "\n";
  3280. for ($j = 0; $j < $i; $j ++) {
  3281. $icon_status = "";
  3282. $icon_comment = "";
  3283. if ($iassign_array[$j]->visible == 1) {
  3284. $iassign_current = $iassign_array[$j]->id;
  3285. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3286. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3287. $icon_status = "";
  3288. $icon_comment = "";
  3289. if ($iassign_submission) {
  3290. // receiver=1 - message to teacher
  3291. // receiver=2 - message to student
  3292. // $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");
  3293. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3294. $verify_message = $DB->get_record_sql(
  3295. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3296. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3297. if ($verify_message)
  3298. foreach ($verify_message as $tmp)
  3299. $sum_comment = $tmp;
  3300. if ($sum_comment > 0) {
  3301. $comment_unread_message = get_string('comment_unread', 'iassign');
  3302. if ($sum_comment == 1)
  3303. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3304. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3305. }
  3306. // $icon_comment = iassign_icons::insert('comment_unread');
  3307. if ($iassign_array[$j]->type_iassign == 3) {
  3308. if ($iassign_array[$j]->show_answer == 1) {
  3309. if ($iassign_submission->status == 3)
  3310. $icon_status = iassign_icons::insert('correct');
  3311. elseif ($iassign_submission->status == 2)
  3312. $icon_status = iassign_icons::insert('incorrect');
  3313. elseif ($iassign_submission->status == 1)
  3314. $icon_status = iassign_icons::insert('post');
  3315. elseif ($iassign_submission->status == 0)
  3316. $icon_status = iassign_icons::insert('not_post');
  3317. } // if ($iassign_array[$j]->show_answer==1)
  3318. else {
  3319. if ($iassign_submission->status == 0)
  3320. $icon_status = iassign_icons::insert('not_post');
  3321. else
  3322. $icon_status = iassign_icons::insert('post');
  3323. }
  3324. } // if ($iassign_array[$j]->type_iassign == 3)
  3325. } // if ($iassign_submission)
  3326. elseif ($iassign_array[$j]->type_iassign == 3) {
  3327. $icon_status = iassign_icons::insert('not_post');
  3328. } // if ($iassign_array[$j]->type_iassign == 3)
  3329. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3330. } // if ($iassign_array[$j]->visible == 1)
  3331. } // for ($j = 0; $j < $i; $j++)
  3332. } else if (isguestuser()) {
  3333. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3334. print '<table width=100% ><tr>' . "\n";
  3335. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3336. print '</tr></table>' . "\n";
  3337. for ($j = 0; $j < $i; $j ++) {
  3338. $icon_status = "";
  3339. $icon_comment = "";
  3340. if ($iassign_array[$j]->visible == 1) {
  3341. $iassign_current = $iassign_array[$j]->id;
  3342. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3343. print '<p>' . $links . '</p>' . "\n";
  3344. } // if ($iassign_array[$j]->visible == 1)
  3345. }
  3346. }
  3347. print $OUTPUT->box_end();
  3348. } // function show_iassign($title, $iassign_array, $i)
  3349. /// Show message of return
  3350. function return_home_course ($message) {
  3351. //D global $DB, $OUTPUT;
  3352. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3353. //D echo $OUTPUT->box_start();
  3354. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3355. //D echo '<tr><td align="left"><strong>' . "\n";
  3356. //D print_string($message, 'iassign');
  3357. //D echo '</strong></td>' . "\n";
  3358. //D echo '<td width=20% align="right">' . "\n";
  3359. //D echo $link_return;
  3360. //D echo '</td></tr></table>' . "\n";
  3361. //D echo $OUTPUT->box_end();
  3362. //D // echo $OUTPUT->footer();
  3363. redirect(new moodle_url($this->return . '&notice=' . $message));
  3364. exit;
  3365. }
  3366. /// Search comment of activity
  3367. function search_comment_submission ($iassign_submissionid) {
  3368. global $USER, $DB, $OUTPUT, $COURSE;
  3369. // $context = context_course::instance($COURSE->id);
  3370. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3371. $colorEdit2 = "#d2e5fc";
  3372. $has_capability = 0;
  3373. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3374. $text = "";
  3375. if ($comments) {
  3376. $even = 1;
  3377. foreach ($comments as $tmp) {
  3378. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3379. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3380. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3381. // $text .= $tmp->comment . "</td></tr>";
  3382. //} else {
  3383. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3384. $avatar = new user_picture($user_data);
  3385. $avatar->courseid = $COURSE->id;
  3386. $avatar->link = true;
  3387. $user_picture = $OUTPUT->render($avatar);
  3388. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3389. if ($even) {
  3390. $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";
  3391. $even = 0;
  3392. } else {
  3393. $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";
  3394. $even = 1;
  3395. }
  3396. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3397. } // foreach ($comments as $tmp)
  3398. }
  3399. return $text;
  3400. }
  3401. /// Update comment of activity
  3402. function update_comment ($iassign_submissionid) {
  3403. global $USER, $DB, $OUTPUT;
  3404. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3405. $receiver = 1; // student message to teacher
  3406. else
  3407. $receiver = 2; // teacher message to student
  3408. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3409. if ($verify_message) {
  3410. foreach ($verify_message as $message) {
  3411. if ($message->receiver == $receiver) {
  3412. $newentry = new stdClass();
  3413. $newentry->id = $message->id;
  3414. $newentry->return_status = 1;
  3415. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3416. print_error('error_update', 'iassign');
  3417. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3418. } // if ($message->receiver == $receiver)
  3419. // Trigger module viewed event.
  3420. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3421. 'objectid' => $this->iassign->id,
  3422. 'context' => $this->context
  3423. ));
  3424. $event->add_record_snapshot('course', $this->course);
  3425. $event->trigger();
  3426. } // foreach ($verify_message as $message)
  3427. }
  3428. }
  3429. /// Record comment of activity
  3430. function write_comment_submission () {
  3431. global $USER, $CFG, $DB;
  3432. $id = $this->cm->id;
  3433. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3434. $row = optional_param('row', 0, PARAM_INT);
  3435. $column = optional_param('column', 0, PARAM_INT);
  3436. $sum_comment = 0;
  3437. $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);
  3438. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3439. $str1 = trim($submission_comment);
  3440. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3441. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3442. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3443. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3444. $receiver = 1; // student message to teacher
  3445. $this->action = 'view';
  3446. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3447. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3448. } else {
  3449. $receiver = 2; // teacher message to student
  3450. $this->action = 'viewsubmission';
  3451. //D $tousers = array(); //MOOC 2016
  3452. //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
  3453. }
  3454. //MOOC 2016: foi p/ 15 linhas acima:
  3455. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3456. // verificar se existe uma submissão para o exercício e aluno informados
  3457. if (!$iassign_submission) {
  3458. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3459. }
  3460. if (!$iassign_submission) {
  3461. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3462. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3463. $this->iassign_submission_current = $id_submission;
  3464. } else {
  3465. $id_submission = $iassign_submission->id;
  3466. } // if (!$iassign_submission)
  3467. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3468. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3469. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3470. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3471. $comments = $DB->get_record_sql(
  3472. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3473. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3474. if ($comments)
  3475. foreach ($comments as $tmp)
  3476. $sum_comment = $tmp;
  3477. if ($sum_comment == 0) {
  3478. $newentry = new stdClass();
  3479. $newentry->iassign_submissionid = $id_submission;
  3480. $newentry->comment_authorid = $USER->id;
  3481. $newentry->timecreated = time();
  3482. $newentry->comment = $submission_comment;
  3483. $newentry->receiver = $receiver;
  3484. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3485. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3486. //T $eventdata = new stdClass();
  3487. //T $eventdata->component = 'mod_iassign'; //your component name
  3488. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3489. //T $eventdata->userfrom = $USER;
  3490. //T $eventdata->userto = $touser;
  3491. //T $eventdata->subject = "Teste de Subject";
  3492. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3493. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3494. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3495. //T $eventdata->smallmessage = "Teste de Mensagem";
  3496. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3497. //T // alteracao tulio faria
  3498. //T //message_send($eventdata);
  3499. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3500. // Trigger module viewed event.
  3501. $event = \mod_iassign\event\submission_comment_created::create(array(
  3502. 'objectid' => $this->iassign->id,
  3503. 'context' => $this->context
  3504. ));
  3505. $event->add_record_snapshot('course', $this->course);
  3506. $event->trigger();
  3507. }
  3508. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3509. // if ($this->action=='viewsubmission') {
  3510. // echo $OUTPUT->header();
  3511. // $this->return_last('confirm_add_comment', $link_return);
  3512. // die;
  3513. // }
  3514. return true;
  3515. } // function write_comment_submission()
  3516. /// Writes a new submission
  3517. // The first student answer is under 'function get_answer()'
  3518. function new_submission ($iassignid, $id_user, $receiver) {
  3519. global $USER, $DB, $OUTPUT;
  3520. $newentry = new stdClass();
  3521. $newentry->iassign_statementid = $iassignid;
  3522. $newentry->userid = $id_user;
  3523. $newentry->timecreated = time();
  3524. $newentry->timemodified = time();
  3525. $newentry->answer = 0; // student only submit message
  3526. if ($receiver == 2) // teacher message to student (write id teacher)
  3527. $newentry->teacher = $USER->id;
  3528. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3529. return_home_course('error_insert_submissions');
  3530. else {
  3531. // Trigger module view event
  3532. $event = \mod_iassign\event\submission_created::create(array(
  3533. 'objectid' => $this->iassign->id,
  3534. 'context' => $this->context
  3535. ));
  3536. $event->add_record_snapshot('course', $this->course);
  3537. $event->trigger();
  3538. }
  3539. return $newentry->id;
  3540. }
  3541. /// Return to a specific address of page
  3542. function return_last ($message, $link_return) {
  3543. global $DB, $OUTPUT;
  3544. print $OUTPUT->box_start();
  3545. print '<table width=100% border=0 valign="top">' . "\n";
  3546. print '<tr><td align="left"><strong>' . "\n";
  3547. print_string($message, 'iassign');
  3548. print '</strong></td>' . "\n";
  3549. print '<td width=20% align="right">' . "\n";
  3550. print $link_return;
  3551. print '</td></tr></table>' . "\n";
  3552. print $OUTPUT->box_end();
  3553. print $OUTPUT->footer();
  3554. die();
  3555. } // function return_last($message, $link_return)
  3556. } // class iassign
  3557. /// Class for manage activities
  3558. class activity {
  3559. var $activity;
  3560. /// Constructor of class.
  3561. // @param int $id Id of activity
  3562. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3563. //D public function activity($id) { self::__construct($id); }
  3564. function __construct ($id) {
  3565. global $DB;
  3566. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3567. if (empty($this->activity))
  3568. $this->activity = null;
  3569. }
  3570. /// Get an activity
  3571. // @return NULL
  3572. function get_activity () {
  3573. if ($this->activity != null)
  3574. return $this->activity;
  3575. else
  3576. return null;
  3577. }
  3578. /// Delete interactive activities
  3579. function delete ($return) {
  3580. global $USER, $CFG, $DB, $OUTPUT;
  3581. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3582. $output = $OUTPUT->header();
  3583. $output .= $OUTPUT->box_start();
  3584. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3585. if ($iassign_submission_currents) {
  3586. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3587. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3588. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3589. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3590. $output .= $OUTPUT->box_end();
  3591. $output .= $OUTPUT->footer();
  3592. print $output;
  3593. die();
  3594. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3595. } // if ($iassign_submission_currents)
  3596. else
  3597. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3598. $output .= '<table width=50% border=0>';
  3599. $output .= '<tr valign="top"><td>';
  3600. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3601. $output .= '</td><td>';
  3602. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3603. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3604. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3605. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3606. $output .= "</form>\n";
  3607. $output .= '</td><td>';
  3608. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3609. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3610. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3611. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3612. $output .= "</form>\n";
  3613. $output .= '</td></tr></table>' . "\n";
  3614. $output .= $OUTPUT->box_end();
  3615. $output .= $OUTPUT->footer();
  3616. print $output;
  3617. } // function delete($return)
  3618. /// Function for confirm the delete of activity
  3619. // @param String $return Url of return
  3620. // @param Object $iassign Object content an activity
  3621. function deleteyes ($return, $iassign) {
  3622. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3623. $msg = '';
  3624. if (!empty($this->activity->id)) {
  3625. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3626. if ($iassign_submission_currents) {
  3627. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3628. foreach ($iassign_submission_currents as $iassign_submission)
  3629. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3630. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3631. } // if ($iassign_submission_currents)
  3632. }
  3633. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3634. // Remove all files associated to this activity:
  3635. $fs = get_file_storage();
  3636. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  3637. $this->delete_calendar($this->activity->id);
  3638. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3639. iassign::update_grade_iassign($this->activity->iassignid);
  3640. if ($delete_iassign_current) {
  3641. $iassign->return_home_course('confirm_delete_iassign');
  3642. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3643. } else {
  3644. $iassign->return_home_course('error_confirm_delete_iassign');
  3645. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3646. }
  3647. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3648. }
  3649. }
  3650. /// Changes position of activities (between those inside a group of interactive activities)
  3651. // @param $move_action = must be "up" or "down"
  3652. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3653. function move_iassign ($move_action, $target, $return) {
  3654. global $DB, $OUTPUT;
  3655. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3656. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3657. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3658. if ($move_action=="firstdown") {
  3659. $final_position_source = 2;
  3660. $final_position_target = 1;
  3661. }
  3662. else
  3663. if ($move_action=="down") {
  3664. $final_position_target = $this->activity->position;
  3665. $final_position_source = $final_position_target + 1;
  3666. }
  3667. else
  3668. if ($move_action=="up") {
  3669. $final_position_target = $this->activity->position;
  3670. $final_position_source = $final_position_target - 1;
  3671. }
  3672. else { // error:
  3673. print_error('error_update_move_iassign', 'iassign');
  3674. exit;
  3675. }
  3676. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3677. $newentry->id = $this->activity->id; // ID of the "source activity"
  3678. $newentry->position = $final_position_source;
  3679. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3680. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3681. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3682. print_error('error_update_move_iassign', 'iassign');
  3683. }
  3684. else { // first update performed successfully
  3685. $newentry->id = $iassign_target->id;
  3686. $newentry->position = $final_position_target;
  3687. if (!$DB->update_record('iassign_statement', $newentry))
  3688. print_error('error_update_move_iassign', 'iassign');
  3689. }
  3690. redirect($return);
  3691. }
  3692. /// Enable or disable the display of interactive activities
  3693. function visible_iassign ($return) {
  3694. global $DB;
  3695. $newentry = new stdClass();
  3696. $newentry->id = $this->activity->id;
  3697. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3698. if (!$DB->update_record('iassign_statement', $newentry))
  3699. print_error('error_update_visible_iassign', 'iassign');
  3700. redirect($return);
  3701. }
  3702. /// Add news interactive activities (register in table 'iassign_statement')
  3703. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3704. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3705. function new_iassign ($param) {
  3706. global $DB;
  3707. $newentry = new stdClass();
  3708. $newentry->iassignid = $param->iassignid;
  3709. $newentry->name = $param->name;
  3710. $newentry->type_iassign = $param->type_iassign;
  3711. $newentry->store_all_submissions = $param->store_all_submissions;
  3712. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3713. $proposition = $param->proposition;
  3714. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3715. else $proposition_text = $proposition;
  3716. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3717. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3718. //TODO Then get it directly from the form data $_POST!
  3719. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3720. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3721. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3722. $newentry->author_name = $param->author_name;
  3723. $newentry->author_modified_name = $param->author_modified_name;
  3724. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3725. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3726. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3727. $newentry->grade = $param->grade;
  3728. $newentry->timemodified = time();
  3729. $newentry->timecreated = time();
  3730. if ($param->type_iassign == 1) {
  3731. $newentry->timedue = 0;
  3732. $newentry->timeavailable = 0;
  3733. } // if ($param->type_iassign == 1)
  3734. else {
  3735. $newentry->timedue = $param->timedue;
  3736. $newentry->timeavailable = $param->timeavailable;
  3737. }
  3738. $newentry->preventlate = $param->preventlate;
  3739. $newentry->test = $param->test;
  3740. $newentry->special_param1 = $param->special_param1;
  3741. $newentry->visible = $param->visible;
  3742. $newentry->position = $param->position;
  3743. $newentry->max_experiment = $param->max_experiment;
  3744. $newentry->dependency = $param->dependency;
  3745. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3746. $newentry->show_answer = $param->show_answer;
  3747. $id = $DB->insert_record("iassign_statement", $newentry);
  3748. if ($id) {
  3749. $component = 'mod_iassign';
  3750. $filearea = 'exercise';
  3751. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3752. $file = $fs->get_file_by_id($param->file);
  3753. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3754. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  3755. //$itemid = $id;
  3756. // File already inserted in other context!
  3757. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3758. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3759. $updateentry = new stdClass();
  3760. $updateentry->id = $id;
  3761. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3762. $updateentry->file = $newfile->get_itemid();
  3763. if (!$DB->update_record("iassign_statement", $updateentry))
  3764. print_error('error_add', 'iassign');
  3765. if ($param->type_iassign == 3)
  3766. iassign::update_grade_iassign($param->iassignid);
  3767. //TODO iLM_HTML5 :: //MOOC2014
  3768. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3769. //D if ($iassign_ilm_configs) {
  3770. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3771. //D if ($iassign_ilm_config->param_type != 'static') {
  3772. //D $newentry = new stdClass();
  3773. //D $newentry->iassign_statementid = $id;
  3774. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3775. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3776. //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});
  3777. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3778. //D print_error('error_add_param', 'iassign');
  3779. //D }
  3780. //D }
  3781. //D }
  3782. // log event --------------------------------------------------------------------------------------
  3783. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3784. // log event --------------------------------------------------------------------------------------
  3785. return $id;
  3786. }
  3787. else
  3788. print_error('error_add', 'iassign');
  3789. } // function new_iassign($param)
  3790. /// Add the calendar entries for this iassign
  3791. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3792. // @return bool
  3793. static function add_calendar ($iassignid) {
  3794. global $DB, $CFG;
  3795. require_once($CFG->dirroot . '/calendar/lib.php');
  3796. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3797. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3798. $event = new stdClass();
  3799. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3800. $event->description = $iassign_statement_activity_item->name;
  3801. $event->courseid = $iassign->course;
  3802. $event->groupid = 0;
  3803. $event->userid = 0;
  3804. $event->modulename = 'iassign';
  3805. $event->instance = $iassign->id;
  3806. $event->eventtype = 'due';
  3807. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3808. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3809. calendar_event::create($event);
  3810. }
  3811. /// Update the calendar entries for this iassign
  3812. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3813. // @return bool
  3814. function update_calendar ($iassignid, $olddescription) {
  3815. global $DB, $CFG;
  3816. require_once($CFG->dirroot . '/calendar/lib.php');
  3817. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3818. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3819. $event = new stdClass();
  3820. $event->id = 0;
  3821. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3822. if ($events) {
  3823. foreach ($events as $value) {
  3824. if ($value->description == $olddescription) {
  3825. $event->id = $value->id;
  3826. }
  3827. }
  3828. }
  3829. if ($event->id != 0) {
  3830. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3831. $event->description = $iassign_statement_activity_item->name;
  3832. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3833. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3834. $calendarevent = calendar_event::load($event->id);
  3835. $calendarevent->update($event);
  3836. } else
  3837. $this->add_calendar($iassignid);
  3838. }
  3839. /// Update the calendar entries for this iassign
  3840. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3841. // @return bool
  3842. function delete_calendar ($iassignid) {
  3843. global $DB, $CFG;
  3844. require_once($CFG->dirroot . '/calendar/lib.php');
  3845. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3846. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3847. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3848. if ($events) {
  3849. foreach ($events as $value) {
  3850. if ($value->description == $iassign_statement_activity_item->name) {
  3851. $DB->delete_records('event', array('id' => $value->id));
  3852. }
  3853. }
  3854. }
  3855. }
  3856. /// Update interactive activities
  3857. function update_iassign ($param) {
  3858. global $DB;
  3859. $component = 'mod_iassign';
  3860. $filearea = 'exercise';
  3861. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3862. $file = $fs->get_file_by_id($param->file);
  3863. $fileold = $fs->get_file_by_id($param->fileold);
  3864. if ($param->file != $param->fileold) {
  3865. if ($fileold) {
  3866. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3867. foreach ($fileoldarea as $value) {
  3868. $value->delete();
  3869. }
  3870. }
  3871. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3872. $itemid = $file->get_itemid() + $param->iassign_id;
  3873. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3874. $param->file = $newfile->get_itemid();
  3875. } else
  3876. $param->file = $file->get_itemid();
  3877. } else {
  3878. $param->file = $file->get_itemid();
  3879. }
  3880. $newentry = new stdClass();
  3881. $newentry->id = $param->iassign_id;
  3882. $newentry->name = $param->name;
  3883. $newentry->type_iassign = $param->type_iassign;
  3884. $newentry->store_all_submissions = $param->store_all_submissions;
  3885. //2019 $newentry->proposition = $param->proposition;
  3886. $proposition = $param->proposition;
  3887. if (is_array($proposition))
  3888. $proposition_text = $proposition['text'];
  3889. else
  3890. $proposition_text = $proposition;
  3891. $newentry->proposition = $proposition_text;
  3892. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3893. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3894. $newentry->grade = $param->grade;
  3895. $newentry->author_modified_name = $param->author_modified_name;
  3896. $newentry->timemodified = time();
  3897. if ($param->type_iassign == 1) {
  3898. $newentry->timedue = 0;
  3899. $newentry->timeavailable = 0;
  3900. } // if ($param->type_iassign == 1)
  3901. else {
  3902. $newentry->timedue = $param->timedue;
  3903. $newentry->timeavailable = $param->timeavailable;
  3904. }
  3905. $newentry->preventlate = $param->preventlate;
  3906. $newentry->test = $param->test;
  3907. $newentry->special_param1 = $param->special_param1;
  3908. $newentry->visible = $param->visible;
  3909. $newentry->max_experiment = $param->max_experiment;
  3910. $newentry->dependency = $param->dependency;
  3911. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3912. $newentry->show_answer = $param->show_answer;
  3913. if (!$DB->update_record("iassign_statement", $newentry))
  3914. print_error('error_update', 'iassign');
  3915. if ($param->type_iassign == 3) {
  3916. iassign::update_grade_iassign($param->iassignid);
  3917. }
  3918. //$id = $newentry->id; // MOOC 2016 --- inicio
  3919. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3920. //if ($iassign_activity_item_configs) {
  3921. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3922. // $newentry = new stdClass();
  3923. // $newentry->id = $iassign_activity_item_config->id;
  3924. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3925. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3926. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3927. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3928. // print_error('error_edit_param', 'iassign');
  3929. // }
  3930. // } // MOOC 2016 --- final
  3931. // log event --------------------------------------------------------------------------------------
  3932. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3933. // log event --------------------------------------------------------------------------------------
  3934. return $newentry->id;
  3935. // if ($param->type_iassign==3)
  3936. // $this->update_grade_iassign($param->iassignid);
  3937. } // function update_iassign($param)
  3938. /// Show information of activity
  3939. function show_info_iassign () {
  3940. global $DB, $OUTPUT;
  3941. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3942. if ($this->activity->type_iassign == 3) {
  3943. if ($this->activity->dependency == 0) {
  3944. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3945. } else {
  3946. $dependencys = explode(';', $this->activity->dependency);
  3947. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3948. foreach ($dependencys as $dependency) {
  3949. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3950. if ($dependencyiassign)
  3951. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3952. } // foreach ($dependencys as $dependency)
  3953. } // if ($iassign_statement_activity_item->dependency == 0)
  3954. if ($this->activity->max_experiment == 0)
  3955. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3956. else
  3957. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3958. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3959. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3960. print $OUTPUT->box($output);
  3961. } // function show_info_iassign()
  3962. /// Shows date of opening and closing activities
  3963. function view_dates () {
  3964. global $USER, $CFG, $DB, $OUTPUT;
  3965. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3966. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3967. $status_iassign = "";
  3968. $status_iassign1 = "";
  3969. $status_iassign2 = "";
  3970. if ($this->activity->type_iassign == 1) // activity of type example
  3971. $type_iassign = get_string('example_iassign', 'iassign');
  3972. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3973. $type_iassign = get_string('test_iassign', 'iassign');
  3974. if ($this->activity->timeavailable > time()) {
  3975. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3976. } elseif ($this->activity->timedue < time()) {
  3977. $status_iassign = get_string('last_timedue', 'iassign');
  3978. }
  3979. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3980. $type_iassign = get_string('exercise_iassign', 'iassign');
  3981. if ($this->activity->timeavailable > time()) {
  3982. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3983. } elseif ($this->activity->timedue < time()) { // after delivery
  3984. $status_iassign = get_string('last_timedue', 'iassign');
  3985. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3986. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3987. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3988. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3989. if ($this->activity->test == 1) // allowed to test after of deadline
  3990. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3991. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3992. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3993. } // elseif ($iassign_statement_activity_item->test == 0)
  3994. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3995. } // elseif ($iassign_statement_activity_item->timedue < time())
  3996. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3997. $output = '<table width=100% >' . "\n";
  3998. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3999. $output .= '<tr>' . "\n";
  4000. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4001. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4002. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4003. // leo $output .= '<td width=80%>' . $type_iassign;
  4004. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4005. // $output .= '</td>' . "\n";
  4006. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4007. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4008. $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>";
  4009. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4010. } else {
  4011. $link_next = "";
  4012. $link_previous = "";
  4013. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4014. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4015. // previous_activity
  4016. if ($iassign_previous) {
  4017. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4018. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4019. } // next_activity
  4020. if ($iassign_next) {
  4021. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4022. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4023. }
  4024. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4025. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4026. $output .= '</tr></table>' . "\n";
  4027. $output .= '<table width=100% >' . "\n";
  4028. if ($this->activity->type_iassign > 1) {
  4029. if ($this->activity->timeavailable)
  4030. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4031. if ($this->activity->timedue)
  4032. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4033. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4034. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4035. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4036. $output .= '</table>' . "\n";
  4037. print $OUTPUT->box($output);
  4038. } // function view_dates()
  4039. } // class activity
  4040. /// Class to manage Interactive Learning Module (iLM)
  4041. class ilm {
  4042. var $ilm;
  4043. /// Constructor of class
  4044. // @param int $id Id of iLM
  4045. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4046. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4047. function __construct ($id) {
  4048. global $DB;
  4049. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4050. if (empty($this->ilm))
  4051. $this->ilm = null;
  4052. }
  4053. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4054. // @calledby view_iassign_current()
  4055. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4056. global $USER, $CFG, $DB;
  4057. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4058. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4059. $typec = strtolower($iassign_ilm->type);
  4060. require_once 'ilm_handlers/' . $typec . '.php';
  4061. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4062. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4063. return $retorno;
  4064. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4065. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4066. // @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);
  4067. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4068. // @param Object $file File in use in activity
  4069. // @return int Return the id of log
  4070. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4071. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4072. $newentry = new stdClass();
  4073. $newentry->iassign_statementid = $iassign_activity_itemid;
  4074. $newentry->userid = $USER->id;
  4075. $newentry->file = $content_or_id_from_ilm_security;
  4076. $newentry->timecreated = time();
  4077. $newentry->view = 1;
  4078. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4079. if (!$id_iLM_security) {
  4080. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4081. } // from (!$DB->insert_record("iassign_security", $newentry))
  4082. return $id_iLM_security;
  4083. }
  4084. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4085. // @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);
  4086. // @param int $userid
  4087. // @param int $iassign_activity_itemid Id of iassign statement
  4088. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4089. global $DB;
  4090. // 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")
  4091. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4092. }
  4093. } // class ilm
  4094. /// Class to manage settings of iLM.
  4095. class ilm_settings {
  4096. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4097. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4098. // @param int $ilm_id Id of iLM
  4099. // @param array $options An array with options for create dynamic tag html APPLET
  4100. // @return string Return with a tag html APPLET created
  4101. static function build_ilm_tags ($ilm_id, $options = array()) {
  4102. global $DB;
  4103. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4104. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4105. $typec = strtolower($iassign_ilm->type);
  4106. require_once 'ilm_handlers/' . $typec . '.php';
  4107. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4108. return $retorno;
  4109. } // static function build_ilm_tags($ilm_id, $options = array())
  4110. /// Function for get modified date of iLM file
  4111. // @param string $file_jar String with Ids of iLM files
  4112. // @return string Return with the filenames and modified date
  4113. static function applet_filetime ($file_jar) {
  4114. $filetime = "";
  4115. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4116. $files_jar = explode(",", $file_jar);
  4117. foreach ($files_jar as $one_file) {
  4118. $file = $fs->get_file_by_id($one_file);
  4119. if ($file)
  4120. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4121. }
  4122. return $filetime;
  4123. }
  4124. /// Function for verify an default applet
  4125. // @param String $file_jar String containing an list de ids of applet files
  4126. // @return boolean Return true or fale if applet is default
  4127. static function applet_default ($file_jar) {
  4128. $is_default = true;
  4129. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4130. $files_jar = explode(",", $file_jar);
  4131. foreach ($files_jar as $one_file) {
  4132. $file = $fs->get_file_by_id($one_file);
  4133. if ($file)
  4134. $is_default &= ($file->get_itemid() == 0);
  4135. }
  4136. return $is_default;
  4137. }
  4138. /// Function for get form variables for add, edit, or copy iLM
  4139. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4140. // @see settings_form.php
  4141. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4142. // @param int $ilm_id Id of iLM
  4143. // @param string $action String with the action
  4144. // @return object Return an object with forms variables
  4145. static function add_edit_copy_ilm ($ilm_id, $action) {
  4146. global $USER, $DB, $CFG;
  4147. require_once('settings_form.php'); // put the form
  4148. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4149. $param = new stdClass();
  4150. $param->action = $action;
  4151. $param->ilm_id = $ilm_id;
  4152. $CFG->action_ilm = $action;
  4153. $CFG->ilm_id = $ilm_id;
  4154. if ($action == 'add') {
  4155. $param->title = get_string('add_ilm', 'iassign');
  4156. $param->name = "";
  4157. $param->version = "";
  4158. $param->url = "";
  4159. $param->description = "";
  4160. $param->extension = "";
  4161. $param->author = $USER->id;
  4162. $param->file_jar = "";
  4163. $param->file_jar_static = "";
  4164. $param->file_class = "";
  4165. $param->width = 800;
  4166. $param->height = 600;
  4167. $param->enable = 0; // 0 - hide / 1 - show
  4168. $param->timecreated = time();
  4169. $param->timemodified = time();
  4170. $param->evaluate = 0;
  4171. $param->parent = 0;
  4172. }
  4173. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4174. if ($iassign_ilm) {
  4175. $description = json_decode($iassign_ilm->description);
  4176. $param->title = get_string('edit_ilm', 'iassign');
  4177. $param->id = $iassign_ilm->id;
  4178. $param->name_ilm = $iassign_ilm->name;
  4179. $param->name = $iassign_ilm->name;
  4180. $param->version = $iassign_ilm->version;
  4181. $param->ilm_type = $iassign_ilm->type;
  4182. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4183. $param->url = $iassign_ilm->url;
  4184. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4185. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4186. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4187. if (!isset($description->{current_language()})) {
  4188. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4189. else
  4190. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4191. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4192. }
  4193. else
  4194. $param->description = $description->{current_language()};
  4195. $param->description_lang = $iassign_ilm->description;
  4196. $param->extension = $iassign_ilm->extension;
  4197. $param->author = $iassign_ilm->author;
  4198. $param->file_jar = $iassign_ilm->file_jar;
  4199. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4200. $param->file_class = $iassign_ilm->file_class;
  4201. $param->width = $iassign_ilm->width;
  4202. $param->height = $iassign_ilm->height;
  4203. $param->enable = $iassign_ilm->enable;
  4204. $param->timecreated = $iassign_ilm->timecreated;
  4205. $param->timemodified = time();
  4206. $param->evaluate = $iassign_ilm->evaluate;
  4207. $param->parent = $iassign_ilm->parent;
  4208. }
  4209. }
  4210. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4211. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4212. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4213. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4214. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4215. // echo "Sem dados<br/>"; exit;
  4216. return;
  4217. }
  4218. $description = json_decode($iassign_ilm->description);
  4219. if ($iassign_ilm) {
  4220. if ($iassign_ilm->parent == 0)
  4221. $iassign_ilm->parent = $ilm_id;
  4222. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4223. $param->title = get_string('new_version_ilm', 'iassign');
  4224. $param->name_ilm = $iassign_ilm->name;
  4225. $param->name = $iassign_ilm->name;
  4226. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4227. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4228. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4229. $param->ilm_type = $iassign_ilm->type;
  4230. $param->url = $iassign_ilm->url;
  4231. $param->description = $description->{current_language()};
  4232. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4233. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4234. $param->extension = $iassign_ilm->extension;
  4235. $param->author = $USER->id;
  4236. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4237. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4238. $param->file_jar_static = '';
  4239. $param->file_class = $iassign_ilm->file_class;
  4240. $param->width = $iassign_ilm->width;
  4241. $param->height = $iassign_ilm->height;
  4242. $param->enable = 0;
  4243. $param->timecreated = time();
  4244. $param->timemodified = time();
  4245. $param->evaluate = $iassign_ilm->evaluate;
  4246. $param->parent = $iassign_ilm->parent;
  4247. }
  4248. }
  4249. elseif ($action == 'copy') {
  4250. $description = json_decode($iassign_ilm->description);
  4251. if ($iassign_ilm) {
  4252. if ($iassign_ilm->parent == 0)
  4253. $iassign_ilm->parent = $ilm_id;
  4254. $param->title = get_string('copy_ilm', 'iassign');
  4255. $param->id = $iassign_ilm->id;
  4256. $param->name_ilm = $iassign_ilm->name;
  4257. $param->name = $iassign_ilm->name;
  4258. $param->version = "";
  4259. $param->ilm_type = $iassign_ilm->type;
  4260. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4261. $param->url = $iassign_ilm->url;
  4262. $param->description = $description->{current_language()};
  4263. $param->description_lang = $iassign_ilm->description;
  4264. $param->extension = $iassign_ilm->extension;
  4265. $param->author = $USER->id;
  4266. $param->file_jar = '';
  4267. $param->file_jar_static = '';
  4268. $param->file_class = $iassign_ilm->file_class;
  4269. $param->width = $iassign_ilm->width;
  4270. $param->height = $iassign_ilm->height;
  4271. $param->enable = 0;
  4272. $param->timecreated = time();
  4273. $param->timemodified = time();
  4274. $param->evaluate = $iassign_ilm->evaluate;
  4275. $param->parent = $iassign_ilm->parent;
  4276. }
  4277. }
  4278. return $param;
  4279. } // static function add_edit_copy_ilm($ilm_id, $action)
  4280. /// Function for save iLM file in moodledata
  4281. // @param int $itemid Itemid of file save in draft (upload file)
  4282. // @param int $ilm_id Id of iLM
  4283. // @return string Return an string with ids of iLM files
  4284. static function new_file_ilm ($itemid, $iassign_ilm) {
  4285. global $CFG, $USER, $DB;
  4286. $return = null;
  4287. $file_jar = array();
  4288. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4289. $contextuser = context_user::instance($USER->id);
  4290. $contextsystem = context_system::instance();
  4291. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4292. if ($files_ilm) {
  4293. foreach ($files_ilm as $value) {
  4294. // CHECK IF file is HTML type
  4295. if ($iassign_ilm->type == 1) {
  4296. // Check if the file extension is ZIP
  4297. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4298. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4299. if ((strtolower($ext) == 'zip')) {
  4300. // Coping...:
  4301. $destination = 'ilm_debug/' . $value->get_filename();
  4302. $value->copy_content_to($destination);
  4303. // Extracting content...:
  4304. $zip = new ZipArchive();
  4305. $extracted = './ilm';
  4306. $dir = "";
  4307. if ($zip->open($destination) === TRUE) {
  4308. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4309. if (is_dir($dir)) {
  4310. $i = 1;
  4311. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4312. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4313. $i ++;
  4314. }
  4315. $name = $previous . "_" . $i;
  4316. $dir = './ilm/' . $name . "/";
  4317. $j = 0;
  4318. while ($item_name = $zip->getNameIndex($j)) {
  4319. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4320. $j++;
  4321. }
  4322. $zip->close();
  4323. }
  4324. $zip->open($destination);
  4325. $zip->extractTo($extracted);
  4326. $zip->close();
  4327. // After the extraction, remove it from DEBUG
  4328. unlink($destination);
  4329. } else { // Error trying to open destination...
  4330. // After the extraction error, also remove it from DEBUG
  4331. unlink($destination);
  4332. print_error('error_add_ilm_zip', 'iassign');
  4333. }
  4334. return $dir;
  4335. }
  4336. } // if ($iassign_ilm->type == 1)
  4337. if ($value->get_filename() != '.') {
  4338. $file_ilm = array(
  4339. 'userid' => $USER->id,
  4340. 'contextid' => $contextsystem->id,
  4341. 'component' => 'mod_iassign',
  4342. 'filearea' => 'ilm',
  4343. 'itemid' => rand(1, 999999999),
  4344. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4345. 'filename' => $value->get_filename());
  4346. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4347. array_push($file_jar, $file_ilm->get_id());
  4348. }
  4349. }
  4350. if (!empty($file_jar)) {
  4351. $return = implode(",", $file_jar);
  4352. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4353. foreach ($old_file_jar as $value) {
  4354. $file = $fs->get_file_by_id($value);
  4355. if ($file)
  4356. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4357. }
  4358. }
  4359. }
  4360. else // if ($files_ilm)
  4361. $return = $iassign_ilm->file_jar;
  4362. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4363. return $return;
  4364. } // static function new_file_ilm($itemid, $iassign_ilm)
  4365. /// Function for save in database an new iLM
  4366. // @param object $param An object with iLM params
  4367. static function new_ilm ($itemid) {
  4368. global $CFG, $USER, $OUTPUT;
  4369. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4370. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4371. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4372. }
  4373. $pathtemp = $CFG->dataroot . '/temp/';
  4374. $contextuser = context_user::instance($USER->id);
  4375. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4376. $zip = new zip_packer();
  4377. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4378. foreach ($files as $file) {
  4379. if (!$file->is_directory())
  4380. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4381. }
  4382. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4383. // Verifica se o pacote possui o XML
  4384. if (!$application_xml) {
  4385. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4386. return;
  4387. } else {
  4388. $missing = "";
  4389. if (!isset($application_xml->name)) {
  4390. $missing .= "name";
  4391. }
  4392. if (!isset($application_xml->version)) {
  4393. $missing .= ", version";
  4394. }
  4395. if (!isset($application_xml->type)) {
  4396. $missing .= ", type";
  4397. }
  4398. if (!isset($application_xml->extension)) {
  4399. $missing .= ", extension";
  4400. }
  4401. if (!isset($application_xml->file_jar)) {
  4402. $missing .= ", file_jar";
  4403. }
  4404. if (!isset($application_xml->file_class)) {
  4405. $missing .= ", file_class";
  4406. }
  4407. if (!isset($application_xml->width)) {
  4408. $missing .= ", width";
  4409. }
  4410. if (!isset($application_xml->height)) {
  4411. $missing .= ", height";
  4412. }
  4413. if (!isset($application_xml->evaluate)) {
  4414. $missing .= ", evaluate";
  4415. }
  4416. if (strlen($missing) > 2) {
  4417. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4418. return;
  4419. }
  4420. }
  4421. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4422. $typec = strtolower($application_xml->type);
  4423. require_once 'ilm_handlers/' . $typec . '.php';
  4424. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4425. return $retorno;
  4426. } // static function new_ilm($itemid)
  4427. /// Function for save in database an iLM edit
  4428. // @param object $param An object with iLM params
  4429. static function edit_ilm ($param, $itemid) {
  4430. // Descobrir o tipo de iLM:
  4431. global $DB, $USER, $CFG;
  4432. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4433. $pathtemp = $CFG->dataroot . '/temp/';
  4434. $contextuser = context_user::instance($USER->id);
  4435. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4436. $zip = new zip_packer();
  4437. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4438. $files_extract = null;
  4439. foreach ($files as $file) {
  4440. if (!$file->is_directory())
  4441. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4442. }
  4443. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4444. $typec = strtolower($iassign_t->type);
  4445. require_once 'ilm_handlers/' . $typec . '.php';
  4446. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4447. }
  4448. /// Function for register the new iLM (in database and in the directory)
  4449. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4450. // @param object $param An object with iLM params
  4451. static function copy_new_version_ilm ($param) {
  4452. global $DB, $CFG, $USER;
  4453. $itemid = $param->file;
  4454. $pathtemp = $CFG->dataroot . '/temp/';
  4455. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4456. //D echo "pathtemp=$pathtemp<br/>";
  4457. $contextuser = context_user::instance($USER->id);
  4458. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4459. $zip = new zip_packer();
  4460. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4461. $files_extract = null;
  4462. foreach ($files as $file) {
  4463. if (!$file->is_directory())
  4464. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4465. }
  4466. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4467. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4468. $typec = strtolower($iassign_t->type);
  4469. require_once 'ilm_handlers/' . $typec . '.php';
  4470. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4471. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4472. } // static function copy_new_version_ilm($param)
  4473. //VER::
  4474. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4475. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4476. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4477. /// Function for change visibility of iLM
  4478. // @param int $ilm_id Id of iLM
  4479. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4480. static function visible_ilm ($ilm_id, $status) {
  4481. global $DB;
  4482. if ($status == 0)
  4483. $visible = 1;
  4484. else
  4485. $visible = 0;
  4486. $newentry = new stdClass();
  4487. $newentry->id = $ilm_id;
  4488. $newentry->enable = $visible;
  4489. if (!$DB->update_record("iassign_ilm", $newentry))
  4490. error(get_string('error_edit_ilm', 'iassign'));
  4491. }
  4492. /// Function for confirm change default iLM
  4493. // @param int $ilm_id Id of iLM
  4494. // @param int $ilm_parent Id of parent iLM
  4495. // @return string Return with an string for create default page confirmation
  4496. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4497. global $OUTPUT, $DB;
  4498. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4499. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4500. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4501. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4502. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4503. return $return;
  4504. }
  4505. /// Function for change the default iLM
  4506. // @see settings_ilm.php
  4507. // @param int $ilm_id Id of iLM
  4508. // @return int Return Id of default iLM
  4509. static function default_ilm ($ilm_id) {
  4510. global $DB;
  4511. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4512. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4513. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4514. $iassign_ilm_default->id = $iassign_ilm->id;
  4515. $iassign_ilm_default->parent = 0;
  4516. $iassign_ilm->parent = $iassign_ilm_default->id;
  4517. $iassign_ilm->id = 0;
  4518. $iassign_ilm_default->enable = 1;
  4519. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4520. print_error('error_edit_ilm', 'iassign');
  4521. }
  4522. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4523. if (!$inserted) {
  4524. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4525. print_error($msg_error);
  4526. //xx print_error('error_add_ilm', 'iassign');
  4527. }
  4528. return $iassign_ilm_default->id;
  4529. } // static function default_ilm ($ilm_id)
  4530. /// Function for confirm delete iLM
  4531. // @param int $ilm_id Id of iLM
  4532. // @param int $ilm_parent Id of parent iLM
  4533. // @return string Return with an string for create delete page confirmation
  4534. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4535. global $OUTPUT, $DB;
  4536. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4537. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4538. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4539. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4540. }
  4541. /// Function for delete directory where the iLM is allocated.
  4542. // @param string $dirPath
  4543. // @throws InvalidArgumentException
  4544. public static function delete_dir ($dirPath) {
  4545. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4546. $dirPath .= '/';
  4547. }
  4548. $files = glob($dirPath . '*', GLOB_MARK);
  4549. foreach ($files as $file) {
  4550. if (is_dir($file)) {
  4551. ilm_settings::delete_dir($file);
  4552. } else {
  4553. unlink($file);
  4554. }
  4555. }
  4556. rmdir($dirPath);
  4557. }
  4558. /// Function for delete iLM
  4559. // @param int $ilm_id Id of iLM
  4560. // @return int Return Id of parent iLM
  4561. static function delete_ilm ($ilm_id) {
  4562. global $DB;
  4563. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4564. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4565. $typec = strtolower($iassign_ilm->type);
  4566. require_once 'ilm_handlers/' . $typec . '.php';
  4567. $retorno = $typec::delete_ilm($ilm_id);
  4568. return $retorno;
  4569. }
  4570. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4571. // @param int $ilm_id Id of iLM
  4572. static function export_ilm ($ilm_id) {
  4573. global $DB;
  4574. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4575. if (!$iassign_ilm) return; // security debug...
  4576. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4577. $typec = strtolower($iassign_ilm->type);
  4578. if (!$typec) $typec = "html5"; // security debug...
  4579. require_once 'ilm_handlers/' . $typec . '.php';
  4580. $typec::export_ilm($ilm_id);
  4581. } // static function export_ilm($ilm_id)
  4582. //TODO iLM_HTML5 :: //MOOC 2016
  4583. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4584. // @param int $ilm_id Id of iLM
  4585. static function export_update_ilm ($ilm_id) {
  4586. global $DB, $CFG;
  4587. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4588. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4589. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4590. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4591. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4592. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4593. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4594. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4595. $upgrade_descriptor .= '</upgrade>' . "\n";
  4596. file_put_contents($xml_filename, $upgrade_descriptor);
  4597. header("Pragma: public");
  4598. header("Expires: 0");
  4599. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4600. header("Cache-Control: private", false);
  4601. header('Content-Type: application/xml; charset=utf-8');
  4602. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4603. header("Content-Length: " . @filesize($xml_filename));
  4604. set_time_limit(0);
  4605. @readfile("$xml_filename") || die("File not found.");
  4606. unlink($xml_filename);
  4607. exit;
  4608. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4609. /// Function for save iLM from XML descriptor
  4610. // @param array $application_xml Data of XML descriptor
  4611. // @param array $files_extract Filenames of extract files
  4612. // @return array Return an array content id of JAR files
  4613. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4614. global $CFG, $USER;
  4615. // Tratamento diferenciado se for do tipo HTML5:
  4616. $source = "";
  4617. $diretorio = "";
  4618. if (strtolower($application_xml->type) == 'html5') {
  4619. $i = 0;
  4620. foreach ($files_extract as $key => $value) {
  4621. $file = $CFG->dataroot . '/temp/' . $key;
  4622. // Verifica se já existe a pasta no diretório dos iLM:
  4623. if ($i == 0) {
  4624. $source = $file;
  4625. if (file_exists("ilm/" . basename($file))) {
  4626. $j = 1;
  4627. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4628. $j ++;
  4629. }
  4630. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4631. // mkdir($diretorio, 0777, true);
  4632. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4633. }
  4634. else {
  4635. $diretorio = 'ilm/' . basename($file);
  4636. // mkdir($diretorio, 0777, true);
  4637. mkdir($diretorio, 0755, true);
  4638. }
  4639. break;
  4640. }
  4641. $i ++;
  4642. }
  4643. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4644. if ($item->isDir()) {
  4645. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4646. }
  4647. else {
  4648. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4649. }
  4650. }
  4651. ilm_settings::delete_dir($source);
  4652. return "./" . $diretorio;
  4653. }
  4654. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4655. $file_jar = array();
  4656. $files_ilm = explode(",", $application_xml->file_jar);
  4657. $contextsystem = context_system::instance();
  4658. foreach ($files_ilm as $value) {
  4659. $file_ilm = array(
  4660. 'userid' => $USER->id,
  4661. 'contextid' => $contextsystem->id,
  4662. 'component' => 'mod_iassign',
  4663. 'filearea' => 'ilm',
  4664. 'itemid' => rand(1, 999999999),
  4665. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4666. 'filename' => $value);
  4667. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4668. array_push($file_jar, $file_ilm->get_id());
  4669. }
  4670. foreach ($files_extract as $key => $value) {
  4671. $file = $CFG->dataroot . '/temp/' . $key;
  4672. if (file_exists($file))
  4673. unlink($file);
  4674. }
  4675. return $file_jar;
  4676. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4677. /// Function for import the iLM from an package
  4678. // @param int $itemid Itemid of zip file
  4679. static function import_ilm ($itemid) {
  4680. global $CFG, $USER, $OUTPUT;
  4681. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4682. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4683. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4684. }
  4685. $pathtemp = $CFG->dataroot . '/temp/';
  4686. $contextuser = context_user::instance($USER->id);
  4687. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4688. $zip = new zip_packer();
  4689. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4690. foreach ($files as $file) {
  4691. if (!$file->is_directory())
  4692. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4693. }
  4694. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4695. // Verifica se o pacote possui o XML
  4696. if (!$application_xml) {
  4697. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4698. return;
  4699. } else {
  4700. $missing = "";
  4701. if (!isset($application_xml->name)) {
  4702. $missing .= "name";
  4703. }
  4704. if (!isset($application_xml->version)) {
  4705. $missing .= ", version";
  4706. }
  4707. if (!isset($application_xml->type)) {
  4708. $missing .= ", type";
  4709. }
  4710. if (!isset($application_xml->extension)) {
  4711. $missing .= ", extension";
  4712. }
  4713. if (!isset($application_xml->file_jar)) {
  4714. $missing .= ", file_jar";
  4715. }
  4716. if (!isset($application_xml->file_class)) {
  4717. $missing .= ", file_class";
  4718. }
  4719. if (!isset($application_xml->width)) {
  4720. $missing .= ", width";
  4721. }
  4722. if (!isset($application_xml->height)) {
  4723. $missing .= ", height";
  4724. }
  4725. if (!isset($application_xml->evaluate)) {
  4726. $missing .= ", evaluate";
  4727. }
  4728. if (strlen($missing) > 2) {
  4729. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4730. return;
  4731. }
  4732. }
  4733. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4734. $typec = strtolower($application_xml->type);
  4735. require_once 'ilm_handlers/' . $typec . '.php';
  4736. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4737. } // static function import_ilm($itemid)
  4738. /// Function for list iLM defaults
  4739. // @return string Return an string with a table of iLM
  4740. static function list_ilm () {
  4741. global $DB, $OUTPUT;
  4742. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4743. $str = '';
  4744. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4745. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4746. if ($iassign_ilm) {
  4747. foreach ($iassign_ilm as $ilm) {
  4748. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4749. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4750. $str .= '<tr><td>';
  4751. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4752. $str .= '<tr>';
  4753. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4754. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4755. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4756. $str .= '</tr>';
  4757. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4758. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4759. $str .= '</table>';
  4760. $str .= '</td></tr>';
  4761. }
  4762. }
  4763. $str .= '</table>';
  4764. return $str;
  4765. }
  4766. /// Function for download and install an upgrade of an iLM
  4767. // @param int $ilm_id Id of iLM
  4768. static function upgrade_ilm ($ilm_id) {
  4769. global $DB, $CFG, $USER;
  4770. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4771. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4772. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4773. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4774. if (!$result)
  4775. print_error('error_upgrade_ilm', 'iassign');
  4776. else {
  4777. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4778. $extension = explode(".", $zip_filename);
  4779. if ($extension[count($extension) - 1] != 'ipz') {
  4780. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4781. die;
  4782. }
  4783. $zip = new zip_packer();
  4784. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4785. $contextuser = context_user::instance($USER->id);
  4786. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4787. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4788. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4789. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4790. if (file_exists($zip_filename))
  4791. unlink($zip_filename);
  4792. if (empty($file_jar)) {
  4793. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4794. print_error($msg_error);
  4795. //xx print_error('error_add_ilm', 'iassign');
  4796. }
  4797. else {
  4798. $newentry = new stdClass();
  4799. $newentry->name = (String) $application_xml->name;
  4800. $newentry->version = (String) $application_xml->version;
  4801. $newentry->url = (String) $application_xml->url;
  4802. $newentry->description = $description_str;
  4803. $newentry->extension = strtolower((String) $application_xml->extension);
  4804. $newentry->file_jar = implode(",", $file_jar);
  4805. $newentry->file_class = (String) $application_xml->file_class;
  4806. $newentry->width = (String) $application_xml->width;
  4807. $newentry->height = (String) $application_xml->height;
  4808. $newentry->enable = 0;
  4809. $newentry->timemodified = time();
  4810. $newentry->author = $USER->id;
  4811. $newentry->timecreated = time();
  4812. $newentry->evaluate = (String) $application_xml->evaluate;
  4813. $newentry->parent = $ilm_id;
  4814. }
  4815. }
  4816. return $iassign_ilm->id;
  4817. } // static function upgrade_ilm($ilm_id)
  4818. //MOOC2014 -- inicio
  4819. //TODO: REVIEW
  4820. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4821. // static function move_iassign($ilm_id)
  4822. //MOOC2014 -- final
  4823. /// Function for list iLM versions with all informations
  4824. // @return string Return an string with a table of iLM
  4825. static function view_ilm ($ilmid, $from) {
  4826. global $DB;
  4827. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4828. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4829. $typec = strtolower($iassign_ilm->type);
  4830. require_once 'ilm_handlers/' . $typec . '.php';
  4831. $retorno = $typec::view_ilm($ilmid, $from);
  4832. return $retorno;
  4833. }
  4834. /// Function for get form variables for add, edit, or copy iLM params
  4835. // @param int $ilm_param_id Id of iLM param
  4836. // @param string $action String with the action
  4837. // @return object Return an object with forms variables
  4838. static function add_edit_copy_param ($ilm_param_id, $action) {
  4839. global $DB;
  4840. require_once('params_form.php');
  4841. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4842. $param = new stdClass();
  4843. $param->action = $action;
  4844. $param->ilm_param_id = $ilm_param_id;
  4845. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4846. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4847. $type = $iassign_ilm_config->param_type;
  4848. if ($action == 'add') {
  4849. $param->title = get_string('add_ilm', 'iassign');
  4850. $param->iassign_ilmid = $ilm_param_id;
  4851. $param->param_name = "";
  4852. $param->param_value = "";
  4853. $param->description = "";
  4854. $param->visible = 1;
  4855. }
  4856. elseif ($action == 'edit') {
  4857. if ($iassign_ilm_config) {
  4858. $param->title = get_string('edit_ilm', 'iassign');
  4859. $param->id = $iassign_ilm_config->id;
  4860. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4861. $param->param_type = $type; //MOOC2014
  4862. $param->param_name = $iassign_ilm_config->param_name;
  4863. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4864. $param->param_value = $iassign_ilm_config->param_value;
  4865. else //MOOC2014
  4866. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4867. $param->param_value = $iassign_ilm_config->param_value;
  4868. $param->description = $iassign_ilm_config->description;
  4869. $param->visible = $iassign_ilm_config->visible;
  4870. }
  4871. }
  4872. elseif ($action == 'copy') {
  4873. if ($iassign_ilm_config) {
  4874. $param->title = get_string('copy_ilm', 'iassign');
  4875. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4876. $param->param_type = $type; //MOOC2014
  4877. $param->param_name = $iassign_ilm_config->param_name;
  4878. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4879. $param->param_value = $iassign_ilm_config->param_value;
  4880. else //MOOC2014
  4881. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4882. $param->description = $iassign_ilm_config->description;
  4883. $param->visible = $iassign_ilm_config->visible;
  4884. }
  4885. }
  4886. return $param;
  4887. } // static function add_edit_copy_param($ilm_param_id, $action)
  4888. /// Function for change visibility of iLM param
  4889. // @param int $ilm_param_id Id of iLM param
  4890. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4891. static function visible_param ($ilm_param_id, $status) {
  4892. global $DB, $CFG;
  4893. if ($status == 0)
  4894. $visible = 1;
  4895. else
  4896. $visible = 0;
  4897. $newentry = new stdClass();
  4898. $newentry->id = $ilm_param_id;
  4899. $newentry->visible = $visible;
  4900. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4901. error(get_string('error_edit_param', 'iassign'));
  4902. }
  4903. /// Function for save in database an new iLM param
  4904. // @param object $param An object with iLM params
  4905. static function add_param ($param) {
  4906. global $DB;
  4907. $newentry = new stdClass();
  4908. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4909. //MOOC2014 $newentry->param_name = $param->param_name;
  4910. $newentry->param_type = $param->param_type; //MOOC2014
  4911. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4912. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4913. $newentry->param_value = $param->param_value;
  4914. else //MOOC2014
  4915. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4916. $newentry->description = $param->description;
  4917. $newentry->visible = $param->visible;
  4918. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4919. if (!$newentry->id) {
  4920. print_error('error_add_param', 'iassign');
  4921. }
  4922. }
  4923. /// Function for save in database a iLM param edit
  4924. // @param object $param An object with iLM params
  4925. static function edit_param ($param) {
  4926. global $DB;
  4927. $updentry = new stdClass();
  4928. $updentry->id = $param->id;
  4929. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4930. $updentry->param_type = $param->param_type; //MOOC2014
  4931. // $updentry->param_name = $param->param_name;
  4932. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4933. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4934. $updentry->param_value = $param->param_value;
  4935. else //MOOC2014
  4936. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4937. $updentry->description = $param->description;
  4938. $updentry->visible = $param->visible;
  4939. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4940. error(get_string('error_edit_param', 'iassign'));
  4941. }
  4942. }
  4943. /// Function for save in database a iLM param copy
  4944. // @param object $param An object with iLM params
  4945. static function copy_param ($param) {
  4946. global $DB;
  4947. $newentry = new stdClass();
  4948. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4949. //$newentry->param_name = $param->param_name;
  4950. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4951. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4952. $newentry->param_value = $param->param_value;
  4953. else //MOOC2014
  4954. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4955. $newentry->description = $param->description;
  4956. $newentry->visible = $param->visible;
  4957. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4958. if (!$newentry->id) {
  4959. print_error('error_add_param', 'iassign');
  4960. }
  4961. }
  4962. /// Function for delete iLM param of database
  4963. // @param int $param_id Id of iLM param
  4964. static function delete_param ($param_id) {
  4965. global $DB;
  4966. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4967. print_error('error_delete_param', 'iassign');
  4968. }
  4969. }
  4970. } // class ilm_settings
  4971. /// Class for manage iLM files (editor).
  4972. class ilm_manager {
  4973. var $id; // course id
  4974. var $url;
  4975. var $from;
  4976. /// Constructor for the base ilm_manager class
  4977. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4978. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4979. function __construct ($id, $url, $from) {
  4980. $this->id = $id; // course id
  4981. $this->url = $url;
  4982. $this->from = $from;
  4983. }
  4984. /// Function to get iAssign content file in Moodle data (exercise)
  4985. // @calledby x function preview_ilm($iassign_ilm) :
  4986. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4987. function get_file_ilm () {
  4988. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4989. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4990. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4991. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4992. $md_file = $fs->get_file_by_id($fileid);
  4993. $ilm_content_file = $md_file->get_content();
  4994. return $ilm_content_file;
  4995. }
  4996. /// Function for creating a new file from the iLM online editor
  4997. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4998. function ilm_editor_new () {
  4999. global $CFG, $DB, $OUTPUT, $PAGE;
  5000. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5001. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5002. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5003. $context = context_course::instance($this->id);
  5004. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5005. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5006. if (!$iassign) {
  5007. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5008. die();
  5009. }
  5010. $temp = explode(",", $iassign->extension);
  5011. $extension = $temp[0]; // default extension for this iLM
  5012. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5013. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5014. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5015. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5016. if ($stringArchiveContent != NULL) {
  5017. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5018. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5019. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5020. $filename = optional_param('filename', NULL, PARAM_RAW);
  5021. //Leo $filename = iassign_utils::format_filename($filename); //
  5022. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5023. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5024. //2019/02 $arrayfilename = explode(".", $filename);
  5025. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5026. //2019/02 $count_dots = count($arrayfilename);
  5027. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5028. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5029. //2019/02 if ($last_name != $extension)
  5030. //2019/02 $filename = $filename . '.' . $extension;
  5031. //2019/02 }
  5032. //2019/02 else { // no extension...
  5033. //2019/02 $filename = $filename . '.' . $extension;
  5034. //2019/02 }
  5035. // Store the name of recent created file
  5036. $_SESSION['file_name'] = $filename;
  5037. //$this->write_file_iassign($string, $filename);
  5038. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5039. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5040. die();
  5041. }
  5042. else { // if ($stringArchiveContent != NULL)
  5043. // iLM On-line editor
  5044. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5045. $str_get_iLM = "window.frames.iLM";
  5046. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5047. }
  5048. else { // otherwise it is JAR named 'iLM'
  5049. $str_get_iLM = "document.iLM";
  5050. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5051. }
  5052. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5053. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5054. $files_array = '';
  5055. foreach ($files as $value) {
  5056. if ($value->get_filename() != ".")
  5057. $files_array .= "'" . $value->get_filename() . "',";
  5058. }
  5059. $files_array .= "''";
  5060. $file = null;
  5061. $ia_content = "";
  5062. $filename = "";
  5063. $error_files_exists = get_string('error_file_exists', 'iassign');
  5064. $output = "<script type='text/javascript'>
  5065. //<![CDATA[
  5066. //D alert('locallib.php: ilm_editor_new');
  5067. function submit_iLM_Answer () {
  5068. var docFormOnLineEditor = document.formEnvio;
  5069. var resposta_exerc = new Array(3);
  5070. var valor_resposta = new Array(3);
  5071. var sessao = new Array(3);
  5072. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5073. resposta_exerc[0] = doc_iLM.getAnswer();
  5074. valor_resposta[0] = doc_iLM.getEvaluation();
  5075. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5076. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5077. var files = new Array(" . $files_array . ");
  5078. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5079. if (docFormOnLineEditor.filename.value=='') {
  5080. // ERROR: the file name is empty
  5081. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5082. return false;
  5083. }
  5084. // }
  5085. for (i=0; i<files.length; i++) {
  5086. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5087. alert('" . $error_files_exists . "');
  5088. return false;
  5089. }
  5090. }
  5091. docFormOnLineEditor.submit();
  5092. return true;
  5093. }
  5094. //]]>
  5095. </script>\n";
  5096. $output .= "
  5097. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5098. $output .= $OUTPUT->box_start();
  5099. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5100. $output .= "
  5101. <table width='100%' cellpadding='20'>
  5102. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5103. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5104. </tr>
  5105. </table>\n";
  5106. $output .= $OUTPUT->box_end();
  5107. $output .= "<center>\n";
  5108. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5109. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5110. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5111. $output .= $output_ilm;
  5112. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5113. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5114. </center>
  5115. </form>\n";
  5116. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5117. $PAGE->navbar->add($title);
  5118. $PAGE->set_title($title);
  5119. $PAGE->set_heading($title); // insert title above the navigation bar
  5120. print $OUTPUT->header();
  5121. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5122. print $output;
  5123. print $OUTPUT->footer();
  5124. }
  5125. die();
  5126. } // function ilm_editor_new()
  5127. /// Function for editing an file in online editor
  5128. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5129. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5130. global $CFG, $DB, $OUTPUT, $PAGE;
  5131. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5132. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5133. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5134. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5135. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5136. // If iLM is not registered, error!
  5137. if (!$iassign) {
  5138. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5139. die;
  5140. }
  5141. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5142. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5143. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5144. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5145. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5146. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5147. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5148. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5149. if ($stringArchiveContent != NULL) {
  5150. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5151. die();
  5152. } else { // if ($stringArchiveContent != NULL)
  5153. $end_file = '';
  5154. if ($content_file) {
  5155. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5156. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5157. }
  5158. $temp = explode(",", $iassign->extension);
  5159. $extension = $temp[0]; // default extension for this iLM
  5160. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5161. $str_get_iLM = "window.frames.iLM";
  5162. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5163. } else { // otherwise it is JAR named 'iLM'
  5164. $str_get_iLM = "document.iLM";
  5165. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5166. }
  5167. $output = "<script type='text/javascript'>
  5168. //<![CDATA[
  5169. function submit_iLM_Answer () {
  5170. var docFormEditor = document.formEnvio;
  5171. var activityAnswer; // to get activity answer (text)
  5172. var activityValue; // to get activity answer value (float)
  5173. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5174. //activityAnswer = doc_iLM.getAnswer();
  5175. //activityValue = doc_iLM.getEvaluation();
  5176. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5177. activityValue = " . $str_get_iLM . ".getEvaluation();
  5178. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5179. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5180. docFormEditor.submit();
  5181. return true;
  5182. }
  5183. //]]>
  5184. </script>\n";
  5185. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5186. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5187. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5188. // return true;
  5189. // }
  5190. $output .= "
  5191. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5192. $output .= $OUTPUT->box_start();
  5193. $output .= "
  5194. <table width='100%' cellpadding='20'>
  5195. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5196. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5197. <input type='hidden' name='filename' value='$filename'/></td>
  5198. <td>
  5199. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5200. </tr>
  5201. </table>\n";
  5202. $output .= $OUTPUT->box_end();
  5203. $output .= " <center>\n";
  5204. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5205. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5206. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5207. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5208. </center>
  5209. </form>\n";
  5210. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5211. $PAGE->navbar->add($title);
  5212. $PAGE->set_title($title);
  5213. $PAGE->set_heading($title); // insert title above the navigation bar
  5214. print $OUTPUT->header();
  5215. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5216. print $output;
  5217. print $OUTPUT->footer();
  5218. } // else if ($stringArchiveContent != NULL)
  5219. die();
  5220. } // function ilm_editor_update()
  5221. /// Function for write iAssign file in Moodle data (exercise)
  5222. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5223. // @param string $stringArchiveContent Content of iassign file
  5224. // @param string $filename Filename of iassign file
  5225. function write_file_iassign ($stringArchiveContent, $filename) {
  5226. global $USER;
  5227. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5228. $context = context_course::instance($this->id);
  5229. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5230. $dirid = $this->get_dir_ilm('dirid');
  5231. $dir = $fs->get_file_by_id($dirid);
  5232. $fileinfo = array('contextid' => $context->id, // ID of course
  5233. 'component' => 'mod_iassign', // usually = table name
  5234. 'filearea' => 'activity', // usually = table name
  5235. 'itemid' => 0, // usually = ID of row in table
  5236. 'filepath' => '/', // any path beginning and ending whith '/'
  5237. 'userid' => $USER->id,
  5238. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5239. 'filename' => $filename); // any filename
  5240. // Create file containing text. '$stringArchiveContent'
  5241. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5242. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5243. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5244. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5245. // 'Activité interactive enregistrée avec succès sous le nom:';
  5246. // 'Atividade interativa gravada com sucesso sob o nome:'
  5247. $output = "
  5248. <script type='text/javascript'>
  5249. //<![CDATA[
  5250. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5251. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5252. //]]>
  5253. </script>";
  5254. print $output;
  5255. die();
  5256. }
  5257. /// Function for write iAssign file in Moodle data (exercise)
  5258. // @param string $stringArchiveContent Content of iassign file
  5259. // @param string $filename Filename of iassign file
  5260. // @param int $itemid Itemid of iassign file
  5261. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5262. global $OUTPUT, $USER;
  5263. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5264. $context = context_course::instance($this->id);
  5265. $dirid = $this->get_dir_ilm('dirid');
  5266. if ($stringArchiveContent != (-1)) {
  5267. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5268. $file = $fs->get_file_by_id($fileid);
  5269. if (!$file) {
  5270. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5271. die;
  5272. }
  5273. $fileinfo = array('contextid' => $context->id, // ID of context
  5274. 'component' => 'mod_iassign', // usually = table name
  5275. 'filearea' => 'activity', // usually = table name
  5276. 'itemid' => 0, // usually = ID of row in table
  5277. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5278. 'userid' => $USER->id,
  5279. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5280. 'license' => 'allrightsreserved', // allrightsreserved
  5281. 'timecreated' => $file->get_timecreated(),
  5282. 'filename' => $file->get_filename()); // any filename
  5283. $file->delete();
  5284. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5285. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5286. }
  5287. $output = "<script type='text/javascript'>
  5288. //<![CDATA[
  5289. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5290. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5291. //]]>
  5292. </script>";
  5293. print $output;
  5294. die();
  5295. }
  5296. /// Function for create an tag for iAssign filter
  5297. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5298. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5299. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5300. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5301. // @param int $fileid Id of file
  5302. // @return string Return an string with an tag of iassign filter
  5303. function tag_ilm ($fileid) {
  5304. global $DB;
  5305. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5306. $width = '600';
  5307. $height = '400';
  5308. $file = $fs->get_file_by_id($fileid);
  5309. $filetype = explode(".", $file->get_filename());
  5310. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5311. foreach ($iassign_ilm as $value) {
  5312. $extensions = explode(",", $value->extension);
  5313. if (in_array($filetype[1], $extensions)) {
  5314. $width = $value->width;
  5315. $height = $value->height;
  5316. }
  5317. }
  5318. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5319. }
  5320. /// Function for delete iAssign file in Moodle data (exercise)
  5321. function delete_file_ilm () {
  5322. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5323. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5324. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5325. $file = $fs->get_file_by_id($fileid);
  5326. if ($file)
  5327. $file->delete();
  5328. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5329. die();
  5330. }
  5331. /// Function for delete selected iAssign file in Moodle data (exercise)
  5332. function delete_selected_ilm () {
  5333. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5334. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5335. $context = context_course::instance($this->id);
  5336. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5337. $dirid = $this->get_dir_ilm('dirid');
  5338. foreach ($files_id as $file_id) {
  5339. $file = $fs->get_file_by_id($file_id);
  5340. if ($file) {
  5341. if (!$file->is_directory())
  5342. $file->delete();
  5343. else {
  5344. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5345. foreach ($files_delete as $value)
  5346. $value->delete();
  5347. $file->delete();
  5348. }
  5349. }
  5350. }
  5351. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5352. die();
  5353. }
  5354. /// Function for duplicate iAssign file from "online" edition
  5355. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5356. function duplicate_file_ilm () {
  5357. global $USER, $COURSE;
  5358. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5359. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5360. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5361. $filename = optional_param('filename', NULL, PARAM_RAW);
  5362. $file = $fs->get_file_by_id($fileid);
  5363. $context = context_course::instance($this->id);
  5364. $fileinfo = array(
  5365. 'contextid' => $context->id, // ID of context
  5366. 'component' => 'mod_iassign', // usually = table name
  5367. 'filearea' => 'activity', // usually = table name
  5368. 'itemid' => 0, // usually = ID of row in table
  5369. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5370. 'userid' => $USER->id,
  5371. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5372. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5373. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5374. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5375. die();
  5376. }
  5377. /// Function for rename iAssign file
  5378. function rename_file_ilm () {
  5379. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5380. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5381. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5382. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5383. $file = $fs->get_file_by_id($fileid);
  5384. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5385. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5386. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5387. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5388. die();
  5389. }
  5390. /// Function for get iassign file for iassign form
  5391. function add_ilm () {
  5392. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5393. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5394. $output = "
  5395. <script type='text/javascript'>
  5396. //<![CDATA[
  5397. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5398. iassign_file_link.innerHTML = '$filename';
  5399. window.opener.document.forms['mform1'].file.value='$fileid';
  5400. window.opener.document.forms['mform1'].filename.value='$filename';
  5401. window.close();
  5402. //]]>
  5403. </script>";
  5404. print $output;
  5405. die();
  5406. }
  5407. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5408. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5409. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5410. function preview_ilm ($courseid, $iassign_ilm) {
  5411. global $OUTPUT, $CFG, $USER;
  5412. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5413. $title = get_string('modulename', 'iassign'); // iAssign
  5414. print $OUTPUT->header();
  5415. print $OUTPUT->box_start();
  5416. $javascript = "
  5417. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5418. <script type='text/javascript'>
  5419. //<![CDATA[
  5420. function submit_close () {
  5421. window.opener.location.reload();
  5422. window.close();
  5423. }
  5424. //]]>
  5425. </script>\n";
  5426. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5427. // to the complete "applet" tag
  5428. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5429. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5430. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5431. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5432. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5433. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5434. if ($ilm_name != "ivprog") {
  5435. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5436. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5437. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5438. } else {
  5439. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5440. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5441. $timecreated = time();
  5442. $token = md5($timecreated);
  5443. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5444. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5445. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5446. $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)
  5447. }
  5448. $html = "
  5449. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5450. <table border='1'>
  5451. <tr><td>
  5452. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5453. <!-- iLM calls : end -->
  5454. </td></tr>
  5455. </table>
  5456. <table>
  5457. <tr>
  5458. <td align='center'>
  5459. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5460. </td></tr>
  5461. </table>
  5462. </form>\n";
  5463. print $javascript . $html;
  5464. print $OUTPUT->box_end();
  5465. //NAO echo format_string($html); // Moodle 3.X
  5466. die();
  5467. } // function preview_ilm($courseid, $iassign_ilm)
  5468. //r_ function preview_ilm ($iassign_ilm)
  5469. //r_ /// Function for preview iassign file from iassign filter.
  5470. //r_ function preview_ilm() {
  5471. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5472. //r_ $tag_filter = $this->tag_ilm($fileid);
  5473. //r_ $javascript = "<script type='text/javascript'>
  5474. //r_ //<![CDATA[
  5475. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5476. //r_ //]]>
  5477. //r_ </script>";
  5478. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5479. //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>
  5480. //r_ </table></form></body></html>";
  5481. //r_ echo $javascript . format_text($html);
  5482. //r_ die;
  5483. //r_ }
  5484. /// Function for export an package (zip) of iassign files
  5485. function export_files_ilm () {
  5486. global $CFG;
  5487. $context = context_course::instance($this->id);
  5488. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5489. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5490. $zip = new zip_archive();
  5491. $zip->open($zip_filename);
  5492. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5493. foreach ($files_id as $file_id) {
  5494. $file = $fs->get_file_by_id($file_id);
  5495. if (!$file->is_directory())
  5496. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5497. else {
  5498. $zip->add_directory($file->get_filepath());
  5499. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5500. foreach ($files_zip as $value) {
  5501. if (!$value->is_directory())
  5502. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5503. else
  5504. $zip->add_directory($value->get_filepath());
  5505. }
  5506. }
  5507. }
  5508. $zip->close();
  5509. header("Pragma: public");
  5510. header("Expires: 0");
  5511. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5512. header("Cache-Control: private", false);
  5513. header("Content-Type: application/zip");
  5514. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5515. header("Content-Transfer-Encoding: binary");
  5516. header("Content-Length: " . @filesize($zip_filename));
  5517. set_time_limit(0);
  5518. @readfile("$zip_filename") || die("File not found.");
  5519. unlink($zip_filename);
  5520. exit;
  5521. }
  5522. /// Function of execute a command in button editor tinymce
  5523. // @param int $fileid Id of file
  5524. function tinymce_ilm ($fileid) {
  5525. $tag_filter = $this->tag_ilm($fileid);
  5526. $output = "<script type='text/javascript'>
  5527. //<![CDATA[
  5528. var tag_filter = '$tag_filter';
  5529. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5530. // all right, insert it
  5531. } else {
  5532. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5533. }
  5534. // window.close();
  5535. //]]>
  5536. </script>\n";
  5537. print $output;
  5538. die();
  5539. }
  5540. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5541. /// Function to add content to the Editor Window
  5542. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5543. // @param int $fileid Id of file
  5544. function editor_ilm ($fileid, $editor) {
  5545. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5546. $output1 = "<script type='text/javascript'>
  5547. //<![CDATA[
  5548. var tag_filter = '$tag_filter';\n";
  5549. if ($editor == 'atto') {
  5550. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5551. } elseif ($editor == 'tinyMCE') {
  5552. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5553. } else
  5554. $output2 = "";
  5555. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5556. window.close();
  5557. //]]>
  5558. </script>\n";
  5559. //D var_dump($output);
  5560. print $output1 . $output2 . $output3;
  5561. die();
  5562. }
  5563. /// Function to add content to the Atto Editor Window
  5564. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5565. // @param int $fileid Id of file
  5566. function atto_ilm ($fileid) {
  5567. global $CFG, $DB;
  5568. $tag_filter = $this->tag_ilm($fileid);
  5569. $output = "<script type='text/javascript'>
  5570. //<![CDATA[
  5571. var tag_filter = '$tag_filter';
  5572. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5573. // all right, insert iLM tag to this editor
  5574. } else {
  5575. // error trying to insert
  5576. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5577. }
  5578. //window.close();
  5579. //]]>
  5580. </script>\n";
  5581. print $output;
  5582. die();
  5583. }
  5584. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5585. // @param string $key Key for return information
  5586. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5587. function get_dir_ilm ($key) {
  5588. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5589. $context = context_course::instance($this->id);
  5590. $dirid = optional_param('dirid', 0, PARAM_INT);
  5591. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5592. if ($dirid == 0) {
  5593. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5594. $dirid = $dir->get_id();
  5595. }
  5596. else {
  5597. $dir = $fs->get_file_by_id($dirid);
  5598. $dir_base = $dir->get_filepath();
  5599. }
  5600. $dir_parent = $dir->get_parent_directory();
  5601. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5602. return $data[$key];
  5603. }
  5604. /// Function for create an new dir
  5605. function new_dir_ilm () {
  5606. global $USER;
  5607. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5608. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5609. $dir_base = $this->get_dir_ilm('dir_base');
  5610. $context = context_course::instance($this->id);
  5611. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5612. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5613. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5614. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5615. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5616. }
  5617. /// Function for delete an dir
  5618. function delete_dir_ilm () { //
  5619. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5620. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5621. $context = context_course::instance($this->id);
  5622. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5623. $dir_parent = $this->get_dir_ilm('dir_parent');
  5624. if ($dir) {
  5625. if ($dir->is_directory()) {
  5626. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5627. foreach ($files_delete as $value)
  5628. $value->delete();
  5629. $dir->delete();
  5630. }
  5631. }
  5632. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5633. die();
  5634. }
  5635. /// Function for rename an dir
  5636. function rename_dir_ilm () {
  5637. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5638. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5639. $context = context_course::instance($this->id);
  5640. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5641. $dir_parent = $this->get_dir_ilm('dir_parent');
  5642. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5643. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5644. if ($dir->is_directory()) {
  5645. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5646. foreach ($files_rename_path as $value)
  5647. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5648. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5649. }
  5650. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5651. die();
  5652. }
  5653. /// Function for move an dir and your content for other dir
  5654. function selected_move_ilm () {
  5655. global $PAGE, $OUTPUT, $CFG;
  5656. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5657. $context = context_course::instance($this->id);
  5658. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5659. $dirid = $this->get_dir_ilm('dirid');
  5660. $dir_base = $this->get_dir_ilm('dir_base');
  5661. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5662. $code_javascript_ilm = "
  5663. <script type='text/javascript'>
  5664. //<![CDATA[
  5665. function getRadiobutton () {
  5666. var radioButtons = document.getElementsByTagName('input');
  5667. var param = '';
  5668. for (var counter=0; counter < radioButtons.length; counter++) {
  5669. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5670. param = radioButtons[counter].value;
  5671. }
  5672. return param;
  5673. }
  5674. function move_selected_ilm () {
  5675. var msgAnswer;
  5676. if (getRadiobutton() != '') {
  5677. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5678. if (msgAnswer)
  5679. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5680. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5681. }
  5682. else
  5683. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5684. }
  5685. function cancel_selected_ilm () {
  5686. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5687. }
  5688. //]]>
  5689. </script>\n";
  5690. $title = get_string('move_files', 'iassign');
  5691. $PAGE->set_title($title);
  5692. $PAGE->set_pagelayout('base');
  5693. print $OUTPUT->header();
  5694. print $OUTPUT->heading($title);
  5695. $dir_paths = array();
  5696. print $OUTPUT->box_start();
  5697. print "<center>";
  5698. foreach ($files_id as $file_id) {
  5699. $file = $fs->get_file_by_id($file_id);
  5700. if ($file) {
  5701. if (!$file->is_directory())
  5702. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5703. else {
  5704. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5705. array_push($dir_paths, $file->get_filepath());
  5706. }
  5707. }
  5708. }
  5709. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5710. if ($dir_base != '/') {
  5711. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5712. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5713. }
  5714. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5715. foreach ($files_tree as $file) {
  5716. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5717. $is_parent = false;
  5718. foreach ($dir_paths as $dir) {
  5719. $path = explode("/", $dir);
  5720. array_pop($path);
  5721. $path[count($path) - 1] = '';
  5722. $path = implode("/", $path);
  5723. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5724. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5725. }
  5726. if ($is_parent == false) {
  5727. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5728. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5729. }
  5730. }
  5731. }
  5732. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5733. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5734. print "</center>";
  5735. print $OUTPUT->box_end();
  5736. print $OUTPUT->footer();
  5737. print $code_javascript_ilm;
  5738. die;
  5739. }
  5740. /// Function for move files for an dir
  5741. function move_files_ilm () {
  5742. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5743. $context = context_course::instance($this->id);
  5744. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5745. $dirid = $this->get_dir_ilm('dirid');
  5746. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5747. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5748. foreach ($files_id as $file_id) {
  5749. $file = $fs->get_file_by_id($file_id);
  5750. if ($file) {
  5751. if ($file->is_directory()) {
  5752. $pathname = explode("/", $file->get_filepath());
  5753. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5754. foreach ($files_move_path as $value) {
  5755. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5756. $value->rename($path_move, $value->get_filename());
  5757. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5758. }
  5759. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5760. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5761. $file->rename($path_move, $file->get_filename());
  5762. } else {
  5763. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5764. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5765. }
  5766. }
  5767. }
  5768. //die;
  5769. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5770. die();
  5771. } // function move_files_ilm()
  5772. /// Function for recover files in use on all activities of a course
  5773. function recover_files_ilm () {
  5774. global $DB, $USER;
  5775. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5776. $courseid = optional_param('id', NULL, PARAM_INT);
  5777. $dirid = $this->get_dir_ilm('dirid');
  5778. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5779. $contextfile = context_course::instance($this->id);
  5780. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5781. foreach ($iassigns as $iassign) {
  5782. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5783. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5784. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5785. $context = context_module::instance($cm->id);
  5786. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5787. if ($files) {
  5788. foreach ($files as $value) {
  5789. $extension = explode(".", $value->get_filename());
  5790. if (!$value->is_directory()) {
  5791. $fileinfo = array('contextid' => $contextfile->id,
  5792. 'component' => 'mod_iassign',
  5793. 'filearea' => 'activity',
  5794. 'itemid' => 0,
  5795. 'filepath' => $this->get_dir_ilm('dir_base'),
  5796. 'userid' => $USER->id,
  5797. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5798. 'license' => 'allrightsreserved',
  5799. 'timecreated' => time(),
  5800. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5801. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5802. }
  5803. }
  5804. } // if ($files)
  5805. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5806. } // foreach ($iassigns as $iassign)
  5807. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5808. die();
  5809. } // function recover_files_ilm()
  5810. /// Auxiliary function the get all files in a given context
  5811. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5812. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5813. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5814. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5815. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5816. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5817. // (NAO s_iassign_statement.file = s_files.id)
  5818. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5819. $dir_base = $this->get_dir_ilm('dir_base');
  5820. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5821. $countf = 0;
  5822. $array_files_id = array(); // all files from this context
  5823. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5824. //$filename = $item_fc->get_filename();
  5825. //$filepath = $item_fc->get_filepath();
  5826. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5827. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5828. // $array_files_aux[] = $item_fc;
  5829. $itemid = $item_fc->get_id();
  5830. if (!in_array($itemid, $array_files_id)) {
  5831. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5832. if ($fileuserid == $userid)
  5833. $filesfrommine[] = $item_fc;
  5834. else
  5835. $filesfromothers[] = $item_fc;
  5836. $array_files_id[] = $itemid;
  5837. $countf++;
  5838. }
  5839. }
  5840. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5841. return $countf;
  5842. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5843. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5844. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5845. function get_all_ilm_files_by_fileid ($fileid) {
  5846. global $DB, $USER;
  5847. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5848. //TODO Criar coluna 'authorid'
  5849. $str_query = "SELECT * FROM {iassign_statement} " .
  5850. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5851. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5852. return $array_iassign_ilm;
  5853. }
  5854. //NN
  5855. //NN
  5856. // Build string with JavaScript code with function to edit/remove/double iLM files
  5857. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5858. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5859. global $CFG;
  5860. $error_files_exists = get_string('error_file_exists', 'iassign');
  5861. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5862. $code_javascript_ilm = "
  5863. <script type='text/javascript'>
  5864. //<![CDATA[
  5865. function preview_ilm (fileid, ilmid) { //JavaScript function
  5866. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5867. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5868. }
  5869. function update_ilm (ilmid, fileid) { //JavaScript function
  5870. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5871. }
  5872. function delete_ilm (ilmid, fileid) { //JavaScript function
  5873. var msgAnswer;
  5874. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5875. if (msgAnswer) {
  5876. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5877. }
  5878. }
  5879. function delete_selected_ilm () { //JavaScript function
  5880. var msgAnswer;
  5881. var param = getCheckbox();
  5882. if (param.join() != '') {
  5883. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5884. if (msgAnswer)
  5885. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5886. }
  5887. else
  5888. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5889. }
  5890. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5891. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5892. }
  5893. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5894. var filenamecopy;
  5895. var i;
  5896. var files = new Array(" . $files_array . ");
  5897. do {
  5898. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5899. } while (filenamecopy == '');
  5900. if (filenamecopy == null)
  5901. return false;\n
  5902. else {
  5903. for (i=0;i<files.length;i++) {
  5904. if (files[i]==filenamecopy) {
  5905. alert('" . $error_files_exists . "');
  5906. return false;\n
  5907. }
  5908. }\n" .
  5909. // @see: function 'duplicate_file_ilm()' above
  5910. "
  5911. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5912. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5913. } // else
  5914. }
  5915. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5916. var filenamecopy;
  5917. var i;
  5918. var files = new Array($files_array);
  5919. do {
  5920. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5921. } while (filenamecopy == '');
  5922. if (filenamecopy == null)
  5923. return false;
  5924. else {
  5925. for (i=0;i<files.length;i++) {
  5926. if (files[i]==filenamecopy) {
  5927. alert('" . $error_files_exists . "');
  5928. return false;
  5929. }
  5930. }
  5931. 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;
  5932. }
  5933. }
  5934. function export_files_ilm () { //JavaScript function
  5935. var param = getCheckbox();
  5936. if (param.join() != '')
  5937. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5938. else
  5939. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5940. }
  5941. function select_all_ilm () { //JavaScript function
  5942. var checkBoxes = document.getElementsByTagName('input');
  5943. var selectAll = document.getElementById('select_all');
  5944. for (var counter=0; counter < checkBoxes.length; counter++) {
  5945. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5946. checkBoxes[counter].checked = selectAll.checked;
  5947. }
  5948. }
  5949. function getCheckbox () { //JavaScript function
  5950. var checkBoxes = document.getElementsByTagName('input');
  5951. var param = new Array();
  5952. for (var counter=0; counter < checkBoxes.length; counter++) {
  5953. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5954. param.push(checkBoxes[counter].value);
  5955. }
  5956. return param;
  5957. }
  5958. function new_dir_ilm () { //JavaScript function
  5959. var dirname = '';
  5960. var i;
  5961. var dirs = new Array(" . $dirs_array . ");
  5962. do {
  5963. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5964. } while (dirname == '');
  5965. if (dirname == null)
  5966. return false;\n
  5967. else {
  5968. for (i=0;i<dirs.length;i++) {
  5969. if (dirs[i]==dirname) {
  5970. alert('" . $error_dir_exists . "');
  5971. return false;\n
  5972. }
  5973. }
  5974. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5975. }
  5976. }
  5977. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5978. var msgAnswer;
  5979. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5980. if (msgAnswer) {
  5981. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5982. }
  5983. }
  5984. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5985. var dirnamecopy;
  5986. var i;
  5987. var dirs = new Array($dirs_array);
  5988. do {
  5989. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5990. } while (dirnamecopy == '');
  5991. if (dirnamecopy == null)
  5992. return false;\n
  5993. else {
  5994. for (i=0;i<dirs.length;i++) {
  5995. if (dirs[i]==dirnamecopy) {
  5996. alert('" . $error_dir_exists . "');
  5997. return false;\n
  5998. }
  5999. }
  6000. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6001. }
  6002. }
  6003. function move_selected_ilm (ilmid) { //JavaScript function
  6004. var param = getCheckbox();
  6005. if (param.join() != '')
  6006. 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();
  6007. else
  6008. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6009. }
  6010. function recover_files_ilm () { //JavaScript function
  6011. var msgAnswer;
  6012. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6013. if (msgAnswer) {
  6014. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6015. }
  6016. }
  6017. window.onload = function() { //JavaScript function
  6018. var xPosition = 0;
  6019. var yPosition = 0;
  6020. element=document.getElementById('new_file');
  6021. while(element) {
  6022. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6023. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6024. element = element.offsetParent;
  6025. }
  6026. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6027. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6028. location.hash = '#new_file';
  6029. };
  6030. //]]>
  6031. </script>\n"; // end of $code_javascript_ilm
  6032. return $code_javascript_ilm;
  6033. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6034. /// List iassign files from course directory
  6035. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6036. function view_files_ilm ($iassign_ilm_class, $extension) {
  6037. global $CFG, $DB, $USER, $OUTPUT;
  6038. $fs = get_file_storage();
  6039. $context = context_course::instance($this->id);
  6040. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6041. $dirid = $this->get_dir_ilm('dirid');
  6042. $dir_base = $this->get_dir_ilm('dir_base');
  6043. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6044. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6045. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6046. $files_array = '';
  6047. foreach ($files_course as $value) {
  6048. if (!$value->is_directory())
  6049. $files_array .= "'" . $value->get_filename() . "',";
  6050. }
  6051. $files_array .= "''";
  6052. $error_files_exists = get_string('error_file_exists', 'iassign');
  6053. $dirs_array = '';
  6054. foreach ($files_course as $value) {
  6055. if ($value->is_directory()) {
  6056. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6057. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6058. }
  6059. }
  6060. $dirs_array .= "''";
  6061. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6062. // TODO Rever o preview pois só deixar ver uma vez.
  6063. $code_javascript_ilm = "
  6064. <script type='text/javascript'>
  6065. //<![CDATA[
  6066. function preview_ilm (fileid, ilmid) {
  6067. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6068. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6069. }
  6070. function update_ilm (ilmid, fileid) {
  6071. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6072. }
  6073. function delete_ilm (ilmid, fileid) {
  6074. var msgAnswer;
  6075. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6076. if (msgAnswer) {
  6077. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6078. }
  6079. }
  6080. function delete_selected_ilm () {
  6081. var msgAnswer;
  6082. var param = getCheckbox();
  6083. if (param.join() != '') {
  6084. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6085. if (msgAnswer)
  6086. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6087. }
  6088. else
  6089. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6090. }
  6091. function add_ilm_iassign (ilmid, filename, fileid) {
  6092. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6093. }
  6094. function duplicate_ilm (ilmid, filename, fileid) {
  6095. var filenamecopy;
  6096. var i;
  6097. var files = new Array($files_array);
  6098. do {
  6099. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6100. } while (filenamecopy == '');
  6101. if (filenamecopy == null)
  6102. return false;\n
  6103. else {
  6104. for (i=0;i<files.length;i++) {
  6105. if (files[i]==filenamecopy) {
  6106. alert('$error_files_exists');
  6107. return false;\n
  6108. }
  6109. }\n" .
  6110. // @see: function 'duplicate_file_ilm()' above
  6111. "
  6112. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6113. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6114. } // else
  6115. }
  6116. function rename_ilm (ilmid, filename, fileid) {
  6117. var filenamecopy;
  6118. var i;
  6119. var files = new Array($files_array);
  6120. do {
  6121. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6122. } while (filenamecopy == '');
  6123. if (filenamecopy == null)
  6124. return false;
  6125. else {
  6126. for (i=0;i<files.length;i++) {
  6127. if (files[i]==filenamecopy) {
  6128. alert('$error_files_exists');
  6129. return false;
  6130. }
  6131. }
  6132. 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;
  6133. }
  6134. }
  6135. function export_files_ilm () {
  6136. var param = getCheckbox();
  6137. if (param.join() != '')
  6138. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6139. else
  6140. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6141. }
  6142. function select_all_ilm () {
  6143. var checkBoxes = document.getElementsByTagName('input');
  6144. var selectAll = document.getElementById('select_all');
  6145. for (var counter=0; counter < checkBoxes.length; counter++) {
  6146. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6147. checkBoxes[counter].checked = selectAll.checked;
  6148. }
  6149. }
  6150. function getCheckbox () {
  6151. var checkBoxes = document.getElementsByTagName('input');
  6152. var param = new Array();
  6153. for (var counter=0; counter < checkBoxes.length; counter++) {
  6154. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6155. param.push(checkBoxes[counter].value);
  6156. }
  6157. return param;
  6158. }
  6159. function new_dir_ilm () {
  6160. var dirname = '';
  6161. var i;
  6162. var dirs = new Array($dirs_array);
  6163. do {
  6164. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6165. } while (dirname == '');
  6166. if (dirname == null)
  6167. return false;\n
  6168. else {
  6169. for (i=0;i<dirs.length;i++) {
  6170. if (dirs[i]==dirname) {
  6171. alert('$error_dir_exists');
  6172. return false;\n
  6173. }
  6174. }
  6175. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6176. }
  6177. }
  6178. function delete_dir_ilm (ilmid, dirid) {
  6179. var msgAnswer;
  6180. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6181. if (msgAnswer) {
  6182. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6183. }
  6184. }
  6185. function rename_dir_ilm (ilmid, dirname, dirid) {
  6186. var dirnamecopy;
  6187. var i;
  6188. var dirs = new Array($dirs_array);
  6189. do {
  6190. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6191. } while (dirnamecopy == '');
  6192. if (dirnamecopy == null)
  6193. return false;\n
  6194. else {
  6195. for (i=0;i<dirs.length;i++) {
  6196. if (dirs[i]==dirnamecopy) {
  6197. alert('$error_dir_exists');
  6198. return false;\n
  6199. }
  6200. }
  6201. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6202. }
  6203. }
  6204. function move_selected_ilm (ilmid) {
  6205. var param = getCheckbox();
  6206. if (param.join() != '')
  6207. 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();
  6208. else
  6209. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6210. }
  6211. function recover_files_ilm () {
  6212. var msgAnswer;
  6213. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6214. if (msgAnswer) {
  6215. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6216. }
  6217. }
  6218. window.onload = function() {
  6219. var xPosition = 0;
  6220. var yPosition = 0;
  6221. element=document.getElementById('new_file');
  6222. while(element) {
  6223. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6224. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6225. element = element.offsetParent;
  6226. }
  6227. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6228. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6229. location.hash = '#new_file';
  6230. };
  6231. //]]>
  6232. </script>\n";
  6233. $output = "";
  6234. $select_all = "";
  6235. $count_files = 0;
  6236. $extensions_allow = array();
  6237. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6238. foreach ($iassign_ilm as $item_iassign_ilm)
  6239. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6240. foreach ($files_course as $value) {
  6241. $filename = $value->get_filename();
  6242. $filepath = $value->get_filepath();
  6243. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6244. $pathname = $pathname[count($pathname) - 1];
  6245. $fileid = $value->get_id();
  6246. $tmp = explode(".", $filename);
  6247. if (count($tmp)>1) // avoid error if the file has no extension
  6248. $filetype = $tmp[1];
  6249. else // probably error...
  6250. $filetype = '';
  6251. $author = $value->get_author();
  6252. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6253. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6254. $extensions = explode(",", $extension);
  6255. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6256. $count_files ++;
  6257. // buscar fileid nas tabelas do iassign
  6258. $list_filein_use = "";
  6259. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6260. if ($iassign_statement_activity_list) {
  6261. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6262. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6263. }
  6264. }
  6265. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6266. if (!$iassign_ilm) {
  6267. $iassign_ilm = new stdClass();
  6268. $iassign_ilm->id = $ilmid;
  6269. }
  6270. // Do not use $var inside "..." - problem with some "unusual" operational system
  6271. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6272. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6273. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6274. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6275. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6276. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6277. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6278. $check_select = "";
  6279. $link_rename = "";
  6280. $link_delete = "";
  6281. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6282. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6283. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6284. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6285. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6286. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6287. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6288. if ($value->get_userid() == $USER->id) {
  6289. if ($iassign_statement_activity_list) {
  6290. $check_select = "";
  6291. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6292. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6293. $link_rename = "";
  6294. } else {
  6295. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6296. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6297. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6298. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6299. }
  6300. }
  6301. if (!in_array($filetype, $extensions_allow)) {
  6302. $link_edit = "";
  6303. $link_add_ilm_iassign = "";
  6304. $link_add_ilm_tinymce = "";
  6305. $link_add_ilm_atto = "";
  6306. $link_filter = "";
  6307. }
  6308. if ($value->is_directory()) {
  6309. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6310. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6311. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6312. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6313. <td><center>$author</center></td>
  6314. <td><center>$timecreated</center></td>
  6315. <td><center>$timemodified</center></td></tr>\n";
  6316. }
  6317. else if ($this->from == 'iassign') {
  6318. $new_id = "";
  6319. $new_class = "";
  6320. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6321. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6322. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6323. }
  6324. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6325. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6326. <td><center>$author</center></td>
  6327. <td><center>$timecreated</center></td>
  6328. <td><center>$timemodified</center></td></tr>\n";
  6329. }
  6330. else if ($this->from == 'block') {
  6331. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6332. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6333. <td><center>$author</center></td>
  6334. <td><center>$timecreated</center></td>
  6335. <td><center>$timemodified</center></td></tr>\n";
  6336. }
  6337. else if ($this->from == 'tinymce') {
  6338. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6339. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6340. <td><center>$author</center></td>
  6341. <td><center>$timecreated</center></td>
  6342. <td><center>$timemodified</center></td></tr>\n";
  6343. }
  6344. else if ($this->from == 'atto') {
  6345. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6346. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6347. <td><center>$author</center></td>
  6348. <td><center>$timecreated</center></td>
  6349. <td><center>$timemodified</center></td></tr>\n";
  6350. }
  6351. }
  6352. }
  6353. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6354. $dir_base = "";
  6355. $header = "";
  6356. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6357. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6358. foreach ($basename as $value) {
  6359. $dir_base .= $value . "/";
  6360. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6361. if ($dir_id) {
  6362. if ($value == "") {
  6363. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6364. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6365. } else {
  6366. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6367. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6368. }
  6369. }
  6370. } // foreach ($basename as $value)
  6371. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6372. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6373. $html .= "
  6374. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6375. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6376. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6377. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6378. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6379. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6380. </table>\n";
  6381. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6382. $html .= "<table width='100%'><tr>\n";
  6383. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6384. if ($count_files != 0) {
  6385. $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";
  6386. $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";
  6387. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6388. }
  6389. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6390. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6391. $html .= "</form>\n";
  6392. print $code_javascript_ilm;
  6393. print $html;
  6394. } // function view_files_ilm($extension)
  6395. } // class ilm_manager
  6396. /// Class to insert of icons
  6397. class iassign_icons {
  6398. static function insert ($icon) {
  6399. global $CFG;
  6400. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6401. return $string;
  6402. }
  6403. }
  6404. /// Class with util functions for plugin manage
  6405. class iassign_utils {
  6406. /// Function to return the filename extension
  6407. // @param string The $filename as an string
  6408. // @return string Return an string (last group after '.')
  6409. static function filename_extension ($filename) {
  6410. if ($filename == null || $filename == '') {
  6411. return null;
  6412. }
  6413. $itens = explode('.', $filename);
  6414. $num = count($itens);
  6415. if ($num < 2) {
  6416. return null;
  6417. }
  6418. return $itens[$num - 1];
  6419. }
  6420. /// Use the PHP class/package ZipArchive to create a Zip file
  6421. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6422. // 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
  6423. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6424. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6425. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6426. $zip = new zip_archive(); //2
  6427. $res = $zip->open($full_path_zip_filename);
  6428. $total_vet = count($vet_student_filename);
  6429. for ($ii=0; $ii<$total_vet; $ii++) {
  6430. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6431. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6432. }
  6433. $ret = $zip->close();
  6434. iassign_utils::download_file($full_path_zip_filename);
  6435. $filenameZip = $zip->filename;
  6436. return array($ret, $zip);
  6437. }
  6438. static function download_file ($zip_filename) {
  6439. header("Pragma: public");
  6440. header("Expires: 0");
  6441. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6442. header("Cache-Control: private", false);
  6443. header("Content-Type: application/zip");
  6444. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6445. header("Content-Transfer-Encoding: binary");
  6446. header("Content-Length: " . @filesize($zip_filename));
  6447. set_time_limit(0);
  6448. @readfile("$zip_filename") || die("File not found.");
  6449. unlink($zip_filename);
  6450. }
  6451. /// Function for format filename remove special caracters
  6452. // @param string $text String for clean
  6453. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6454. // @return string Return an string in clean format
  6455. static function format_filename ($text) {
  6456. if ($text != '.') {
  6457. //D $text = htmlspecialchars(urldecode($text));
  6458. //D echo "locallib.php: format_filename: $text<br/>";
  6459. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6460. $text = json_decode($text)->{current_language()};
  6461. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6462. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6463. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6464. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6465. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6466. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6467. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6468. // E.g. text = "exerc_midpoint.course.geo"
  6469. // 0123456789012345678901234
  6470. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6471. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6472. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6473. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6474. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6475. //$ext = strrpos($text, ".");
  6476. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6477. //$text = str_replace($array1, $array2, $text);
  6478. }
  6479. return $text;
  6480. }
  6481. /// Function to filter characters to the file name to iLM content
  6482. // @param string $text String for clean
  6483. // @param string $ext String ot the extension of the iLM
  6484. // @return string Return an string in clean format
  6485. static function filter_filename_extension ($filename, $ext) {
  6486. if ($filename != '.') {
  6487. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6488. $arrTo = array("_","","","","","","","","","","","","");
  6489. $filename = str_replace($arrFrom, $arrTo, $filename);
  6490. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6491. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6492. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6493. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6494. $index_lastposition = strlen($filenameF);
  6495. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6496. $text = str_replace(".", "_", $text); // erase all other "."
  6497. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6498. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6499. }
  6500. else
  6501. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6502. return $filenameF;
  6503. }
  6504. /// Function for format pathname remove special caracters
  6505. // @param string $text String for clean
  6506. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6507. // @return string Return an string in clean format
  6508. static function format_pathname ($text, $is_lowercase = true) {
  6509. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6510. $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", "-", "_", "", "", "");
  6511. $text = str_replace($array1, $array2, $text);
  6512. if ($is_lowercase)
  6513. $text = strtolower($text);
  6514. return $text;
  6515. }
  6516. /// Function for format file name from iLM original name
  6517. // @param string $text String to build the file neam
  6518. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6519. // @return string Return an string in clean format
  6520. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6521. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6522. $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", "-", "_", "", "", "");
  6523. $index_firstposition_blank = strpos($ilm_name, " ");
  6524. if ($index_firstposition_blank) { // truncate the name!
  6525. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6526. }
  6527. $index_firstposition_dots = strpos($ilm_name, ":");
  6528. if ($index_firstposition_dots) { // truncate the name!
  6529. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6530. }
  6531. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6532. if ($is_lowercase)
  6533. $namefiltered = strtolower($namefiltered);
  6534. return $namefiltered;
  6535. }
  6536. /// Function for insert version in the filename
  6537. // @param string $filename Name of file
  6538. // @return string Return the filename with version
  6539. static function version_filename ($filename) {
  6540. $array_filename = explode('.', $filename);
  6541. if (count($array_filename) > 1)
  6542. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6543. else
  6544. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6545. return $filename;
  6546. }
  6547. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6548. static function remove_code_message ($string) {
  6549. $array = explode("&lt;ia_uc&gt;", $string);
  6550. return $array[0];
  6551. }
  6552. }
  6553. // class iassign_utils
  6554. /// Class with language functions for plugin manage
  6555. class iassign_language {
  6556. /// Function for return text in language or get default language (en)
  6557. // @param string $lang Code of language
  6558. // @param string $description JSON text content all languages
  6559. // @return string Return an string in the language selected
  6560. static function get_description_lang ($lang, $descriptions) {
  6561. $description_lang = "";
  6562. $description = json_decode($descriptions);
  6563. if ($description == null) {
  6564. $description_lang = $descriptions;
  6565. }
  6566. else {
  6567. if (isset($description->{$lang}))
  6568. $description_lang = $description->{$lang};
  6569. else
  6570. if (isset($description->en)) //MOOC2014
  6571. $description_lang = $description->en;
  6572. else //MOOC2014
  6573. $description_lang = "en"; //MOOC2014
  6574. }
  6575. return $description_lang;
  6576. }
  6577. /// Function for return all language supported by iLM
  6578. // @param string $descriptions JSON text content all languages
  6579. // @return string Return as string with all languages
  6580. static function get_all_lang ($descriptions) {
  6581. $langs = "";
  6582. $description = json_decode($descriptions);
  6583. if ($description) {
  6584. foreach ($description as $key => $value) {
  6585. $langs .= $key . " ; ";
  6586. }
  6587. $langs = substr($langs, 0, strlen($langs) - 3);
  6588. }
  6589. return $langs;
  6590. }
  6591. /// Function for convert json in xml //MOOC2014
  6592. // @param string $json JSON text
  6593. // @return string Return as string with xml tags
  6594. static function json_to_xml ($json) {
  6595. $xml = "";
  6596. $json = json_decode($json);
  6597. foreach ($json as $key => $value) {
  6598. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6599. }
  6600. return $xml;
  6601. }
  6602. }
  6603. // class iassign_language
  6604. /// Class with log functions for plugin manage.
  6605. class iassign_log {
  6606. /// Function for insert log event
  6607. // @param string $action Code action of event
  6608. // @param string $information Text for describe action of event
  6609. // @param int $cmid Id of context module
  6610. // @param int $ilmid Id of iLM
  6611. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6612. global $COURSE, $CFG, $USER, $DB;
  6613. $newentry = new stdClass();
  6614. $newentry->time = time();
  6615. $newentry->userid = $USER->id;
  6616. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6617. $newentry->course = $COURSE->id;
  6618. $newentry->cmid = $cmid;
  6619. $newentry->ilmid = $ilmid;
  6620. $newentry->action = $action;
  6621. $newentry->info = $information;
  6622. $newentry->language = current_language();
  6623. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6624. if (ini_get("browscap") && function_exists('get_browse')) {
  6625. $browser = get_browse(null, true);
  6626. $newentry->javascript = $browser['javascript'];
  6627. $newentry->java = $browser['javaapplets'];
  6628. }
  6629. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6630. print_error('error_add_log', 'iassign');
  6631. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6632. } // class iassign_log