locallib.php 337 KB

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