locallib.php 337 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.3 2020/01/16
  7. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  8. *
  9. * - v 4.9.2 2019/03/13
  10. * + Several fixes to allow iLM under HTML stack
  11. *
  12. * - v 4.9.1 2017/11/02
  13. * + 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")
  14. * + 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)'
  15. *
  16. * - v 4.9 2017/03/13
  17. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  18. *
  19. * - v 4.8 2016/05/12
  20. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  21. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  22. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  23. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  24. * replaced by
  25. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  26. * - v 4.7 2016/02/17
  27. * + 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(...)')
  28. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  29. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  30. * + 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)
  31. * + 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'
  32. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  33. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  34. *
  35. * --------------- (code bellow was used at our MOOC 2014)
  36. * - v 4.6 2014/02/25
  37. * + Fix bugs in filter function for open applets.
  38. * - v 4.5 2014/02/24
  39. * + Fix bugs in params.
  40. * + Insert new param type.
  41. * - v 4.4 2014/01/24
  42. * + Allow select type of params.
  43. * + Insert the use of applet params specific for activities.
  44. * - v 4.3 2014/01/23
  45. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  46. * - v 4.2 2016/02/13
  47. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  48. * --------------- (above code used at our MOOC 2014)
  49. *
  50. * - v 4.1 2013/12/13
  51. * + Insert log in iAssign actions.
  52. * + 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).
  53. * + Insert class for Log actions in system.
  54. * - v 4.0 2013/10/31
  55. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  56. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  57. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  58. * - v 3.9 2013/10/25
  59. * + Insert support of upgrade iLM.
  60. * + Insert support for more than one extension in iLM.
  61. * + Fix bugs in verion control.
  62. * - v 3.8 2013/09/19
  63. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  64. * - v 3.7 2013/09/12
  65. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  66. * + 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).
  67. * - v 3.6 2013/09/05
  68. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  69. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  70. * + Change tag APPLET in function ilm_settings::view_ilm.
  71. * - v 3.5 2013/08/26
  72. * + Fix bug in download package iassign without answers (iassign::report).
  73. * - v 3.4 2013/08/23
  74. * + Fix bug in export package iassign.
  75. * - v 3.3 2013/08/22
  76. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  77. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  78. * - v 3.2 2013/08/21
  79. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  80. * + Change functions for import files for ilm_manager.php.
  81. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  82. * - v 3.1 2013/08/15
  83. * + Change return file selected (ilm_manager::add_ilm).
  84. * + 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).
  85. * - v 3.0 2013/08/02
  86. * + 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).
  87. * - v 2.9 2013/08/01
  88. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  89. * - v 2.8 2013/07/25
  90. * + Insert the activity name in header of view (activity::view_dates).
  91. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  92. * - v 2.7 2013/07/24
  93. * + Create link previous and next for student view in one activity (activity::view_dates).
  94. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  95. * - v 2.6 2013/07/23
  96. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  97. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  98. * - v 2.5 2013/07/12
  99. * + 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).
  100. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  101. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  102. *
  103. * @author Patricia Alves Rodrigues
  104. * @author Leônidas O. Brandão
  105. * @contributor Igor Moreira Félix (2018-)
  106. * @contributor Márcio de Lima Passos (2014)
  107. * @version v 4.9.2 2019/03/13
  108. * @version v 4.8 2016/05/12
  109. * @package mod_iassign_lib
  110. * @since 2010/09/27
  111. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  112. *
  113. * <b>License</b>
  114. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  115. */
  116. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  117. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  118. //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"'
  119. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  120. /**
  121. * Standard base class for all iAssign
  122. */
  123. class iassign {
  124. var $cm;
  125. var $course;
  126. var $iassign;
  127. var $striassign;
  128. var $striassigns;
  129. var $context;
  130. var $activity;
  131. var $iassign_up;
  132. var $iassign_down;
  133. var $action;
  134. var $iassign_submission_current;
  135. var $userid_iassign;
  136. var $bottonPost;
  137. var $write_solution;
  138. var $view_iassign;
  139. // 3.1 update PHP 7.0 compatibility for all moodle versions
  140. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  141. /// Constructor for the base iassign class
  142. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  143. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  144. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  145. function __construct ($iassign, $cm, $course) {
  146. global $COURSE, $CFG, $USER, $DB;
  147. $botton = optional_param('botton', NULL, PARAM_TEXT);
  148. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  149. if (!is_null($botton))
  150. $USER->iassignEdit = $botton;
  151. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  152. // 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'
  153. $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"
  154. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  155. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  156. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  157. $this->action = optional_param('action', NULL, PARAM_TEXT);
  158. $this->cm = $cm;
  159. $this->context = context_module::instance($this->cm->id);
  160. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  161. $this->userid_iassign = $USER->id;
  162. if ($course) {
  163. $this->course = $course;
  164. }
  165. else if ($this->cm->course == $COURSE->id) {
  166. $this->course = $COURSE;
  167. }
  168. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  169. print_error('invalidid', 'iassign');
  170. }
  171. $this->coursecontext = context_course::instance($this->course->id);
  172. if ($iassign) {
  173. $this->iassign = $iassign;
  174. }
  175. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  176. print_error('invalidid', 'iassign');
  177. }
  178. $USER->context = context_module::instance($this->cm->id);
  179. $USER->cm = $this->cm->id;
  180. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  181. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  182. $this->context = context_module::instance($this->cm->id);
  183. $this->striassign = get_string('modulename', 'iassign');
  184. $this->striassigns = get_string('modulenameplural', 'iassign');
  185. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  186. $this->bottonPost = 0;
  187. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  188. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  189. $this->view();
  190. } // function __construct($iassign, $cm, $course)
  191. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  192. // This method provides the page to view each iLM with any interactive activity
  193. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  194. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  195. global $USER, $DB, $OUTPUT;
  196. // $iassign_statementid = $this->iassign->iassign_statementid;
  197. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  198. $iassign_statementid = $this->activity->get_activity()->id;
  199. else
  200. $iassign_statementid = "";
  201. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  202. // If this user has no capability to View 'iassign': stop here
  203. require_capability('mod/iassign:view', $this->context);
  204. // Trigger module view event
  205. $event = \mod_iassign\event\course_module_viewed::create(array(
  206. 'objectid' => $this->iassign->id,
  207. 'context' => $this->context
  208. ));
  209. $event->add_record_snapshot('course', $this->course);
  210. $event->trigger();
  211. if ($this->action) { // when student do/redo activity or teacher see student solution
  212. $this->action(); // calls '$this->view_iLM();'
  213. }
  214. else {
  215. print $OUTPUT->header();
  216. $this->view_iassigns(); // show the iLM with the content
  217. print $OUTPUT->footer();
  218. }
  219. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  220. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  221. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  222. //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" }
  223. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //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" }
  226. //D else echo "Apagou!<br/>";
  227. die();
  228. } // function view()
  229. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  230. function action () {
  231. global $USER;
  232. // action:
  233. // up - move up activity (mover atividade para cima)
  234. // down - move down activity (mover atividade para baixo)
  235. // visible - view/hide activity (exibir/ocultar atividade)
  236. // delete - delete activity (excluir atividade)
  237. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  238. // deleteno - does not erase activity (não apaga atividade)
  239. // add - add activity (adicionar atividade)
  240. // edit - edit activity (modificar atividade)
  241. $action_iassign = array(
  242. 'newcomment' => '$this->get_answer();',
  243. 'view' => '$this->view_iassign_current();',
  244. 'get_answer' => '$this->get_answer();',
  245. 'repeat' => '$this->view_iassign_current();',
  246. 'overwrite' => '$this->get_answer();',
  247. 'stats_student' => '$this->stats_students();',
  248. 'download_answer' => '$this->export_file_answer();',
  249. 'download_all_answer' => '$this->export_package_answer();');
  250. $action_iassign_limit = array(
  251. 'view' => '$this->view_iassign_current();',
  252. 'newcomment' => '$this->get_answer();',
  253. 'viewsubmission' => '$this->view_iassign_current();',
  254. 'edit_status' => '$this->edit_status();',
  255. 'edit_grade' => '$this->edit_grade();',
  256. 'export_csv' => '$this->export_csv();',
  257. 'report' => '$this->report();',
  258. 'print' => '$this->report();',
  259. 'stats' => '$this->stats();',
  260. 'printstats' => '$this->stats();');
  261. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  262. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  263. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  264. 'visible' => '$this->activity->visible_iassign($this->return);',
  265. 'delete' => '$this->activity->delete($this->return);',
  266. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  267. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  268. 'add' => '$this->add_edit_iassign();',
  269. 'edit' => '$this->add_edit_iassign();',
  270. 'get_answer' => '$this->get_answer();',
  271. 'duplicate_activity' => '$this->duplicate_activity();',
  272. 'move_activity' => '$this->move_activity();',
  273. 'auto_evaluate' => '$this->auto_evaluate();',
  274. 'get_student_submission' => '$this->get_student_submission();',
  275. 'get_teacher_exercise' => '$this->get_teacher_exercise();'
  276. );
  277. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  278. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  279. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  280. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  281. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  282. }
  283. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  284. eval($action_iassign_limit[$this->action]);
  285. }
  286. else { // Student reaches this point
  287. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  288. // Arrive here with: "get_answer"; "view"
  289. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  290. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  291. }
  292. } // function action()
  293. /// This method prints the student submission to a specific exercise
  294. function get_student_submission () {
  295. global $DB;
  296. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  297. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  298. if (!$student || !$exercise) exit;
  299. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  300. if ($iassign_submission)
  301. print($iassign_submission->answer);
  302. die();
  303. }
  304. /// This method prints the teacher exercise
  305. function get_teacher_exercise () {
  306. global $DB, $COURSE;
  307. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  308. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  309. $fs = get_file_storage(); // Get reference to all files in Moodle data
  310. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id,
  311. 'mod_iassign',
  312. 'exercise',
  313. $iassign_statement->file);
  314. foreach ($files as $file) {
  315. if ($file->get_filename() != ".") {
  316. print($file->get_content());
  317. }
  318. }
  319. die();
  320. }
  321. /// This method runs activities auto evaluation in teacher area
  322. function auto_evaluate () {
  323. global $COURSE, $CFG, $USER, $DB, $OUTPUT;
  324. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  325. exit;
  326. // Get list of exercises in the instance:
  327. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  328. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  329. // Get list of enrolled students:
  330. $params = array('shortname' => 'student');
  331. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  332. $context = context_course::instance($this->course->id);
  333. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  334. $students_list = $DB->get_records_sql(
  335. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  336. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  337. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  338. print $OUTPUT->header();
  339. print '<script> var exercises = [ ';
  340. foreach ($exercises_list as $exercise) {
  341. print $exercise->id . ',';
  342. }
  343. print ' ]; var students = [ ';
  344. foreach ($students_list as $student) {
  345. print $student->userid . ',';
  346. }
  347. print ']; var ilms = [';
  348. foreach ($exercises_list as $exercise) {
  349. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  350. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  351. }
  352. print '];
  353. var endpoint = "'.$CFG->wwwroot . "/mod/iassign/view.php?action=get_student_submission&id=".$this->cm->id.'";
  354. window.onload = function(e){
  355. for (i = 0; i < exercises.length; i++) {
  356. var teacher_answer = "'.$CFG->wwwroot.'/mod/iassign/view.php?action=get_teacher_exercise&id='.$this->cm->id.'&iassign_exercise=" + exercises[i];
  357. for (j = 0; j < students.length; j++) {//" + students[j] + "
  358. var student_answer = endpoint + "&iassign_student=3&iassign_exercise=" + exercises[i];
  359. var final_url = ilms[i] + "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment="+encodeURIComponent(teacher_answer)+"&iLM_PARAM_TeacherAutoEval="+encodeURIComponent(student_answer);
  360. console.log(final_url);
  361. window.frames["ifrm"].location=final_url;
  362. break;
  363. }
  364. break;
  365. }
  366. }';
  367. print '</script>';
  368. print '<iframe name="ifrm"></iframe>';
  369. print $OUTPUT->footer();
  370. }
  371. /// This method moves an iAssign activity
  372. function move_activity () {
  373. global $USER, $CFG, $DB, $COURSE;
  374. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  375. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  376. $update_entry_new_iassign = new stdClass();
  377. $update_entry_new_iassign->id = $iassign_id;
  378. $update_entry_new_iassign->iassignid = $iassign_destiny;
  379. // Update the iassign_statement
  380. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  381. // Update file context
  382. $c_i = context_module::instance($this->cm->id);
  383. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  384. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  385. $path_module = context_course::instance($COURSE->id);
  386. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  387. if ($context_file) {
  388. $id_context = $context_file->id;
  389. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  390. $fs = get_file_storage(); // Get reference to all files in Moodle data
  391. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  392. foreach ($files as $value) {
  393. if ($value->get_filename() != ".") {
  394. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  395. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  396. $updateentry = new stdClass();
  397. $updateentry->id = $iassign_id;
  398. $updateentry->file = $newfile->get_itemid();
  399. $DB->update_record("iassign_statement", $updateentry);
  400. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  401. break;
  402. }
  403. }
  404. }
  405. $this->return_home_course('moved_activity');
  406. exit;
  407. }
  408. /// This method duplicates an iAssign activity
  409. function duplicate_activity () {
  410. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  411. $id = $this->cm->id;
  412. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  413. $context = context_module::instance($this->cm->id);
  414. $contextuser = context_user::instance($USER->id);
  415. // Get the the iAssign acitivity to be duplicated
  416. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  417. // Remove the current id of activity
  418. $iassign_statement->id=0;
  419. // Get the information about current author, and add this information in author_modified field
  420. $author = $DB->get_record("user", array('id' => $USER->id));
  421. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  422. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  423. // Store the activity in the table
  424. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  425. // Duplicate activity file
  426. $fs = get_file_storage(); // Get reference to all files in Moodle data
  427. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  428. foreach ($files as $value) {
  429. if ($value->get_filename() != ".") {
  430. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  431. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  432. $updateentry = new stdClass();
  433. $updateentry->id = $id_;
  434. $updateentry->file = $newfile->get_itemid();
  435. // Update the duplicated iLM iAssign with new file id
  436. $DB->update_record("iassign_statement", $updateentry);
  437. }
  438. }
  439. }
  440. // log event --------------------------------------------------------------------------------------
  441. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  442. $this->return_home_course('duplicated_activity');
  443. exit;
  444. }
  445. /// This method gets the content from the iLM and register it
  446. // It could be the "exercise template" (teacher) or an answer (student)
  447. function get_answer () {
  448. global $USER, $CFG, $DB, $OUTPUT;
  449. $id = $this->cm->id;
  450. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  451. $comment = false;
  452. if ($submission_comment)
  453. $comment = $this->write_comment_submission();
  454. // receives data of iLM using the current activity
  455. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  456. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  457. // receives data of submission of current activity
  458. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  459. // receives post and get
  460. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  461. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  462. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  463. $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)
  464. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  465. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  466. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  467. $msg = '';
  468. // Feedback
  469. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  470. $str_action = "view"; // repeat
  471. if (strtolower($iassign_ilm->name) == "igeom") {
  472. }
  473. $title = get_string('evaluate_iassign', 'iassign');
  474. print $OUTPUT->header();
  475. print $OUTPUT->box_start();
  476. // Action = { view ; repeat ; viewsubmission }
  477. // * '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")
  478. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  479. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  480. $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;
  481. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  482. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  483. print '<table width=100% >';
  484. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  485. //TODO alterar aqui???
  486. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  487. // empty_answer_post = No solution was posted.
  488. if ($comment)
  489. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  490. else
  491. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  492. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  493. } else {
  494. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  495. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  496. // Correct answer!!
  497. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  498. $this->write_solution = 1; //
  499. $status = 3;
  500. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  501. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  502. // log record
  503. $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;
  504. // Trigger module viewed event.
  505. $event = \mod_iassign\event\submission_created::create(array(
  506. 'objectid' => $this->iassign->id,
  507. 'context' => $this->context,
  508. 'other' => $info
  509. ));
  510. $event->add_record_snapshot('course', $this->course);
  511. $event->trigger();
  512. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  513. // Wrong answer...: get_answer_incorrect
  514. $status = 2;
  515. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  516. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  517. // log record
  518. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  519. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  520. // Trigger module viewed event.
  521. $event = \mod_iassign\event\submission_created::create(array(
  522. 'objectid' => $this->iassign->id,
  523. 'context' => $this->context,
  524. 'other' => $info
  525. ));
  526. $event->add_record_snapshot('course', $this->course);
  527. $event->trigger();
  528. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  529. // Presents to the learner the result of the automatic evaluate?
  530. if ($this->activity->get_activity()->show_answer == 0) { // no...
  531. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  532. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  533. print '<tr>';
  534. // log record
  535. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  536. // Trigger module viewed event.
  537. $event = \mod_iassign\event\submission_created::create(array(
  538. 'objectid' => $this->iassign->id,
  539. 'context' => $this->context,
  540. 'other' => $info
  541. ));
  542. $event->add_record_snapshot('course', $this->course);
  543. $event->trigger();
  544. } else { // yes!!!
  545. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  546. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  547. print '<tr>';
  548. print $msg;
  549. }
  550. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  551. $status = 1;
  552. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  553. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  554. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  555. print '<tr>';
  556. // log record
  557. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  558. $event = \mod_iassign\event\submission_created::create(array(
  559. 'objectid' => $this->iassign->id,
  560. 'context' => $this->context,
  561. 'other' => $info
  562. ));
  563. $event->add_record_snapshot('course', $this->course);
  564. $event->trigger();
  565. } // if ($iassign_ilm->evaluate == 1)
  566. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  567. print '</tr></table>';
  568. print $OUTPUT->box_end();
  569. // add or update evaluate
  570. if ($this->write_solution == 1) {
  571. $timenow = time();
  572. // new record
  573. if (!$iassign_submission) {
  574. $newentry = new stdClass();
  575. $newentry->userid = $this->userid_iassign;
  576. // $newentry->userid = $USER->id;
  577. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  578. $newentry->timecreated = $timenow;
  579. $newentry->timemodified = $timenow;
  580. $newentry->answer = $iLM_PARAM_ArchiveContent;
  581. $newentry->grade = round($grade_student, 2);
  582. $newentry->status = $status;
  583. $newentry->experiment = 1;
  584. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  585. print_error('error_insert', 'iassign');
  586. } else {
  587. // Trigger module viewed event.
  588. $event = \mod_iassign\event\submission_created::create(array(
  589. 'objectid' => $this->iassign->id,
  590. 'context' => $this->context
  591. ));
  592. $event->add_record_snapshot('course', $this->course);
  593. $event->trigger();
  594. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  595. }
  596. } elseif ($iassign_submission->status != 3) {
  597. $newentry = new stdClass();
  598. $newentry->id = $iassign_submission->id;
  599. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  600. $newentry->userid = $iassign_submission->userid;
  601. $newentry->timecreated = $iassign_submission->timecreated;
  602. $newentry->timemodified = $timenow;
  603. $newentry->answer = $iLM_PARAM_ArchiveContent;
  604. $newentry->grade = round($grade_student, 2);
  605. $newentry->status = $status;
  606. $newentry->experiment = $iassign_submission->experiment + 1;
  607. if (!$DB->update_record("iassign_submission", $newentry)) {
  608. print_error('error_update', 'iassign');
  609. //D depurar...
  610. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  611. //D $fp = fopen("teste1.txt","w");
  612. //D fwrite($fp,$stringAux);
  613. } else {
  614. // Trigger module viewed event.
  615. $event = \mod_iassign\event\submission_updated::create(array(
  616. 'objectid' => $this->iassign->id,
  617. 'context' => $this->context
  618. ));
  619. $event->add_record_snapshot('course', $this->course);
  620. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  621. }
  622. } else {
  623. if ($return_get_answer == 1) {
  624. $newentry = new stdClass();
  625. $newentry->id = $iassign_submission->id;
  626. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  627. $newentry->userid = $iassign_submission->userid;
  628. $newentry->timecreated = $iassign_submission->timecreated;
  629. $newentry->timemodified = $timenow;
  630. $newentry->answer = $iLM_PARAM_ArchiveContent;
  631. $newentry->grade = round($grade_student, 2);
  632. $newentry->status = $status;
  633. $newentry->experiment = $iassign_submission->experiment + 1;
  634. if (!$DB->update_record("iassign_submission", $newentry))
  635. print_error('error_update', 'iassign');
  636. else {
  637. $event = \mod_iassign\event\submission_updated::create(array(
  638. 'objectid' => $this->iassign->id,
  639. 'context' => $this->context
  640. ));
  641. $event->add_record_snapshot('course', $this->course);
  642. $event->trigger();
  643. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  644. print $OUTPUT->box_start();
  645. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  646. print $OUTPUT->box_end();
  647. }
  648. } elseif ($return_get_answer == 2) {
  649. print $OUTPUT->box_start();
  650. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  651. print $OUTPUT->box_end();
  652. } else {
  653. print $OUTPUT->box_start();
  654. print "
  655. <script type='text/javascript'>
  656. //<![CDATA[
  657. function overwrite () {
  658. document.formEnvio.return_get_answer.value = 1;
  659. document.formEnvio.submit();
  660. }
  661. function nooverwrite () {
  662. document.formEnvio.return_get_answer.value = 2;
  663. document.formEnvio.submit();
  664. }
  665. //]]>
  666. </script>";
  667. $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;
  668. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  669. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  670. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  671. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  672. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  673. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  674. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  675. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  676. <input type='hidden' name='return_get_answer'/> ";
  677. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  678. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  679. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  680. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  681. print " </form>";
  682. print $OUTPUT->box_end();
  683. }
  684. }
  685. } // if ($this->write_solution == 1)
  686. print $OUTPUT->footer();
  687. die();
  688. } // function get_answer()
  689. /// Export in file the answer of student.
  690. function export_file_answer () {
  691. global $DB;
  692. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  693. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  694. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  695. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  696. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  697. $extensions = explode(",", $iassign_ilm->extension);
  698. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  699. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  700. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  701. header("Pragma: public");
  702. header("Expires: 0");
  703. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  704. header("Cache-Control: private", false);
  705. header("Content-Type: document/unknown");
  706. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  707. set_time_limit(0);
  708. print($iassign_submission->answer);
  709. exit;
  710. } // function export_file_answer()
  711. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  712. // @calledby $this->export_package_answer()
  713. //TODO Precisa terminar! //TODO_HTML
  714. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  715. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  716. <head>
  717. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  718. $str_html .= " </head>
  719. <body>\n";
  720. $tam = sizeof($array_iassign_name);
  721. for ($ii=0; $ii<$tam; $ii++) {
  722. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  723. }
  724. $str_html .= "
  725. </body>\n</html>";
  726. return $str_html;
  727. }
  728. /// Export an package (zip) with all answer of students
  729. // @calledby $this->action()
  730. function export_package_answer () {
  731. global $DB, $CFG, $OUTPUT;
  732. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  733. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  734. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  735. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  736. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  737. $userid = optional_param('userid', NULL, PARAM_INT);
  738. $iassign_user = $DB->get_record("user", array("id" => $userid));
  739. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  740. //TODO_HTML echo "username=$username<br/>"; exit;
  741. $current_date = date('Y_m_d_H');
  742. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  743. // If temporary directory under Moodle data does not exists => create it
  744. if (!is_dir($diretorio)) {
  745. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  746. // created directory with permissions to be seen by everyone
  747. }
  748. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  749. if (!is_writable($diretorio)) { // send a highlighted message!
  750. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  751. exit; // just in case
  752. }
  753. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  754. $zip = new zip_archive(); // create ZIP
  755. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  756. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  757. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  758. $vet_student_filename = array();
  759. $vet_student_content = array();
  760. foreach ($iassign_statements as $iassign_statement) {
  761. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  762. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  763. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  764. $extensions = explode(",", $iassign_ilm->extension);
  765. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  766. if ($iassign_submission) {
  767. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  768. $student_content = $iassign_submission->answer;
  769. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  770. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  771. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  772. if ($resp) {
  773. $vet_student_filename[] = $student_filename;
  774. $vet_student_content[] = $student_content;
  775. }
  776. else { // send a highlighted message!
  777. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  778. exit; // just in case
  779. }
  780. }
  781. }
  782. $zip->close(); // close the ZIP file
  783. if (count($vet_student_filename)>0) {
  784. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  785. $result_tf = $vet_result[0];
  786. $filenameZip = $vet_result[1]->filename;
  787. }
  788. iassign_utils::download_file($zip_filename); // download the ZIP file
  789. exit;
  790. } // function export_package_answer()
  791. /// Editing status of interactive activities
  792. function edit_status () {
  793. global $USER, $DB, $OUTPUT;
  794. $newentry = new stdClass();
  795. $newentry->id = $this->iassign_submission_current;
  796. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  797. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  798. if ($iassign_submission->status != 0 && $newentry->status == 0)
  799. $newentry->status = $iassign_submission->status;
  800. $newentry->teacher = $USER->id;
  801. if (!$DB->update_record('iassign_submission', $newentry))
  802. print_error('error_update', 'iassign');
  803. else {
  804. // Trigger module viewed event.
  805. $event = \mod_iassign\event\submission_updated::create(array(
  806. 'objectid' => $this->iassign->id,
  807. 'context' => $this->context
  808. ));
  809. $event->add_record_snapshot('course', $this->course);
  810. $event->trigger();
  811. $this->action = 'viewsubmission';
  812. $this->view_iassign_current();
  813. } // if (!$DB->update_record('iassign_submission', $newentry))
  814. } // function edit_status()
  815. /// Editing grade of interactive activities
  816. function edit_grade () {
  817. global $USER, $DB, $OUTPUT;
  818. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  819. if ($newgrade && $newgrade >= 0) {
  820. $newentry = new stdClass();
  821. $newentry->id = $this->iassign_submission_current;
  822. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  823. $newentry->teacher = $USER->id;
  824. if (!$DB->update_record('iassign_submission', $newentry))
  825. print_error('error_update', 'iassign');
  826. else {
  827. // Trigger module viewed event.
  828. $event = \mod_iassign\event\submission_updated::create(array(
  829. 'objectid' => $this->iassign->id,
  830. 'context' => $this->context
  831. ));
  832. $event->add_record_snapshot('course', $this->course);
  833. $event->trigger();
  834. }
  835. } // if ($newgrade >= 0)
  836. $this->action = 'viewsubmission';
  837. $this->view_iassign_current();
  838. }
  839. /// Add or Edit interactive activities
  840. // @calledby $this->action()
  841. function add_edit_iassign () {
  842. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  843. require_once('iassign_form.php');
  844. $id = $this->cm->id;
  845. $iassignid = $this->iassign->id;
  846. $param = new stdClass();
  847. $param->action = $this->action; // oculto
  848. $param->id = $id; // oculto
  849. $COURSE->cm = $id;
  850. $COURSE->iassignid = $iassignid;
  851. $COURSE->iassign_file_id = NULL;
  852. $context = context_module::instance($this->cm->id);
  853. $contextuser = context_user::instance($USER->id);
  854. $component = 'mod_iassign';
  855. $filearea = 'exercise';
  856. if (!empty($this->iassign_current))
  857. $COURSE->iassign_id = $this->iassign_current;
  858. else
  859. $COURSE->iassign_id = 0;
  860. $total_of_activities = 0; // get the total number of activities in this iAssign block
  861. if ($this->action == 'add') {
  862. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  863. $params = array('iassignid' => $iassignid);
  864. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  865. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  866. $total_of_activities = count($iassign_statement);
  867. $param->iassignid = $iassignid;
  868. $param->name = "";
  869. $param->oldname = "";
  870. $param->type_iassign = 3;
  871. $param->proposition = "";
  872. $author = $DB->get_record("user", array("id" => $USER->id));
  873. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  874. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  875. $param->author = $param->author_name;
  876. $param->author_modified = $param->author_modified_name;
  877. $COURSE->iassign_list = array();
  878. $param->iassign_list = array();
  879. if ($iassign_statement) {
  880. foreach ($iassign_statement as $iassign) {
  881. $iassignid = $iassign->id;
  882. $param->iassign_list[$iassignid] = 0;
  883. $COURSE->iassign_list[$iassignid] = new stdClass();
  884. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  885. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  886. $COURSE->iassign_list[$iassignid]->enable = 1;
  887. } // foreach ($iassign_statement as $iassign)
  888. }
  889. $param->iassign_ilmid = 0;
  890. //echo "locallib.php: add_edit_iassign(): add<br/>";
  891. $param->file = 0;
  892. $param->fileold = 0;
  893. $param->filename = "";
  894. $param->grade = $iassign_data->grade;
  895. $param->timemodified = time();
  896. $param->timecreated = time();
  897. $param->timeavailable = $iassign_data->timeavailable;
  898. $param->timedue = $iassign_data->timedue;
  899. $param->preventlate = $iassign_data->preventlate;
  900. $param->test = $iassign_data->test;
  901. $param->special_param1 = 0;
  902. $param->visible = 1;
  903. $param->max_experiment = $iassign_data->max_experiment;
  904. $param->dependency = 0;
  905. $param->automatic_evaluate = 1;
  906. $param->show_answer = 1;
  907. } // if ($this->action == 'add')
  908. elseif ($this->action == 'edit') {
  909. $COURSE->iassign_list = array();
  910. $this_activity = $this->activity->get_activity();
  911. if ($this_activity != null) {
  912. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  913. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  914. $param->iassign_id = $iassign_statement_current->id; // oculto
  915. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  916. $param->name = $iassign_statement_current->name;
  917. $param->oldname = $iassign_statement_current->name;
  918. $param->type_iassign = $iassign_statement_current->type_iassign;
  919. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  920. //2019 $param->proposition = $iassign_statement_current->proposition;
  921. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  922. $param->author_name = $iassign_statement_current->author_name; // oculto
  923. $param->author = $iassign_statement_current->author_name;
  924. $author = $DB->get_record("user", array('id' => $USER->id));
  925. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  926. $param->author_modified = $param->author_modified_name;
  927. $dependency = explode(';', $iassign_statement_current->dependency);
  928. $param->iassign_list = array();
  929. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  930. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  931. $array_dependency = array();
  932. $subdependency = "";
  933. $sub_subdependency = "";
  934. // dependent on this exercise
  935. if ($iassign_statement_dependency) {
  936. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  937. // to whom this exercise depends
  938. foreach ($inter as $tmp)
  939. $sub_subdependency .= $this->search_sub_dependency($tmp);
  940. $list_dependency = $subdependency . $sub_subdependency;
  941. $array_dependency = explode(";", $list_dependency);
  942. }
  943. // Get all activity with the same iLM - iassignid
  944. $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";
  945. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  946. $total_of_activities = count($all_others_iassign_statement) + 1;
  947. $inter = array();
  948. if ($all_others_iassign_statement) {
  949. foreach ($all_others_iassign_statement as $iassign)
  950. if (in_array($iassign->id, $dependency))
  951. $inter[] = $iassign->id;
  952. }
  953. if ($all_others_iassign_statement) {
  954. foreach ($all_others_iassign_statement as $iassign) {
  955. $iassignid = $iassign->id;
  956. $COURSE->iassign_list[$iassignid] = new stdClass();
  957. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  958. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  959. if (in_array($iassignid, $dependency))
  960. $param->iassign_list[$iassignid] = 1;
  961. else
  962. $param->iassign_list[$iassignid] = 0;
  963. if (in_array($iassignid, $array_dependency))
  964. $COURSE->iassign_list[$iassignid]->enable = 0;
  965. else
  966. $COURSE->iassign_list[$iassignid]->enable = 1;
  967. } // foreach ($all_others_iassign_statement as $iassign)
  968. }
  969. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  970. $param->fileold = 0;
  971. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  972. $param->filename = '';
  973. $param->grade = $iassign_statement_current->grade;
  974. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  975. $param->timeavailable = $iassign_statement_current->timeavailable;
  976. $param->timedue = $iassign_statement_current->timedue;
  977. $param->preventlate = $iassign_statement_current->preventlate;
  978. $param->test = $iassign_statement_current->test;
  979. $param->special_param1 = $iassign_statement_current->special_param1;
  980. $param->position = $iassign_statement_current->position; // oculto
  981. $param->visible = $iassign_statement_current->visible;
  982. $param->max_experiment = $iassign_statement_current->max_experiment;
  983. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  984. $param->show_answer = $iassign_statement_current->show_answer;
  985. $fs = get_file_storage(); // Get reference to all files in Moodle data
  986. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  987. if ($files) {
  988. foreach ($files as $file) {
  989. if ($file->get_filename() != '.') {
  990. $param->filename = $file->get_filename();
  991. $param->file = $file->get_id();
  992. $param->fileold = $file->get_id();
  993. $COURSE->iassign_file_id = $file->get_id();
  994. }
  995. }
  996. }
  997. //TODO //MOOC2014 -- inicio
  998. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  999. //D if ($iassign_ilm_configs) {
  1000. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1001. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1002. //D } //MOOC2014 -- fim
  1003. } // if ($this_activity != null)
  1004. } // elseif ($this->action == 'edit')
  1005. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1006. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1007. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1008. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1009. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1010. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1011. $param->position = $total_of_activities;
  1012. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1013. $mform->set_data($param);
  1014. if ($mform->is_cancelled()) {
  1015. $this->return_home_course('iassign_cancel');
  1016. exit;
  1017. }
  1018. else { // if ($mform->is_cancelled())
  1019. $result = $mform->get_data();
  1020. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1021. if ($result) {
  1022. $result->context = $context;
  1023. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1024. $result->grade = 0;
  1025. if ($result->type_iassign == 1) {
  1026. $result->automatic_evaluate = 0;
  1027. $result->show_answer = 0;
  1028. }
  1029. elseif ($result->automatic_evaluate == 0)
  1030. $result->show_answer = 0;
  1031. // $_POST['iassign_list']
  1032. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1033. if ($result->iassign_list) {
  1034. foreach ($result->iassign_list as $key => $value)
  1035. $result->dependency .= $key . ';';
  1036. }
  1037. else
  1038. $result->dependency = 0;
  1039. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1040. //TODO Then get it directly from the form data $_POST!
  1041. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1042. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1043. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1044. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1045. if ($this->action == 'add') {
  1046. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1047. if ($iassign_statement_name) {
  1048. $this->return_home_course('error_iassign_name');
  1049. die();
  1050. }
  1051. // Really insert the new iActivity in table '*_iassign_statement'
  1052. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1053. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1054. // Trigger module viewed event.
  1055. $event = \mod_iassign\event\iassign_created::create(array(
  1056. 'objectid' => $iassignid,
  1057. 'context' => $context
  1058. ));
  1059. $event->add_record_snapshot('course', $this->course);
  1060. $event->trigger();
  1061. $this->return_home_course('iassign_add');
  1062. } // if ($this->action == 'add')
  1063. elseif ($this->action == 'edit') {
  1064. $iassignid = $this->activity->update_iassign($result);
  1065. $this->activity->update_calendar($iassignid, $result->oldname);
  1066. // Trigger module viewed event.
  1067. $event = \mod_iassign\event\iassign_updated::create(array(
  1068. 'objectid' => $iassignid,
  1069. 'context' => $context
  1070. ));
  1071. $event->add_record_snapshot('course', $this->course);
  1072. $event->trigger();
  1073. $this->return_home_course('iassign_update');
  1074. } // elseif ($this->action == 'edit')
  1075. die();
  1076. } // if ($result)
  1077. } // else if ($mform->is_cancelled())
  1078. print $OUTPUT->header();
  1079. $mform->display();
  1080. print $OUTPUT->footer();
  1081. die();
  1082. } // function add_edit_iassign()
  1083. /// Search for dependencies
  1084. function search_dependency ($search_iassing_id, $iassign_statement) {
  1085. global $DB, $OUTPUT;
  1086. $dependency = "";
  1087. if ($iassign_statement)
  1088. foreach ($iassign_statement as $iassign) {
  1089. $inter_dependency = explode(';', $iassign->dependency);
  1090. if (in_array($search_iassing_id, $inter_dependency)) {
  1091. $dependency .= $iassign->id . ";";
  1092. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1093. } // if (in_array($search_iassing_id, $inter_dependency))
  1094. } // foreach ($iassign_statement as $iassign)
  1095. return $dependency;
  1096. }
  1097. /// Search for "sub"dependency
  1098. function search_sub_dependency ($search_iassing_id) {
  1099. global $DB, $OUTPUT;
  1100. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1101. $dependency = "";
  1102. if ($iassign_statement) {
  1103. $inter_dependency = explode(';', $iassign_statement->dependency);
  1104. foreach ($inter_dependency as $tmp) {
  1105. if ($tmp != 0)
  1106. $dependency .= $tmp . ";";
  1107. $dependency .= $this->search_sub_dependency($tmp);
  1108. } // foreach ($inter_dependency as $tmp)
  1109. } // if ($iassign_statement)
  1110. return $dependency;
  1111. }
  1112. // Warning message
  1113. static function warning_message_iassign ($strcode) {
  1114. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1115. }
  1116. /// Update grade of iAssign
  1117. // Called always any iAssign activity is created
  1118. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1119. static function update_grade_iassign ($iassignid) {
  1120. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1121. require_once($CFG->libdir . '/gradelib.php');
  1122. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1123. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1124. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1125. // Each iAssign item is associated with one item on the "gradebook"
  1126. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1127. //$sum_grade = 0;
  1128. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1129. //foreach($grade as $tmp) {
  1130. // $sum_grade += $tmp->grade;
  1131. // }
  1132. //1 Solution 1
  1133. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1134. //1 $sum_grade = 0; //1
  1135. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1136. //2 Solution 2
  1137. $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
  1138. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1139. if (key($array_sum_grade))
  1140. $sum_grade = key($array_sum_grade); //2
  1141. else
  1142. $sum_grade = 0; //2
  1143. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1144. $grades = NULL;
  1145. $params = array('itemname' => $grade_iassign->name);
  1146. $params['iteminstance'] = $iassignid;
  1147. $params['gradetype'] = GRADE_TYPE_VALUE;
  1148. //2016 if ($sum_grade != 0) {
  1149. $params['grademax'] = $sum_grade;
  1150. $params['rawgrademax'] = $sum_grade;
  1151. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1152. $params['grademin'] = 0;
  1153. // @calls /lib/gradelib.php: call to grade_item->insert()
  1154. //TODO: is there any error here in Moodle version 3.0?
  1155. //TODO: Incorrect property 'grademax' found when inserting grade object
  1156. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1157. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1158. }
  1159. /// Update grade of student
  1160. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1161. global $CFG, $DB, $OUTPUT;
  1162. require_once($CFG->libdir . '/gradelib.php');
  1163. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1164. // Review all the student submission for this iAssign activity
  1165. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1166. $total_grade = 0;
  1167. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1168. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1169. if ($iassign_submission)
  1170. $total_grade += $iassign_submission->grade;
  1171. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1172. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1173. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1174. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1175. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1176. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1177. $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
  1178. if (key($array_sum_grade))
  1179. $sum_grade = key($array_sum_grade); //2
  1180. else
  1181. $sum_grade = 0; //2
  1182. $grades['userid'] = $userid;
  1183. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1184. $params = array('itemname' => $grade_iassign->name);
  1185. $params['iteminstance'] = $iassignid;
  1186. $params['gradetype'] = GRADE_TYPE_VALUE;
  1187. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1188. $params['grademax'] = $sum_grade;
  1189. $params['rawgrademax'] = $sum_grade;
  1190. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1191. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1192. }
  1193. /// Display caption of icons
  1194. function view_legend_icons () {
  1195. global $USER, $CFG, $DB, $OUTPUT;
  1196. $id = $this->cm->id;
  1197. if ($this->action == 'print')
  1198. print '<table border=1 width=100%><tr>';
  1199. else
  1200. print '<table width=100%><tr>';
  1201. print '<td >';
  1202. if ($this->action != 'print')
  1203. print $OUTPUT->help_icon('legend', 'iassign');
  1204. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1205. // $imagetext = '');
  1206. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1207. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1208. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1209. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1210. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1211. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1212. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1213. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1214. print '</td>' . "\n";
  1215. if ($this->action != 'print') {
  1216. $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>";
  1217. $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>";
  1218. $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>";
  1219. $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>";
  1220. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1221. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1222. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1223. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1224. } // if ($this->action != 'print')
  1225. print '</tr></table>' . "\n";
  1226. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1227. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1228. $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>";
  1229. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1230. print '</tr></table>' . "\n";
  1231. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1232. else
  1233. print '</td></tr></table>' . "\n";
  1234. } // function view_legend_icons()
  1235. /// Display activity current
  1236. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1237. function view_iassign_current () {
  1238. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1239. $id = $this->cm->id;
  1240. $iassignid = $this->iassign->id;
  1241. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1242. $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
  1243. // 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 ...
  1244. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1245. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1246. $ilm_name = '';
  1247. if ($ilm->ilm)
  1248. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1249. // 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
  1250. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1251. // log record
  1252. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1253. //Trigger module viewed event.
  1254. $event = \mod_iassign\event\submission_viewed::create(array(
  1255. 'objectid' => $iassign->id,
  1256. 'context' => $this->context,
  1257. 'other' => $info
  1258. ));
  1259. $event->add_record_snapshot('course', $this->course);
  1260. $event->trigger();
  1261. // Search of iLM data used in the current activity
  1262. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1263. // Add actual activity to navbar:
  1264. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1265. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1266. print $OUTPUT->header();
  1267. if ($this->action == 'viewsubmission') {
  1268. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1269. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1270. else
  1271. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1272. } else {
  1273. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1274. }
  1275. if ($iassign_submission)
  1276. $this->update_comment($iassign_submission->id);
  1277. $file = $iassign_statement_activity_item->file;
  1278. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1279. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1280. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1281. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1282. $this->bottonPost = 0; // hide submit button
  1283. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1284. $this->view_iassign = false; // disable visualization of activity
  1285. $repeat = "";
  1286. $last_iassign = "";
  1287. $student_answer = "";
  1288. $comment = "";
  1289. // *** Teacher access (view learner's submission)
  1290. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1291. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1292. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1293. // ---> access teacher for test
  1294. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1295. $this->bottonPost = 1;
  1296. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1297. $this->activity->view_dates();
  1298. $USER->iassignEdit = $this->bottonPost;
  1299. $this->activity->show_info_iassign();
  1300. if ($iassign_submission) {
  1301. //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;
  1302. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1303. } else {
  1304. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1305. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1306. }
  1307. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1308. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1309. // Prepare tags to present the iLM
  1310. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1311. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1312. // *** (end) Teacher access (view the activity)
  1313. // *** Teacher access (view learner's submission to the activity)
  1314. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1315. // It is teacher or 'nonediting teacher' that can evaluate
  1316. // ----> area teacher evaluate
  1317. $row = optional_param('row', 0, PARAM_INT);
  1318. $column = optional_param('column', 0, PARAM_INT);
  1319. $link_next = iassign_icons::insert('right_disable');
  1320. $link_previous = iassign_icons::insert('left_disable');
  1321. $link_up = iassign_icons::insert('up_disable');
  1322. $link_down = iassign_icons::insert('down_disable');
  1323. // next_activity
  1324. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1325. $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);
  1326. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1327. }
  1328. // previous_activity
  1329. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1330. $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);
  1331. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1332. }
  1333. // previous_student
  1334. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1335. $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);
  1336. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1337. }
  1338. // next_student
  1339. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1340. $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);
  1341. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1342. }
  1343. if ($iassign_submission) {
  1344. $student_answer = $iassign_submission->answer;
  1345. }
  1346. $last_iassign = get_string('last_iassign', 'iassign');
  1347. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1348. // Messages related to due date (and user role)
  1349. $this->activity->view_dates();
  1350. print $OUTPUT->box_start();
  1351. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1352. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1353. print $OUTPUT->user_picture($user_data);
  1354. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1355. print '</td>' . "\n";
  1356. print '<td width=20% align=right>' . "\n";
  1357. print '<table width=50 cellpadding="0">';
  1358. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1359. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1360. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1361. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1362. print '</table>' . "\n";
  1363. print '</td></tr></table>' . "\n";
  1364. print $OUTPUT->box_end();
  1365. print $OUTPUT->box_start();
  1366. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1367. print '<td width=60% valign="top">' . "\n";
  1368. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1369. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1370. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1371. $resp = get_string('yes');
  1372. else
  1373. $resp = get_string('no');
  1374. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1375. if ($iassign_statement_activity_item->show_answer == 1)
  1376. $resp = get_string('yes');
  1377. else
  1378. $resp = get_string('no');
  1379. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1380. print '</td>';
  1381. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1382. print '<td width=40% valign="top" align="left">';
  1383. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1384. // check status of solution sent by the student
  1385. if ($iassign_submission) {
  1386. switch ($iassign_submission->status) {
  1387. case 3 :
  1388. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1389. break;
  1390. case 2 :
  1391. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1392. break;
  1393. case 1 :
  1394. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1395. break;
  1396. default :
  1397. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1398. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1399. } // switch ($iassign_submission->status)
  1400. }
  1401. else { // if ($iassign_submission)
  1402. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1403. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1404. }
  1405. // update_status
  1406. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1407. $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);
  1408. print " <script type='text/javascript'>
  1409. //<![CDATA[
  1410. function overwriteStatus (newstatus) {
  1411. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1412. document.formEditStatus.return_status.value=newstatus;
  1413. document.formEditStatus.submit();
  1414. }
  1415. else
  1416. document.formEditStatus.return_status.value=-1;
  1417. }
  1418. //]]>
  1419. </script>";
  1420. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1421. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1422. 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";
  1423. print " <input type='hidden' name='return_status'>\n";
  1424. print "</form>\n";
  1425. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1426. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1427. $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);
  1428. print "
  1429. <script type='text/javascript'>
  1430. //<![CDATA[
  1431. function overwriteGrade (newgrade,maxgrade) {
  1432. if (newgrade<0 || newgrade>maxgrade) {
  1433. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1434. document.formEditGrade.return_grade.value=-1;
  1435. document.formEditGrade.submit();
  1436. }
  1437. else {
  1438. document.formEditGrade.return_grade.value=newgrade;
  1439. document.formEditGrade.submit();
  1440. }
  1441. }
  1442. //]]>
  1443. </script>";
  1444. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1445. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1446. print " <input type='text' name='grade' size='6'>";
  1447. print " <input type='hidden' name='return_grade'> ";
  1448. 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";
  1449. print "</form>";
  1450. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1451. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1452. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1453. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1454. if ($teacher)
  1455. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1456. } // if ($iassign_submission->experiment > 0)
  1457. print '</td>';
  1458. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1459. print '</tr></table>';
  1460. print $OUTPUT->box_end();
  1461. $USER->iassignEdit = $this->bottonPost;
  1462. if ($iassign_submission && $allow_resubmission) {
  1463. // Put the iLM to
  1464. print $OUTPUT->box_start();
  1465. print '<p><strong>' . $last_iassign . '</strong></p>';
  1466. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1467. $enderecoPOST = "";
  1468. // Prepare tags to present the iLM
  1469. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1470. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1471. print $OUTPUT->box_end();
  1472. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1473. // ATTENTION: exception used by iGeom (exercise with "script")
  1474. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1475. if (substr($ilm_name, 0, 5)=="igeom") {
  1476. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1477. $loadTeacherActivity = true;
  1478. }
  1479. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1480. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1481. // Prepare tags to present the iLM
  1482. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1483. }
  1484. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1485. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1486. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1487. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1488. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1489. // *** (end) Teacher access (view learner's submission to the activity)
  1490. // *** Student access (view the activity)
  1491. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1492. // It could be the learner (he could send or resend the activity)
  1493. // ---> access student
  1494. $time_now = time();
  1495. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1496. // activity of type example - not submit button for submission
  1497. $this->view_iassign = true;
  1498. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1499. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1500. // activity of type test - iLM automatic evaluator - submit button for submission
  1501. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1502. $this->bottonPost = 1;
  1503. $this->view_iassign = true;
  1504. } else
  1505. $this->view_iassign = false;
  1506. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1507. // activity of type exercise (learner can send his answer, if yet open...)
  1508. $this->view_iassign = true;
  1509. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1510. $this->view_iassign = false;
  1511. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1512. $this->bottonPost = 1; // allow the submit button
  1513. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1514. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1515. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1516. if (!$iassign_submission) {
  1517. $str_iassign_submission_id = '';
  1518. $str_iassign_submission_answer = '';
  1519. }
  1520. else {
  1521. $str_iassign_submission_id = $iassign_submission->id;
  1522. $str_iassign_submission_answer = $iassign_submission->answer;
  1523. }
  1524. if ($this->action != 'repeat') {
  1525. $repeat = "<a href='view.php?action=repeat&id="
  1526. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1527. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1528. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1529. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1530. }
  1531. $this->bottonPost = 1;
  1532. $this->write_solution = 1; // can register his submission
  1533. $student_answer = $str_iassign_submission_answer;
  1534. }
  1535. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1536. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1537. $last_iassign = get_string('last_iassign', 'iassign');
  1538. if ($iassign_submission) {
  1539. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1540. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1541. $student_answer = $iassign_submission->answer;
  1542. } else {
  1543. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1544. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1545. }
  1546. }
  1547. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1548. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1549. $this->bottonPost = 1;
  1550. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1551. } else {
  1552. $last_iassign = get_string('last_iassign', 'iassign');
  1553. if ($iassign_submission) {
  1554. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1555. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1556. $student_answer = $iassign_submission->answer;
  1557. } else {
  1558. // Symbol of "redo activity"
  1559. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1560. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1561. }
  1562. }
  1563. } // elseif ($iassign_statement_activity_item->test == 1)
  1564. elseif ($iassign_statement_activity_item->test == 0)
  1565. $this->view_iassign = false;
  1566. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1567. if ($iassign_submission)
  1568. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1569. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1570. else
  1571. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1572. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1573. $this->activity->view_dates();
  1574. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1575. print $OUTPUT->box_start();
  1576. print '<table width=100% border=0 valign="top">' . "\n";
  1577. print '<tr><td width=60% valign="top">' . "\n";
  1578. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1579. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1580. $flag_dependency = true;
  1581. if ($iassign_statement_activity_item->type_iassign == 3) {
  1582. if ($iassign_statement_activity_item->dependency == 0) {
  1583. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1584. } else {
  1585. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1586. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1587. foreach ($dependencys as $dependency) {
  1588. if ($dependency) {
  1589. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1590. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1591. if ($dependencysubmissions) {
  1592. if ($dependencysubmissions->status == 3)
  1593. $icon = iassign_icons::insert('correct');
  1594. elseif ($dependencysubmissions->status == 2) {
  1595. $icon = iassign_icons::insert('incorrect');
  1596. $flag_dependency = false;
  1597. } elseif ($dependencysubmissions->status == 1) {
  1598. $icon = iassign_icons::insert('post');
  1599. $flag_dependency = false;
  1600. } elseif ($dependencysubmissions->status == 0) {
  1601. $icon = iassign_icons::insert('not_post');
  1602. $flag_dependency = false;
  1603. }
  1604. } else {
  1605. $icon = iassign_icons::insert('not_post');
  1606. $flag_dependency = false;
  1607. } // if ($dependencysubmissions)
  1608. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1609. } // if ($dependency)
  1610. } // foreach ($dependencys as $dependency)
  1611. } // if ($iassign_statement_activity_item->dependency == 0)
  1612. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1613. if ($flag_dependency == false) {
  1614. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1615. $this->view_iassign = false;
  1616. print '</tr></table>' . "\n";
  1617. }
  1618. else {
  1619. $this->view_iassign = true;
  1620. print '</td>' . "\n";
  1621. } // if ($flag_dependency == false)
  1622. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1623. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1624. // receiver=1 - message to teacher
  1625. // receiver=2 - message to student
  1626. if ($iassign_submission) {
  1627. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1628. if ($verify_message)
  1629. $comment = iassign_icons::insert('comment_unread');
  1630. }
  1631. print '<td width=40% valign="top" align="left">';
  1632. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1633. if ($iassign_statement_activity_item->show_answer == 1) {
  1634. // check status of solution sent by the student
  1635. if ($iassign_submission) {
  1636. switch ($iassign_submission->status) {
  1637. case 3 :
  1638. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1639. break;
  1640. case 2 :
  1641. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1642. break;
  1643. case 1 :
  1644. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1645. break;
  1646. default :
  1647. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1648. $repeat = "";
  1649. $last_iassign = "";
  1650. } // switch ($iassign_submission->status)
  1651. } else {
  1652. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1653. $repeat = "";
  1654. $last_iassign = "";
  1655. }
  1656. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1657. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  1658. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  1659. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  1660. if ($iassign_statement_activity_item->max_experiment == 0)
  1661. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  1662. else {
  1663. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  1664. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  1665. $repeat = "";
  1666. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  1667. $this->bottonPost = 0;
  1668. $this->write_solution = 0;
  1669. }
  1670. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  1671. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  1672. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1673. if ($teacher)
  1674. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  1675. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  1676. } // if ($iassign_statement_activity_item->show_answer==1)
  1677. else {
  1678. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  1679. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1680. $repeat = "";
  1681. $last_iassign = "";
  1682. } elseif ($iassign_submission->status == 1) {
  1683. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1684. }
  1685. }
  1686. print '</td>';
  1687. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1688. print '</tr></table>' . "\n";
  1689. // Presents the iLM
  1690. print '<table width=100% border=0 valign="top">' . "\n";
  1691. print '<td width=80% align="left">';
  1692. 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\".
  1693. print '<td width=20% align="rigth">';
  1694. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  1695. print $repeat; // symbol of "redo activity"
  1696. print '</td></tr></table>' . "\n";
  1697. //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)'
  1698. $output = '';
  1699. if (!$iassign_ilm) {
  1700. $iassign_ilm = new stdClass();
  1701. $iassign_ilm->file_jar = "";
  1702. }
  1703. $output .= $OUTPUT->box_start();
  1704. $USER->iassignEdit = $this->bottonPost;
  1705. // ---
  1706. // Presents the iLM
  1707. // Prepare tags to present the iLM
  1708. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  1709. $student_answer = ""; //?
  1710. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  1711. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  1712. $student_answer = "";
  1713. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  1714. } else {
  1715. // When student is redoing his activity
  1716. // ATTENTION: exception used by iGeom (exercise with "script")
  1717. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  1718. if (substr($ilm_name, 0, 5)=="igeom") {
  1719. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1720. $loadTeacherActivity = true;
  1721. }
  1722. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  1723. }
  1724. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  1725. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  1726. //1 $history_comment = '';
  1727. //1 if ($iassign_submission) {
  1728. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  1729. //1 }
  1730. //1 if (!empty($history_comment)) {
  1731. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  1732. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  1733. //1 $output .= $history_comment;
  1734. //1 $output .= "</table>\n";
  1735. //1 }
  1736. //1 $output .= "</form></center>\n";
  1737. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  1738. //1 }
  1739. $output .= $OUTPUT->box_end();
  1740. print $output;
  1741. } // if ($this->view_iassign)
  1742. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  1743. } // if ($this->view_iassign)
  1744. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1745. else
  1746. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1747. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  1748. print '<table width=100% border=0 valign="top">' . "\n";
  1749. print '<tr><td width=60% valign="top">' . "\n";
  1750. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1751. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1752. print '</tr></table>' . "\n";
  1753. $student_answer = "";
  1754. $enderecoPOST = "";
  1755. // Prepare tags to present the iLM
  1756. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  1757. print $output;
  1758. }
  1759. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  1760. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1761. 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
  1762. // Put a block with area to sent/answer comments
  1763. $output = '';
  1764. $history_comment = '';
  1765. $row = optional_param('row', 0, PARAM_INT);
  1766. $column = optional_param('column', 0, PARAM_INT);
  1767. if ($iassign_submission) {
  1768. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1769. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1770. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1771. }
  1772. else {
  1773. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1774. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1775. }
  1776. $output .= $OUTPUT->box_start();
  1777. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  1778. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  1779. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  1780. $output .= "</form></center>\n";
  1781. if (!empty($history_comment)) {
  1782. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  1783. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  1784. $output .= $history_comment;
  1785. $output .= "</table>";
  1786. }
  1787. $output .= $OUTPUT->box_end();
  1788. print $output;
  1789. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1790. // final block 'studant'
  1791. print $OUTPUT->footer();
  1792. die();
  1793. } // function view_iassign_current()
  1794. /// Export the data from performance report into CSV file format
  1795. function export_csv () {
  1796. global $USER, $CFG, $DB, $OUTPUT;
  1797. $str = "";
  1798. $fields = "student_id, student_name";
  1799. // Finding all iassign activities for the iassign:
  1800. $id = $this->cm->id;
  1801. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1802. $c = 1;
  1803. foreach ($iassign_list as $iassign) {
  1804. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  1805. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  1806. $c ++;
  1807. }
  1808. // Finding enrolled students:
  1809. $params = array('shortname' => 'student');
  1810. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  1811. $context = context_course::instance($this->course->id);
  1812. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1813. $students = $DB->get_records_sql(
  1814. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1815. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1816. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1817. foreach ($students as $student) {
  1818. $str .= $student->userid . ',';
  1819. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  1820. foreach ($iassign_list as $iassign) {
  1821. $str .= ',' . $iassign->id . ',';
  1822. $str .= '"' . $iassign->name . '",';
  1823. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  1824. if ($student_submissions) {
  1825. $str .= $student_submissions->experiment . ',';
  1826. $str .= $student_submissions->grade . ',';
  1827. switch ($student_submissions->status) {
  1828. case 3:
  1829. $str .= '"correct",';
  1830. break;
  1831. case 2:
  1832. $str .= '"incorrect",';
  1833. break;
  1834. case 1:
  1835. $str .= '"post",';
  1836. break;
  1837. case 0:
  1838. $str .= '"not_post",';
  1839. break;
  1840. }
  1841. } else {
  1842. $str .= ',,"not_post",';
  1843. }
  1844. $str .= $iassign->iassign_ilmid . ',';
  1845. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  1846. $str .= '"' . $ilm_activity->name . '"';
  1847. }
  1848. $str .= "\n";
  1849. }
  1850. $str = $fields . "\n" . $str;
  1851. header("Content-type: text/csv");
  1852. header("Content-disposition: attachment; filename=report.csv");
  1853. header("Pragma: no-cache");
  1854. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  1855. header('Content-Length: ' . strlen($str));
  1856. header('Connection: close');
  1857. print $str;
  1858. flush();
  1859. } // function export_csv()
  1860. /// Display report of performance
  1861. function report () {
  1862. global $USER, $CFG, $DB, $OUTPUT;
  1863. $id = $this->cm->id;
  1864. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1865. if ($this->action != 'print') {
  1866. $title = get_string('report', 'iassign');
  1867. print $OUTPUT->header();
  1868. } // if ($this->action != 'print')
  1869. print $OUTPUT->box_start();
  1870. $this->view_legend_icons();
  1871. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  1872. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  1873. print $OUTPUT->box_end();
  1874. if ($this->action == 'print')
  1875. print '<table border=1 width="100%">' . "\n";
  1876. else
  1877. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1878. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  1879. // $num = array();
  1880. $i = 1;
  1881. $num = array();
  1882. foreach ($iassign_list as $iassign) {
  1883. $test_exercise = "";
  1884. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  1885. if (($iassign_submission) && $iassign->type_iassign < 3) {
  1886. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  1887. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  1888. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  1889. $num[$i] = new stdClass();
  1890. $num[$i]->name = $iassign->name;
  1891. $num[$i]->id = $i;
  1892. $num[$i]->iassignid = $iassign->id;
  1893. print ' <tr >' . "\n";
  1894. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  1895. print "<td class=\"cell c0 actvity\">";
  1896. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  1897. print ' </tr>' . "\n";
  1898. $i ++;
  1899. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  1900. } // foreach ($iassign_list as $iassign)
  1901. print "</table>";
  1902. print "<p></p>";
  1903. if ($this->action == 'print')
  1904. print '<table border=1 width="100%">' . "\n";
  1905. else
  1906. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1907. $context = context_course::instance($this->course->id);
  1908. if ($i > 1) {
  1909. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  1910. $params = array('shortname' => 'student');
  1911. $role = $DB->get_record_sql(
  1912. "SELECT s.id, s.shortname FROM {role} s " .
  1913. " WHERE s.shortname = :shortname", $params);
  1914. // $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");
  1915. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1916. $students = $DB->get_records_sql(
  1917. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1918. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1919. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1920. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  1921. for ($j = 1; $j < $i; $j ++) {
  1922. $sum_iassign_correct[$j] = 0;
  1923. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  1924. }
  1925. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  1926. $sum_iassign = $j - 1;
  1927. print '</tr>' . "\n";
  1928. $total = 0;
  1929. $sum_student = 0;
  1930. $comment = iassign_icons::insert('comment_read');
  1931. $sum_comment = 0;
  1932. $sum_correct_iassign = array();
  1933. $sum_correct_student = array();
  1934. $USER->matrix_iassign = array();
  1935. if ($students) {
  1936. $w = 0;
  1937. foreach ($students as $tmp) {
  1938. $users_array[$w] = $tmp;
  1939. $w ++;
  1940. }
  1941. for ($x = 0; $x < $w; $x ++) {
  1942. print '<tr>' . "\n";
  1943. $sum_student ++;
  1944. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  1945. print ' <td >' . $name . '</td>' . "\n";
  1946. $total_student = 0;
  1947. $tentativas = 0;
  1948. for ($j = 1; $j < $i; $j ++) {
  1949. $sum_comment = 0;
  1950. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  1951. print ' <td valign="bottom" align="center">' . "\n";
  1952. if ($student_submissions) {
  1953. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  1954. $tentativas = $student_submissions->experiment;
  1955. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  1956. $params = array('iassign_submissionid' => $student_submissions->id);
  1957. $student_submissions_comment = $DB->get_record_sql(
  1958. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1959. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  1960. if ($student_submissions_comment)
  1961. foreach ($student_submissions_comment as $tmp)
  1962. $sum_comment = $tmp;
  1963. // informations to previous activities
  1964. if ($j - 1 < 1 || $j == $i)
  1965. $iassign_previous = "-1";
  1966. else
  1967. $iassign_previous = $num[$j - 1]->iassignid;
  1968. if ($x - 1 < 0 || $x == $w)
  1969. $user_previous = "-1";
  1970. else
  1971. $user_previous = $users_array[$x - 1]->userid;
  1972. // next
  1973. if ($i - 1 > $j)
  1974. $iassign_next = $num[$j + 1]->iassignid;
  1975. else
  1976. $iassign_next = "-1";
  1977. if ($w - 1 > $x)
  1978. $user_next = $users_array[$x + 1]->userid;
  1979. else
  1980. $user_next = "-1";
  1981. $position = "&row= $x&column=$j";
  1982. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  1983. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1984. $url .= $position;
  1985. // receiver=1 - message to teacher
  1986. // receiver=2 - message to student
  1987. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  1988. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  1989. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  1990. $verify_message = $DB->get_record_sql(
  1991. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1992. "WHERE iassign_submissionid = :iassign_submissionid " .
  1993. " AND return_status= :return_status " .
  1994. " AND receiver= :receiver", $params);
  1995. if ($verify_message)
  1996. foreach ($verify_message as $tmp)
  1997. $sum_verify_message = $tmp;
  1998. if ($sum_verify_message > 0)
  1999. $comment = iassign_icons::insert('comment_unread');
  2000. else
  2001. $comment = iassign_icons::insert('comment_read');
  2002. if ($student_submissions->status == 3) {
  2003. $sum_iassign_correct[$j] ++;
  2004. $total_student ++;
  2005. $feedback = iassign_icons::insert('correct');
  2006. }
  2007. elseif ($student_submissions->status == 2) {
  2008. $feedback = iassign_icons::insert('incorrect');
  2009. }
  2010. elseif ($student_submissions->status == 1) {
  2011. $feedback = iassign_icons::insert('post');
  2012. }
  2013. elseif ($student_submissions->status == 0) {
  2014. $feedback = iassign_icons::insert('not_post');
  2015. }
  2016. if ($this->action != 'print') {
  2017. print '<table><tr>';
  2018. if ($tentativas > 0)
  2019. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2020. else
  2021. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2022. print '<td> &nbsp; </td>';
  2023. print '</tr>' . "\n";
  2024. if ($sum_comment > 0 && $sum_verify_message > 0)
  2025. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2026. else if ($sum_comment > 0)
  2027. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2028. print '</table>' . "\n";
  2029. }
  2030. if ($this->action == 'print')
  2031. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2032. } // if ($student_submissions)
  2033. else { // if ($student_submissions)
  2034. // informations to browse previous activities
  2035. if ($j - 1 < 1 || $j == $i)
  2036. $iassign_previous = "-1";
  2037. else
  2038. $iassign_previous = $num[$j - 1]->iassignid;
  2039. if ($x - 1 < 0 || $x == $w)
  2040. $user_previous = "-1";
  2041. else
  2042. $user_previous = $users_array[$x - 1]->userid;
  2043. // next
  2044. if ($i - 1 > $j)
  2045. $iassign_next = $num[$j + 1]->iassignid;
  2046. else
  2047. $iassign_next = "-1";
  2048. if ($w - 1 > $x)
  2049. $user_next = $users_array[$x + 1]->userid;
  2050. else
  2051. $user_next = "-1";
  2052. $position = "&row= $x&column=$j";
  2053. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2054. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2055. $url .= $position;
  2056. $feedback = iassign_icons::insert('not_post');
  2057. if ($this->action == 'print')
  2058. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2059. else {
  2060. print '<table><tr>';
  2061. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2062. print '<td> &nbsp; </td>';
  2063. print '</tr><tr>' . "\n";
  2064. print '<td> &nbsp;</td>';
  2065. if ($sum_comment > 0)
  2066. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2067. else
  2068. print '<td> &nbsp;</td>';
  2069. print '</tr></table>';
  2070. }
  2071. } // else if ($student_submissions)
  2072. $USER->matrix_iassign[$x][$j] = new stdClass();
  2073. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2074. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2075. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2076. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2077. if ($student_submissions)
  2078. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2079. else
  2080. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2081. print '</td>' . "\n";
  2082. } // for ($j=1; $j<$i; $j++)
  2083. $total = $total + $total_student;
  2084. $porcentagem = ($total_student / ($j - 1)) * 100;
  2085. if ($tentativas != 0 && $tentativas != null) {
  2086. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2087. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2088. }
  2089. else {
  2090. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2091. }
  2092. print '</tr>' . "\n";
  2093. $sum_correct_student[$sum_student] = new stdClass();
  2094. $sum_correct_student[$sum_student]->name = $name;
  2095. $sum_correct_student[$sum_student]->sum = $total_student;
  2096. } // for ($x = 0; $x < $w; $x ++)
  2097. for ($i = 1; $i < $j; $i ++) {
  2098. if (is_null($sum_iassign_correct[$i]))
  2099. $sum_iassign_correct[$i] = 0;
  2100. $sum_correct_iassign[$i] = new stdClass();
  2101. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2102. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2103. }
  2104. // print '</tr></table>' . "\n";
  2105. }
  2106. } // if ($i>1)
  2107. else {
  2108. print_string('no_activity', 'iassign');
  2109. }
  2110. print "</table>\n";
  2111. if ($this->action != 'print')
  2112. print $OUTPUT->footer();
  2113. die();
  2114. } // function report()
  2115. /// Display graphics of performance
  2116. function stats () {
  2117. global $USER, $CFG, $DB, $OUTPUT;
  2118. $id = $this->cm->id;
  2119. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2120. if ($this->action != 'printstats')
  2121. $title = get_string('graphic', 'iassign');
  2122. $num = array();
  2123. $sum_correct_iassign = array();
  2124. $sum_correct_student = array();
  2125. $sum_student = 0;
  2126. $i = 1;
  2127. foreach ($iassign_list as $iassign) {
  2128. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2129. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2130. $sum_iassign_correct[$i] = 0;
  2131. $num[$i] = new stdClass();
  2132. $num[$i]->name = $iassign->name;
  2133. $num[$i]->id = $i;
  2134. $num[$i]->iassignid = $iassign->id;
  2135. $i ++;
  2136. } // if ($iassign->type_iassign == 3)
  2137. } // foreach ($iassign_list as $iassign)
  2138. $sum_iassign = $i - 1;
  2139. $context = context_course::instance($this->course->id);
  2140. if ($i > 1) {
  2141. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2142. $params = array('shortname' => 'student');
  2143. $role = $DB->get_record_sql(
  2144. "SELECT s.id, s.shortname FROM {role} s " .
  2145. " WHERE s.shortname = :shortname", $params);
  2146. // $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");
  2147. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2148. $students = $DB->get_records_sql(
  2149. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2150. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2151. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2152. $total = 0;
  2153. $sum_student = 0;
  2154. $j = 0;
  2155. $sum_correct_iassign = array();
  2156. $sum_correct_student = array();
  2157. $sum_experiment = array();
  2158. if ($students) {
  2159. foreach ($students as $users) {
  2160. $sum_student ++;
  2161. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2162. // rows
  2163. $total_student = 0;
  2164. for ($j = 1; $j < $i; $j ++) {
  2165. $total_experiment = 0;
  2166. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2167. if ($student_submissions) {
  2168. if ($student_submissions->status == 3) {
  2169. $sum_iassign_correct[$j] ++;
  2170. $total_student ++;
  2171. } // if ($student_submissions->status == 3)
  2172. $total_experiment += $student_submissions->experiment;
  2173. }
  2174. $sum_experiment[$j] = $total_experiment;
  2175. } // for ($j=1; $j<$i; $j++)
  2176. $total = $total + $total_student;
  2177. $sum_correct_student[$sum_student] = new stdClass();
  2178. $sum_correct_student[$sum_student]->name = $name;
  2179. $sum_correct_student[$sum_student]->sum = $total_student;
  2180. } // foreach ($students as $users)
  2181. }
  2182. for ($i = 1; $i < $j; $i ++) {
  2183. if (is_null($sum_iassign_correct[$i]))
  2184. $sum_iassign_correct[$i] = 0;
  2185. $sum_correct_iassign[$i] = new stdClass();
  2186. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2187. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2188. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2189. } // for ($i = 1; $i < $j; $i++)
  2190. } // if ($i > 1)
  2191. if ($this->action != 'printstats') {
  2192. $title = get_string('graphic', 'iassign');
  2193. print $OUTPUT->header();
  2194. $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>";
  2195. $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>";
  2196. print '<table width=100%><tr>';
  2197. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2198. print '<td width=15% align="right">' . $link_report . '</td>';
  2199. print '</td></tr></table>' . "\n";
  2200. print "<br><br>";
  2201. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2202. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2203. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2204. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2205. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2206. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2207. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2208. print '</tr>' . "\n";
  2209. $sum_correct = 0;
  2210. if ($sum_correct_iassign) {
  2211. foreach ($sum_correct_iassign as $iassign) {
  2212. if (is_null($iassign->experiment))
  2213. $iassign->experiment = 0;
  2214. $bar = "";
  2215. $sum = $iassign->sum;
  2216. $percent = ($sum / $sum_student) * 100;
  2217. $text = number_format($percent, 1) . '%';
  2218. $sum_correct += $sum;
  2219. if ($sum > 0) {
  2220. for ($i = 1; $i < $percent * 2; $i ++)
  2221. $bar .= iassign_icons::insert('hbar_blue');
  2222. $bar .= iassign_icons::insert('hbar_blue_r');
  2223. } // if ($sum > 0)
  2224. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2225. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2226. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2227. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2228. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2229. print '</tr>' . "\n";
  2230. } // foreach ($sum_correct_iassign as $iassign)
  2231. }
  2232. print "</table>";
  2233. print "<br><br>";
  2234. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2235. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2236. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2237. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2238. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2239. print '</tr>' . "\n";
  2240. $sum_correct = 0;
  2241. foreach ($sum_correct_student as $student) {
  2242. $bar = "";
  2243. $sum = $student->sum;
  2244. $percent = ($sum / $sum_iassign) * 100;
  2245. $text = number_format($percent, 1) . '%';
  2246. $sum_correct += $sum;
  2247. if ($sum > 0) {
  2248. for ($i = 1; $i < $percent * 2; $i ++)
  2249. $bar .= iassign_icons::insert('hbar_blue');
  2250. $bar .= iassign_icons::insert('hbar_blue_r');
  2251. } // if ($sum > 0)
  2252. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2253. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2254. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2255. print '</tr>' . "\n";
  2256. } // foreach ($sum_correct_student as $student)
  2257. print "</table>\n";
  2258. print "<br><br>\n";
  2259. $var = 0;
  2260. $cv = 0;
  2261. $dv = 0;
  2262. $avg = 0;
  2263. if ($sum_correct_student) {
  2264. $avg = $sum_correct / $sum_student;
  2265. if ($avg > 0) {
  2266. foreach ($sum_correct_student as $student)
  2267. $var += pow($student->sum - $avg, 2);
  2268. $var = $var / $sum_student;
  2269. $dv = sqrt($var);
  2270. $cv = ($dv / $avg) * 100;
  2271. }
  2272. }
  2273. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2274. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2275. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2276. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2277. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2278. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2279. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2280. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2281. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2282. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2283. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2284. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2285. print "</table>\n";
  2286. print $OUTPUT->footer();
  2287. } else {
  2288. print "<STYLE TYPE='text/css'>
  2289. <!--
  2290. .boldtable {
  2291. font-family:sans-serif;
  2292. font-size:10pt;
  2293. }
  2294. -->
  2295. </STYLE>\n";
  2296. print '<table border=1 width=100%>' . "\n";
  2297. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2298. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2299. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2300. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2301. print '</tr>' . "\n";
  2302. $sum_correct = 0;
  2303. foreach ($sum_correct_iassign as $iassign) {
  2304. $bar = "";
  2305. $sum = $iassign->sum;
  2306. $percent = ($sum / $sum_student) * 100;
  2307. $text = number_format($percent, 1) . '%';
  2308. $sum_correct += $sum;
  2309. if ($sum > 0) {
  2310. for ($i = 1; $i < $percent * 2; $i ++)
  2311. $bar .= iassign_icons::insert('hbar_blue');
  2312. $bar .= iassign_icons::insert('hbar_blue_r');
  2313. } // if ($sum > 0)
  2314. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2315. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2316. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2317. print '</tr>' . "\n";
  2318. } // foreach ($sum_correct_iassign as $iassign)
  2319. print "</table>";
  2320. print "<br><br>";
  2321. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2322. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2323. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2324. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2325. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2326. print '</tr>' . "\n";
  2327. $sum_correct = 0;
  2328. foreach ($sum_correct_student as $student) {
  2329. $bar = "";
  2330. $sum = $student->sum;
  2331. $percent = ($sum / $sum_iassign) * 100;
  2332. $text = number_format($percent, 1) . '%';
  2333. $sum_correct += $sum;
  2334. if ($sum > 0) {
  2335. for ($i = 1; $i < $percent * 2; $i ++)
  2336. $bar .= iassign_icons::insert('hbar_blue');
  2337. $bar .= iassign_icons::insert('hbar_blue_r');
  2338. } // if ($sum > 0)
  2339. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2340. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2341. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2342. print '</tr>' . "\n";
  2343. } // foreach ($sum_correct_student as $student)
  2344. print "</table>\n";
  2345. print "<br/><br/>\n";
  2346. $var = 0;
  2347. $cv = 0;
  2348. $dv = 0;
  2349. $avg = 0;
  2350. if ($sum_correct_student) {
  2351. $avg = $sum_correct / $sum_student;
  2352. if ($avg > 0) {
  2353. foreach ($sum_correct_student as $student)
  2354. $var += pow($student->sum - $avg, 2);
  2355. $var = $var / $sum_student;
  2356. $dv = sqrt($var);
  2357. $cv = ($dv / $avg) * 100;
  2358. }
  2359. }
  2360. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2361. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2362. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2363. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2364. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2365. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2366. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2367. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2368. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2369. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2370. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2371. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2372. print "</table>\n";
  2373. } // if ($this->action != 'printstats')
  2374. die();
  2375. }
  2376. /// Display graphics of performance for students
  2377. function stats_students () {
  2378. global $USER, $CFG, $DB, $OUTPUT;
  2379. $id = $this->cm->id;
  2380. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2381. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2382. $title = get_string('results', 'iassign');
  2383. $sum_correct = 0;
  2384. $sum_incorrect = 0;
  2385. $sum_post = 0;
  2386. $sum_nopost = 0;
  2387. $sum_iassign = count($iassign_statement_list);
  2388. $bar_nopost = "";
  2389. $bar_correct = "";
  2390. $bar_incorrect = "";
  2391. $bar_post = "";
  2392. $text_nopost = "";
  2393. $text_correct = "";
  2394. $text_incorrect = "";
  2395. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2396. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2397. if ($iassign_submission) {
  2398. if ($iassign_submission->status == 3)
  2399. $sum_correct ++;
  2400. elseif ($iassign_submission->status == 2)
  2401. $sum_incorrect ++;
  2402. elseif ($iassign_submission->status == 1)
  2403. $sum_post ++;
  2404. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2405. $sum_nopost ++;
  2406. } // if ($iassign_submission)
  2407. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2408. if ($sum_iassign > 0) {
  2409. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2410. $text_correct = number_format($percent_correct, 1) . '%';
  2411. }
  2412. if ($sum_correct > 0) {
  2413. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2414. $bar_correct .= iassign_icons::insert('hbar_green');
  2415. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2416. } // if ($sum_correct > 0)
  2417. if ($sum_iassign > 0) {
  2418. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2419. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2420. }
  2421. if ($sum_incorrect > 0) {
  2422. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2423. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2424. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2425. } // if ($sum_incorrect > 0)
  2426. if ($sum_iassign > 0) {
  2427. $percent_post = ($sum_post / $sum_iassign) * 100;
  2428. $text_post = number_format($percent_post, 1) . '%';
  2429. }
  2430. if ($sum_post > 0) {
  2431. for ($i = 1; $i < $percent_post * 2; $i ++)
  2432. $bar_post .= iassign_icons::insert('hbar_blue');
  2433. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2434. } // if ($sum_post > 0)
  2435. if ($sum_iassign > 0) {
  2436. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2437. $text_nopost = number_format($percent_nopost, 1) . '%';
  2438. }
  2439. if ($sum_nopost > 0) {
  2440. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2441. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2442. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2443. } // if ($sum_nopost > 0)
  2444. print $OUTPUT->header();
  2445. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2446. print '<table width=100%><tr>';
  2447. print '<td align="right">' . $link_return . '</td>' . "\n";
  2448. print '</td></tr></table>' . "\n";
  2449. print "<br/><br/>\n";
  2450. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2451. print '<tr><th colspan=3 class="header c1">' . "\n";
  2452. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2453. // $imagetext = '');
  2454. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2455. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2456. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2457. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2458. print '</tr>' . "\n";
  2459. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2460. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2461. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2462. print '</tr>' . "\n";
  2463. if ($sum_post) {
  2464. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2465. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2466. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2467. print '</tr>' . "\n";
  2468. } // if ($sum_post)
  2469. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2470. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2471. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2472. print '</tr>' . "\n";
  2473. print "</table>";
  2474. print "<br><br>";
  2475. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2476. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2477. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2478. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2479. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2480. $sum_grade = 0;
  2481. $sum_grade_student = 0;
  2482. $avg = 0;
  2483. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2484. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2485. if (!$iassign_submission) {
  2486. $iassign_submission = new stdClass();
  2487. $iassign_submission->grade = 0;
  2488. }
  2489. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2490. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2491. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2492. print '</tr>' . "\n";
  2493. $sum_grade += $iassign_statement_activity_item->grade;
  2494. $sum_grade_student += $iassign_submission->grade;
  2495. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2496. if ($sum_grade > 0)
  2497. $avg = $sum_grade_student / $sum_grade * 100;
  2498. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2499. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2500. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2501. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2502. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2503. print "</table>";
  2504. print $OUTPUT->footer();
  2505. die();
  2506. } // function stats_students()
  2507. /// Display page of iAssign's activity
  2508. function view_iassigns () {
  2509. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2510. $id = $this->cm->id;
  2511. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2512. $notice = optional_param('notice', '', PARAM_TEXT);
  2513. if (strpos($notice, 'error'))
  2514. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2515. else if ($notice != '')
  2516. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2517. print $OUTPUT->box_start();
  2518. print '<table width=100% border=0><tr>' . "\n";
  2519. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2520. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2521. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2522. $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>";
  2523. $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>";
  2524. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2525. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2526. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2527. // Has capability to see "report": teacher or up
  2528. print '<td width=10% align="left">' . "\n";
  2529. print $link_help;
  2530. print '</td>' . "\n";
  2531. print '<td width=10% align="left">' . "\n";
  2532. print $link_report;
  2533. print '</td>' . "\n";
  2534. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2535. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2536. print '<td width=15% align="left">' . "\n";
  2537. print $link_add;
  2538. print "</td>\n";
  2539. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2540. //print '</tr></table>' . "\n";
  2541. print '<div style="float: right;">';
  2542. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2543. if ($iassign_list) {
  2544. print '<td align="right">' . "\n";
  2545. // $USER->iassignEdit == 0 view 'Turn editing off'
  2546. // $USER->iassignEdit == 1 view 'Turn editing on'
  2547. if (!isset($USER->iassignEdit))
  2548. $USER->iassignEdit = 0;
  2549. if ($USER->iassignEdit == 0) {
  2550. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2551. $botton = 1;
  2552. } // if ($USER->iassignEdit == 0)
  2553. elseif ($USER->iassignEdit == 1) {
  2554. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2555. $botton = 0;
  2556. } // elseif ($USER->iassignEdit == 1)
  2557. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2558. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2559. print " <input type=submit value='$bottonEdit_message'/>\n";
  2560. print "</form>\n";
  2561. print "</td>\n";
  2562. } // if ($iassign_list)
  2563. }
  2564. print '</tr></table>' . "\n";
  2565. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2566. // $this->view_legend_icons();
  2567. print $OUTPUT->box_end();
  2568. $iassign_array_exercise = array();
  2569. $i_exercise = 0;
  2570. $iassign_array_test = array();
  2571. $i_test = 0;
  2572. $iassign_array_example = array();
  2573. $i_example = 0;
  2574. $iassign_array_general = array();
  2575. $i_general = 0;
  2576. if ($iassign_list) {
  2577. if ($this->iassign->activity_group == 0) {
  2578. foreach ($iassign_list as $iassign) {
  2579. $iassign_array_general[$i_general] = $iassign;
  2580. $i_general ++;
  2581. }
  2582. } // if ($this->iassign->activity_group == 0)
  2583. else {
  2584. foreach ($iassign_list as $iassign) {
  2585. if ($iassign->type_iassign == 3) {
  2586. $iassign_array_exercise[$i_exercise] = $iassign;
  2587. $i_exercise ++;
  2588. } // if ($iassign->type_iassign == 3)
  2589. if ($iassign->type_iassign == 2) {
  2590. $iassign_array_test[$i_test] = $iassign;
  2591. $i_test ++;
  2592. } // if ($iassign->type_iassign == 2)
  2593. if ($iassign->type_iassign == 1) {
  2594. $iassign_array_example[$i_example] = $iassign;
  2595. $i_example ++;
  2596. } // if ($iassign->type_iassign == 1)
  2597. }
  2598. }
  2599. if ($iassign_array_exercise) {
  2600. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  2601. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2602. }
  2603. if ($iassign_array_test) {
  2604. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  2605. $this->show_iassign($title, $iassign_array_test, $i_test);
  2606. }
  2607. if ($iassign_array_example) {
  2608. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  2609. $this->show_iassign($title, $iassign_array_example, $i_example);
  2610. }
  2611. if ($iassign_array_general) {
  2612. $title = "";
  2613. $this->show_iassign($title, $iassign_array_general, $i_general);
  2614. }
  2615. } else { // if ($iassign_list)
  2616. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2617. }
  2618. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2619. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2620. print $OUTPUT->box_start();
  2621. print '<table width=100% border=0><tr>' . "\n";
  2622. print '<td width=10% align="left">' . "\n";
  2623. print $link_report;
  2624. print '</td>' . "\n";
  2625. print '</tr></table>' . "\n";
  2626. print $OUTPUT->box_end();
  2627. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2628. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2629. print $OUTPUT->box_start();
  2630. print '<table width=100% border=0><tr>' . "\n";
  2631. print '<td align="left">' . "\n";
  2632. print $link_add;
  2633. print '</td>' . "\n";
  2634. print '</tr></table>' . "\n";
  2635. print $OUTPUT->box_end();
  2636. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2637. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2638. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2639. $this->view_legend_icons();
  2640. } // function view_iassigns()
  2641. /// Display all iAssigns
  2642. function show_iassign ($title, $iassign_array, $i) {
  2643. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  2644. $id = $this->cm->id;
  2645. print $OUTPUT->box_start();
  2646. print " <script type='text/javascript'>
  2647. //<![CDATA[
  2648. function validate_move () {
  2649. var radios = document.getElementsByName('iassign_destiny');
  2650. var formValid = false;
  2651. //alert('aqui validate_move()');
  2652. var i = 0;
  2653. while (!formValid && i < radios.length) {
  2654. if (radios[i].checked) formValid = true;
  2655. i++;
  2656. }
  2657. if (!formValid) {
  2658. document.getElementById('move_dest').classList.add('alert-danger');
  2659. }
  2660. return formValid;
  2661. }
  2662. var modal;
  2663. function load_move(id_ias) {
  2664. document.form_move_activity.iassign_current.value = id_ias;
  2665. modal.style.display = 'block';
  2666. var radios = document.getElementsByName('iassign_destiny');
  2667. var i = 0;
  2668. while (i < radios.length) {
  2669. radios[i].checked = false;
  2670. i++;
  2671. }
  2672. document.getElementById('move_dest').classList.remove('alert-danger');
  2673. }
  2674. function load_modal_elements() {
  2675. modal = document.getElementById('myModal');
  2676. var span = document.getElementById('close_modal');
  2677. span.onclick = function() {
  2678. modal.style.display = 'none';
  2679. }
  2680. window.onclick = function(event) {
  2681. if (event.target == modal) {
  2682. modal.style.display = 'none';
  2683. }
  2684. }
  2685. }
  2686. window.onload = load_modal_elements;
  2687. //]]>
  2688. </script>\n";
  2689. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  2690. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  2691. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  2692. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  2693. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  2694. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  2695. <input type='hidden' name='iassign_current' value='' />";
  2696. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  2697. $section = $course_sections[0];
  2698. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  2699. for ($k = 0; $k < count($ids_sections); $k++) {
  2700. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  2701. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  2702. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  2703. if ($c_cm) {
  2704. if ($ccm->instance == $c_cm->instance) {
  2705. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2706. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2707. }
  2708. else {
  2709. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2710. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2711. }
  2712. }
  2713. }
  2714. $radio_buttons .= "</ul>";
  2715. }
  2716. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  2717. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  2718. </form>
  2719. </div></div> </div></div>\n";
  2720. print " <style>.modal {
  2721. display: none;
  2722. position: fixed;
  2723. z-index: 1;
  2724. left: 0;
  2725. top: 0;
  2726. width: 100%;
  2727. height: 100%;
  2728. overflow: scroll;
  2729. background-color: rgb(0,0,0);
  2730. background-color: rgba(0,0,0,0.4);
  2731. }
  2732. .modal-content {
  2733. background-color: #fefefe;
  2734. margin: 15% auto;
  2735. padding: 10px 10px;
  2736. border: 1px solid #888;
  2737. width: 50%;
  2738. }
  2739. #close_modal {
  2740. color: #aaa;
  2741. float: right;
  2742. font-size: 28px;
  2743. font-weight: bold;
  2744. margin-top: -15px;
  2745. margin-right: -3px;
  2746. }
  2747. #close_modal:hover,
  2748. #close_modal:focus {
  2749. color: black;
  2750. text-decoration: none;
  2751. cursor: pointer;
  2752. }
  2753. #modal_title {
  2754. min-height: 3rem;
  2755. color: initial;
  2756. background: initial;
  2757. font-size: 1.5rem;
  2758. line-height: 1.5;
  2759. padding: 15px;
  2760. border-bottom: 1px solid #e5e5e5;
  2761. }
  2762. .input_move {
  2763. width: 90%;
  2764. padding: 2px;
  2765. }
  2766. .input_move:hover {
  2767. background: #eff0ef;
  2768. }
  2769. </style>";
  2770. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2771. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  2772. for ($j = 0; $j < $i; $j ++) {
  2773. $iassign_current = $iassign_array[$j]->id;
  2774. // receiver=1 - message to teacher
  2775. // receiver=2 - message to student
  2776. $sum_comment = 0;
  2777. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  2778. foreach ($iassign_submissions as $iassign_submission) {
  2779. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  2780. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2781. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2782. if ($verify_message)
  2783. foreach ($verify_message as $tmp)
  2784. $sum_comment += $tmp;
  2785. } // foreach ($iassign_submissions as $iassign_submission)
  2786. if ($sum_comment == 0)
  2787. $comment_unread = "";
  2788. else {
  2789. $comment_unread_message = get_string('comment_unread', 'iassign');
  2790. if ($sum_comment == 1)
  2791. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2792. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  2793. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  2794. }
  2795. if ($j == $i - 1)
  2796. $iassign_down = $iassign_array[$j]->id;
  2797. else
  2798. $iassign_down = $iassign_array[$j + 1]->id;
  2799. if ($j > 0)
  2800. $iassign_up = $iassign_array[$j - 1]->id;
  2801. else
  2802. $iassign_up = $iassign_array[$j]->id;
  2803. if ($iassign_array[$j]->visible == 0)
  2804. $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>";
  2805. else
  2806. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2807. $links .= $comment_unread;
  2808. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  2809. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  2810. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  2811. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  2812. if ($j==0) // first activity
  2813. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2814. else
  2815. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2816. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  2817. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  2818. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  2819. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  2820. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  2821. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  2822. if (count($iassign_array) > 1) {
  2823. if ($j == 0)
  2824. $links .= $link_down;
  2825. elseif ($j == $i - 1)
  2826. $links .= $link_up;
  2827. else
  2828. $links .= $link_up . $link_down;
  2829. } // if (count($iassign_array) > 1)
  2830. $links .= $link_edit . $link_delete;
  2831. if ($iassign_array[$j]->visible == 0)
  2832. $links .= $link_visible_show;
  2833. else
  2834. $links .= $link_visible_hide;
  2835. $links .= $link_duplicate_activity . $link_move_activity;
  2836. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2837. print '<p>' . $links . '</p>' . "\n";
  2838. }
  2839. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2840. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  2841. print '<table width=100% ><tr>' . "\n";
  2842. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2843. print '</tr></table>' . "\n";
  2844. for ($j = 0; $j < $i; $j ++) {
  2845. $icon_status = "";
  2846. $icon_comment = "";
  2847. if ($iassign_array[$j]->visible == 1) {
  2848. $iassign_current = $iassign_array[$j]->id;
  2849. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  2850. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2851. $icon_status = "";
  2852. $icon_comment = "";
  2853. if ($iassign_submission) {
  2854. // receiver=1 - message to teacher
  2855. // receiver=2 - message to student
  2856. // $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");
  2857. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  2858. $verify_message = $DB->get_record_sql(
  2859. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2860. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2861. if ($verify_message)
  2862. foreach ($verify_message as $tmp)
  2863. $sum_comment = $tmp;
  2864. if ($sum_comment > 0) {
  2865. $comment_unread_message = get_string('comment_unread', 'iassign');
  2866. if ($sum_comment == 1)
  2867. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2868. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  2869. }
  2870. // $icon_comment = iassign_icons::insert('comment_unread');
  2871. if ($iassign_array[$j]->type_iassign == 3) {
  2872. if ($iassign_array[$j]->show_answer == 1) {
  2873. if ($iassign_submission->status == 3)
  2874. $icon_status = iassign_icons::insert('correct');
  2875. elseif ($iassign_submission->status == 2)
  2876. $icon_status = iassign_icons::insert('incorrect');
  2877. elseif ($iassign_submission->status == 1)
  2878. $icon_status = iassign_icons::insert('post');
  2879. elseif ($iassign_submission->status == 0)
  2880. $icon_status = iassign_icons::insert('not_post');
  2881. } // if ($iassign_array[$j]->show_answer==1)
  2882. else {
  2883. if ($iassign_submission->status == 0)
  2884. $icon_status = iassign_icons::insert('not_post');
  2885. else
  2886. $icon_status = iassign_icons::insert('post');
  2887. }
  2888. } // if ($iassign_array[$j]->type_iassign == 3)
  2889. } // if ($iassign_submission)
  2890. elseif ($iassign_array[$j]->type_iassign == 3) {
  2891. $icon_status = iassign_icons::insert('not_post');
  2892. } // if ($iassign_array[$j]->type_iassign == 3)
  2893. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  2894. } // if ($iassign_array[$j]->visible == 1)
  2895. } // for ($j = 0; $j < $i; $j++)
  2896. } else if (isguestuser()) {
  2897. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2898. print '<table width=100% ><tr>' . "\n";
  2899. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2900. print '</tr></table>' . "\n";
  2901. for ($j = 0; $j < $i; $j ++) {
  2902. $icon_status = "";
  2903. $icon_comment = "";
  2904. if ($iassign_array[$j]->visible == 1) {
  2905. $iassign_current = $iassign_array[$j]->id;
  2906. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2907. print '<p>' . $links . '</p>' . "\n";
  2908. } // if ($iassign_array[$j]->visible == 1)
  2909. }
  2910. }
  2911. print $OUTPUT->box_end();
  2912. } // function show_iassign($title, $iassign_array, $i)
  2913. /// Show message of return
  2914. function return_home_course ($message) {
  2915. //D global $DB, $OUTPUT;
  2916. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2917. //D echo $OUTPUT->box_start();
  2918. //D echo '<table width=100% border=0 valign="top">' . "\n";
  2919. //D echo '<tr><td align="left"><strong>' . "\n";
  2920. //D print_string($message, 'iassign');
  2921. //D echo '</strong></td>' . "\n";
  2922. //D echo '<td width=20% align="right">' . "\n";
  2923. //D echo $link_return;
  2924. //D echo '</td></tr></table>' . "\n";
  2925. //D echo $OUTPUT->box_end();
  2926. //D // echo $OUTPUT->footer();
  2927. redirect(new moodle_url($this->return . '&notice=' . $message));
  2928. exit;
  2929. }
  2930. /// Search comment of activity
  2931. function search_comment_submission ($iassign_submissionid) {
  2932. global $USER, $DB, $OUTPUT, $COURSE;
  2933. // $context = context_course::instance($COURSE->id);
  2934. $colorEdit1 = "#a7bede"; // "#dce7ec"
  2935. $colorEdit2 = "#b7ceee";
  2936. $has_capability = 0;
  2937. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  2938. $text = "";
  2939. if ($comments) {
  2940. $even = 1;
  2941. foreach ($comments as $tmp) {
  2942. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  2943. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  2944. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2945. // $text .= $tmp->comment . "</td></tr>";
  2946. //} else {
  2947. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2948. if ($even) {
  2949. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2950. $even = 0;
  2951. } else {
  2952. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2953. $even = 1;
  2954. }
  2955. $text .= $tmp->comment . "</td></tr>\n";
  2956. } // foreach ($comments as $tmp)
  2957. }
  2958. return $text;
  2959. }
  2960. /// Update comment of activity
  2961. function update_comment ($iassign_submissionid) {
  2962. global $USER, $DB, $OUTPUT;
  2963. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  2964. $receiver = 1; // student message to teacher
  2965. else
  2966. $receiver = 2; // teacher message to student
  2967. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  2968. if ($verify_message) {
  2969. foreach ($verify_message as $message) {
  2970. if ($message->receiver == $receiver) {
  2971. $newentry = new stdClass();
  2972. $newentry->id = $message->id;
  2973. $newentry->return_status = 1;
  2974. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  2975. print_error('error_update', 'iassign');
  2976. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  2977. } // if ($message->receiver == $receiver)
  2978. // Trigger module viewed event.
  2979. $event = \mod_iassign\event\submission_comment_updated::create(array(
  2980. 'objectid' => $this->iassign->id,
  2981. 'context' => $this->context
  2982. ));
  2983. $event->add_record_snapshot('course', $this->course);
  2984. $event->trigger();
  2985. } // foreach ($verify_message as $message)
  2986. }
  2987. }
  2988. /// Record comment of activity
  2989. function write_comment_submission () {
  2990. global $USER, $CFG, $DB;
  2991. $id = $this->cm->id;
  2992. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  2993. $row = optional_param('row', 0, PARAM_INT);
  2994. $column = optional_param('column', 0, PARAM_INT);
  2995. $sum_comment = 0;
  2996. $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);
  2997. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  2998. $str1 = trim($submission_comment);
  2999. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3000. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3001. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3002. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3003. $receiver = 1; // student message to teacher
  3004. $this->action = 'view';
  3005. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3006. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3007. } else {
  3008. $receiver = 2; // teacher message to student
  3009. $this->action = 'viewsubmission';
  3010. //D $tousers = array(); //MOOC 2016
  3011. //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
  3012. }
  3013. //MOOC 2016: foi p/ 15 linhas acima:
  3014. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3015. if (!$iassign_submission) {
  3016. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3017. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3018. $this->iassign_submission_current = $id_submission;
  3019. } else {
  3020. $id_submission = $iassign_submission->id;
  3021. } // if (!$iassign_submission)
  3022. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3023. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3024. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3025. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3026. $comments = $DB->get_record_sql(
  3027. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3028. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3029. if ($comments)
  3030. foreach ($comments as $tmp)
  3031. $sum_comment = $tmp;
  3032. if ($sum_comment == 0) {
  3033. $newentry = new stdClass();
  3034. $newentry->iassign_submissionid = $id_submission;
  3035. $newentry->comment_authorid = $USER->id;
  3036. $newentry->timecreated = time();
  3037. $newentry->comment = $submission_comment;
  3038. $newentry->receiver = $receiver;
  3039. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3040. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3041. //T $eventdata = new stdClass();
  3042. //T $eventdata->component = 'mod_iassign'; //your component name
  3043. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3044. //T $eventdata->userfrom = $USER;
  3045. //T $eventdata->userto = $touser;
  3046. //T $eventdata->subject = "Teste de Subject";
  3047. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3048. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3049. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3050. //T $eventdata->smallmessage = "Teste de Mensagem";
  3051. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3052. //T // alteracao tulio faria
  3053. //T //message_send($eventdata);
  3054. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3055. // Trigger module viewed event.
  3056. $event = \mod_iassign\event\submission_comment_created::create(array(
  3057. 'objectid' => $this->iassign->id,
  3058. 'context' => $this->context
  3059. ));
  3060. $event->add_record_snapshot('course', $this->course);
  3061. $event->trigger();
  3062. }
  3063. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3064. // if ($this->action=='viewsubmission') {
  3065. // echo $OUTPUT->header();
  3066. // $this->return_last('confirm_add_comment', $link_return);
  3067. // die;
  3068. // }
  3069. return true;
  3070. } // function write_comment_submission()
  3071. /// Writes a new submission
  3072. // The first student answer is under 'function get_answer()'
  3073. function new_submission ($iassignid, $id_user, $receiver) {
  3074. global $USER, $DB, $OUTPUT;
  3075. $newentry = new stdClass();
  3076. $newentry->iassign_statementid = $iassignid;
  3077. $newentry->userid = $id_user;
  3078. $newentry->timecreated = time();
  3079. $newentry->timemodified = time();
  3080. $newentry->answer = 0; // student only submit message
  3081. if ($receiver == 2) // teacher message to student (write id teacher)
  3082. $newentry->teacher = $USER->id;
  3083. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3084. return_home_course('error_insert_submissions');
  3085. else {
  3086. // Trigger module view event
  3087. $event = \mod_iassign\event\submission_created::create(array(
  3088. 'objectid' => $this->iassign->id,
  3089. 'context' => $this->context
  3090. ));
  3091. $event->add_record_snapshot('course', $this->course);
  3092. $event->trigger();
  3093. }
  3094. return $newentry->id;
  3095. }
  3096. /// Return to a specific address of page
  3097. function return_last ($message, $link_return) {
  3098. global $DB, $OUTPUT;
  3099. print $OUTPUT->box_start();
  3100. print '<table width=100% border=0 valign="top">' . "\n";
  3101. print '<tr><td align="left"><strong>' . "\n";
  3102. print_string($message, 'iassign');
  3103. print '</strong></td>' . "\n";
  3104. print '<td width=20% align="right">' . "\n";
  3105. print $link_return;
  3106. print '</td></tr></table>' . "\n";
  3107. print $OUTPUT->box_end();
  3108. print $OUTPUT->footer();
  3109. die();
  3110. } // function return_last($message, $link_return)
  3111. } // class iassign
  3112. /// Class for manage activities
  3113. class activity {
  3114. var $activity;
  3115. /// Constructor of class.
  3116. // @param int $id Id of activity
  3117. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3118. //D public function activity($id) { self::__construct($id); }
  3119. function __construct ($id) {
  3120. global $DB;
  3121. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3122. if (empty($this->activity))
  3123. $this->activity = null;
  3124. }
  3125. /// Get an activity
  3126. // @return NULL
  3127. function get_activity () {
  3128. if ($this->activity != null)
  3129. return $this->activity;
  3130. else
  3131. return null;
  3132. }
  3133. /// Delete interactive activities
  3134. function delete ($return) {
  3135. global $USER, $CFG, $DB, $OUTPUT;
  3136. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3137. $output = $OUTPUT->header();
  3138. $output .= $OUTPUT->box_start();
  3139. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3140. if ($iassign_submission_currents) {
  3141. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3142. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3143. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3144. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3145. $output .= $OUTPUT->box_end();
  3146. $output .= $OUTPUT->footer();
  3147. print $output;
  3148. die();
  3149. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3150. } // if ($iassign_submission_currents)
  3151. else
  3152. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3153. $output .= '<table width=50% border=0>';
  3154. $output .= '<tr valign="top"><td>';
  3155. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3156. $output .= '</td><td>';
  3157. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3158. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3159. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3160. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3161. $output .= "</form>\n";
  3162. $output .= '</td><td>';
  3163. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3164. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3165. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3166. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3167. $output .= "</form>\n";
  3168. $output .= '</td></tr></table>' . "\n";
  3169. $output .= $OUTPUT->box_end();
  3170. $output .= $OUTPUT->footer();
  3171. print $output;
  3172. } // function delete($return)
  3173. /// Function for confirm the delete of activity
  3174. // @param String $return Url of return
  3175. // @param Object $iassign Object content an activity
  3176. function deleteyes ($return, $iassign) {
  3177. global $USER, $CFG, $DB, $OUTPUT;
  3178. $msg = '';
  3179. if (!empty($this->activity->id)) {
  3180. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3181. if ($iassign_submission_currents) {
  3182. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3183. foreach ($iassign_submission_currents as $iassign_submission)
  3184. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3185. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3186. } // if ($iassign_submission_currents)
  3187. }
  3188. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3189. $this->delete_calendar($this->activity->id);
  3190. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3191. iassign::update_grade_iassign($this->activity->iassignid);
  3192. if ($delete_iassign_current) {
  3193. $iassign->return_home_course('confirm_delete_iassign');
  3194. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3195. } else {
  3196. $iassign->return_home_course('error_confirm_delete_iassign');
  3197. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3198. }
  3199. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3200. }
  3201. }
  3202. /// Changes position of activities (between those inside a group of interactive activities)
  3203. // @param $move_action = must be "up" or "down"
  3204. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3205. function move_iassign ($move_action, $target, $return) {
  3206. global $DB, $OUTPUT;
  3207. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3208. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3209. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3210. if ($move_action=="firstdown") {
  3211. $final_position_source = 2;
  3212. $final_position_target = 1;
  3213. }
  3214. else
  3215. if ($move_action=="down") {
  3216. $final_position_target = $this->activity->position;
  3217. $final_position_source = $final_position_target + 1;
  3218. }
  3219. else
  3220. if ($move_action=="up") {
  3221. $final_position_target = $this->activity->position;
  3222. $final_position_source = $final_position_target - 1;
  3223. }
  3224. else { // error:
  3225. print_error('error_update_move_iassign', 'iassign');
  3226. exit;
  3227. }
  3228. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3229. $newentry->id = $this->activity->id; // ID of the "source activity"
  3230. $newentry->position = $final_position_source;
  3231. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3232. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3233. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3234. print_error('error_update_move_iassign', 'iassign');
  3235. }
  3236. else { // first update performed successfully
  3237. $newentry->id = $iassign_target->id;
  3238. $newentry->position = $final_position_target;
  3239. if (!$DB->update_record('iassign_statement', $newentry))
  3240. print_error('error_update_move_iassign', 'iassign');
  3241. }
  3242. redirect($return);
  3243. }
  3244. /// Enable or disable the display of interactive activities
  3245. function visible_iassign ($return) {
  3246. global $DB;
  3247. $newentry = new stdClass();
  3248. $newentry->id = $this->activity->id;
  3249. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3250. if (!$DB->update_record('iassign_statement', $newentry))
  3251. print_error('error_update_visible_iassign', 'iassign');
  3252. redirect($return);
  3253. }
  3254. /// Add news interactive activities (register in table 'iassign_statement')
  3255. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3256. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3257. function new_iassign ($param) {
  3258. global $DB;
  3259. $newentry = new stdClass();
  3260. $newentry->iassignid = $param->iassignid;
  3261. $newentry->name = $param->name;
  3262. $newentry->type_iassign = $param->type_iassign;
  3263. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3264. $proposition = $param->proposition;
  3265. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3266. else $proposition_text = $proposition;
  3267. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3268. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3269. //TODO Then get it directly from the form data $_POST!
  3270. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3271. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3272. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3273. $newentry->author_name = $param->author_name;
  3274. $newentry->author_modified_name = $param->author_modified_name;
  3275. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3276. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3277. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3278. $newentry->grade = $param->grade;
  3279. $newentry->timemodified = time();
  3280. $newentry->timecreated = time();
  3281. if ($param->type_iassign == 1) {
  3282. $newentry->timedue = 0;
  3283. $newentry->timeavailable = 0;
  3284. } // if ($param->type_iassign == 1)
  3285. else {
  3286. $newentry->timedue = $param->timedue;
  3287. $newentry->timeavailable = $param->timeavailable;
  3288. }
  3289. $newentry->preventlate = $param->preventlate;
  3290. $newentry->test = $param->test;
  3291. $newentry->special_param1 = $param->special_param1;
  3292. $newentry->visible = $param->visible;
  3293. $newentry->position = $param->position;
  3294. $newentry->max_experiment = $param->max_experiment;
  3295. $newentry->dependency = $param->dependency;
  3296. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3297. $newentry->show_answer = $param->show_answer;
  3298. $id = $DB->insert_record("iassign_statement", $newentry);
  3299. if ($id) {
  3300. $component = 'mod_iassign';
  3301. $filearea = 'exercise';
  3302. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3303. $file = $fs->get_file_by_id($param->file);
  3304. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3305. // File already inserted in other context!
  3306. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3307. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3308. $updateentry = new stdClass();
  3309. $updateentry->id = $id;
  3310. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3311. $updateentry->file = $newfile->get_itemid();
  3312. if (!$DB->update_record("iassign_statement", $updateentry))
  3313. print_error('error_add', 'iassign');
  3314. if ($param->type_iassign == 3)
  3315. iassign::update_grade_iassign($param->iassignid);
  3316. //TODO iLM_HTML5 :: //MOOC2014
  3317. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3318. //D if ($iassign_ilm_configs) {
  3319. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3320. //D if ($iassign_ilm_config->param_type != 'static') {
  3321. //D $newentry = new stdClass();
  3322. //D $newentry->iassign_statementid = $id;
  3323. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3324. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3325. //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});
  3326. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3327. //D print_error('error_add_param', 'iassign');
  3328. //D }
  3329. //D }
  3330. //D }
  3331. // log event --------------------------------------------------------------------------------------
  3332. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3333. // log event --------------------------------------------------------------------------------------
  3334. return $id;
  3335. }
  3336. else
  3337. print_error('error_add', 'iassign');
  3338. } // function new_iassign($param)
  3339. /// Add the calendar entries for this iassign
  3340. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3341. // @return bool
  3342. static function add_calendar ($iassignid) {
  3343. global $DB, $CFG;
  3344. require_once($CFG->dirroot . '/calendar/lib.php');
  3345. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3346. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3347. $event = new stdClass();
  3348. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3349. $event->description = $iassign_statement_activity_item->name;
  3350. $event->courseid = $iassign->course;
  3351. $event->groupid = 0;
  3352. $event->userid = 0;
  3353. $event->modulename = 'iassign';
  3354. $event->instance = $iassign->id;
  3355. $event->eventtype = 'due';
  3356. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3357. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3358. calendar_event::create($event);
  3359. }
  3360. /// Update the calendar entries for this iassign
  3361. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3362. // @return bool
  3363. function update_calendar ($iassignid, $olddescription) {
  3364. global $DB, $CFG;
  3365. require_once($CFG->dirroot . '/calendar/lib.php');
  3366. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3367. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3368. $event = new stdClass();
  3369. $event->id = 0;
  3370. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3371. if ($events) {
  3372. foreach ($events as $value) {
  3373. if ($value->description == $olddescription) {
  3374. $event->id = $value->id;
  3375. }
  3376. }
  3377. }
  3378. if ($event->id != 0) {
  3379. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3380. $event->description = $iassign_statement_activity_item->name;
  3381. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3382. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3383. $calendarevent = calendar_event::load($event->id);
  3384. $calendarevent->update($event);
  3385. } else
  3386. $this->add_calendar($iassignid);
  3387. }
  3388. /// Update the calendar entries for this iassign
  3389. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3390. // @return bool
  3391. function delete_calendar ($iassignid) {
  3392. global $DB, $CFG;
  3393. require_once($CFG->dirroot . '/calendar/lib.php');
  3394. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3395. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3396. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3397. if ($events) {
  3398. foreach ($events as $value) {
  3399. if ($value->description == $iassign_statement_activity_item->name) {
  3400. $DB->delete_records('event', array('id' => $value->id));
  3401. }
  3402. }
  3403. }
  3404. }
  3405. /// Update interactive activities
  3406. function update_iassign ($param) {
  3407. global $DB;
  3408. $component = 'mod_iassign';
  3409. $filearea = 'exercise';
  3410. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3411. $file = $fs->get_file_by_id($param->file);
  3412. $fileold = $fs->get_file_by_id($param->fileold);
  3413. if ($param->file != $param->fileold) {
  3414. if ($fileold) {
  3415. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3416. foreach ($fileoldarea as $value) {
  3417. $value->delete();
  3418. }
  3419. }
  3420. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3421. $itemid = $file->get_itemid() + $param->iassign_id;
  3422. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3423. $param->file = $newfile->get_itemid();
  3424. } else
  3425. $param->file = $file->get_itemid();
  3426. } else {
  3427. $param->file = $file->get_itemid();
  3428. }
  3429. $newentry = new stdClass();
  3430. $newentry->id = $param->iassign_id;
  3431. $newentry->name = $param->name;
  3432. $newentry->type_iassign = $param->type_iassign;
  3433. //2019 $newentry->proposition = $param->proposition;
  3434. $proposition = $param->proposition;
  3435. if (is_array($proposition))
  3436. $proposition_text = $proposition['text'];
  3437. else
  3438. $proposition_text = $proposition;
  3439. $newentry->proposition = $proposition_text;
  3440. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3441. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3442. $newentry->grade = $param->grade;
  3443. $newentry->author_modified_name = $param->author_modified_name;
  3444. $newentry->timemodified = time();
  3445. if ($param->type_iassign == 1) {
  3446. $newentry->timedue = 0;
  3447. $newentry->timeavailable = 0;
  3448. } // if ($param->type_iassign == 1)
  3449. else {
  3450. $newentry->timedue = $param->timedue;
  3451. $newentry->timeavailable = $param->timeavailable;
  3452. }
  3453. $newentry->preventlate = $param->preventlate;
  3454. $newentry->test = $param->test;
  3455. $newentry->special_param1 = $param->special_param1;
  3456. $newentry->visible = $param->visible;
  3457. $newentry->max_experiment = $param->max_experiment;
  3458. $newentry->dependency = $param->dependency;
  3459. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3460. $newentry->show_answer = $param->show_answer;
  3461. if (!$DB->update_record("iassign_statement", $newentry))
  3462. print_error('error_update', 'iassign');
  3463. if ($param->type_iassign == 3) {
  3464. iassign::update_grade_iassign($param->iassignid);
  3465. }
  3466. //$id = $newentry->id; // MOOC 2016 --- inicio
  3467. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3468. //if ($iassign_activity_item_configs) {
  3469. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3470. // $newentry = new stdClass();
  3471. // $newentry->id = $iassign_activity_item_config->id;
  3472. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3473. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3474. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3475. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3476. // print_error('error_edit_param', 'iassign');
  3477. // }
  3478. // } // MOOC 2016 --- final
  3479. // log event --------------------------------------------------------------------------------------
  3480. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3481. // log event --------------------------------------------------------------------------------------
  3482. return $newentry->id;
  3483. // if ($param->type_iassign==3)
  3484. // $this->update_grade_iassign($param->iassignid);
  3485. } // function update_iassign($param)
  3486. /// Show information of activity
  3487. function show_info_iassign () {
  3488. global $DB, $OUTPUT;
  3489. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3490. if ($this->activity->type_iassign == 3) {
  3491. if ($this->activity->dependency == 0) {
  3492. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3493. } else {
  3494. $dependencys = explode(';', $this->activity->dependency);
  3495. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3496. foreach ($dependencys as $dependency) {
  3497. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3498. if ($dependencyiassign)
  3499. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3500. } // foreach ($dependencys as $dependency)
  3501. } // if ($iassign_statement_activity_item->dependency == 0)
  3502. if ($this->activity->max_experiment == 0)
  3503. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3504. else
  3505. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3506. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3507. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3508. print $OUTPUT->box($output);
  3509. } // function show_info_iassign()
  3510. /// Shows date of opening and closing activities
  3511. function view_dates () {
  3512. global $USER, $CFG, $DB, $OUTPUT;
  3513. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3514. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3515. $status_iassign = "";
  3516. $status_iassign1 = "";
  3517. $status_iassign2 = "";
  3518. if ($this->activity->type_iassign == 1) // activity of type example
  3519. $type_iassign = get_string('example_iassign', 'iassign');
  3520. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3521. $type_iassign = get_string('test_iassign', 'iassign');
  3522. if ($this->activity->timeavailable > time()) {
  3523. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3524. } elseif ($this->activity->timedue < time()) {
  3525. $status_iassign = get_string('last_timedue', 'iassign');
  3526. }
  3527. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3528. $type_iassign = get_string('exercise_iassign', 'iassign');
  3529. if ($this->activity->timeavailable > time()) {
  3530. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3531. } elseif ($this->activity->timedue < time()) { // after delivery
  3532. $status_iassign = get_string('last_timedue', 'iassign');
  3533. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3534. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3535. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3536. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3537. if ($this->activity->test == 1) // allowed to test after of deadline
  3538. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3539. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3540. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3541. } // elseif ($iassign_statement_activity_item->test == 0)
  3542. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3543. } // elseif ($iassign_statement_activity_item->timedue < time())
  3544. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3545. $output = '<table width=100% >' . "\n";
  3546. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3547. $output .= '<tr>' . "\n";
  3548. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3549. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3550. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3551. // leo $output .= '<td width=80%>' . $type_iassign;
  3552. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3553. // $output .= '</td>' . "\n";
  3554. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3555. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3556. $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>";
  3557. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3558. } else {
  3559. $link_next = "";
  3560. $link_previous = "";
  3561. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3562. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3563. // previous_activity
  3564. if ($iassign_previous) {
  3565. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3566. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3567. } // next_activity
  3568. if ($iassign_next) {
  3569. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3570. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3571. }
  3572. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3573. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3574. $output .= '</tr></table>' . "\n";
  3575. $output .= '<table width=100% >' . "\n";
  3576. if ($this->activity->type_iassign > 1) {
  3577. if ($this->activity->timeavailable)
  3578. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3579. if ($this->activity->timedue)
  3580. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3581. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3582. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3583. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3584. $output .= '</table>' . "\n";
  3585. print $OUTPUT->box($output);
  3586. } // function view_dates()
  3587. } // class activity
  3588. /// Class to manage Interactive Learning Module (iLM)
  3589. class ilm {
  3590. var $ilm;
  3591. /// Constructor of class
  3592. // @param int $id Id of iLM
  3593. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3594. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3595. function __construct ($id) {
  3596. global $DB;
  3597. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3598. if (empty($this->ilm))
  3599. $this->ilm = null;
  3600. }
  3601. /// Shows activity in iLM
  3602. // @calledby view_iassign_current()
  3603. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3604. global $USER, $CFG, $DB;
  3605. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3606. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3607. $typec = strtolower($iassign_ilm->type);
  3608. require_once 'ilm_handlers/' . $typec . '.php';
  3609. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3610. return $retorno;
  3611. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3612. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3613. // @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);
  3614. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3615. // @param Object $file File in use in activity
  3616. // @return int Return the id of log
  3617. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3618. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3619. $newentry = new stdClass();
  3620. $newentry->iassign_statementid = $iassign_activity_itemid;
  3621. $newentry->userid = $USER->id;
  3622. $newentry->file = $content_or_id_from_ilm_security;
  3623. $newentry->timecreated = time();
  3624. $newentry->view = 1;
  3625. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3626. if (!$id_iLM_security) {
  3627. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3628. } // from (!$DB->insert_record("iassign_security", $newentry))
  3629. return $id_iLM_security;
  3630. }
  3631. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3632. // @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);
  3633. // @param int $userid
  3634. // @param int $iassign_activity_itemid Id of iassign statement
  3635. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3636. global $DB;
  3637. // 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")
  3638. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3639. }
  3640. } // class ilm
  3641. /// Class to manage settings of iLM.
  3642. class ilm_settings {
  3643. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  3644. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3645. // @param int $ilm_id Id of iLM
  3646. // @param array $options An array with options for create dynamic tag html APPLET
  3647. // @return string Return with a tag html APPLET created
  3648. static function build_ilm_tags ($ilm_id, $options = array()) {
  3649. global $DB;
  3650. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3651. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3652. $typec = strtolower($iassign_ilm->type);
  3653. require_once 'ilm_handlers/' . $typec . '.php';
  3654. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3655. return $retorno;
  3656. } // static function build_ilm_tags($ilm_id, $options = array())
  3657. /// Function for get modified date of iLM file
  3658. // @param string $file_jar String with Ids of iLM files
  3659. // @return string Return with the filenames and modified date
  3660. static function applet_filetime ($file_jar) {
  3661. $filetime = "";
  3662. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3663. $files_jar = explode(",", $file_jar);
  3664. foreach ($files_jar as $one_file) {
  3665. $file = $fs->get_file_by_id($one_file);
  3666. if ($file)
  3667. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3668. }
  3669. return $filetime;
  3670. }
  3671. /// Function for verify an default applet
  3672. // @param String $file_jar String containing an list de ids of applet files
  3673. // @return boolean Return true or fale if applet is default
  3674. static function applet_default ($file_jar) {
  3675. $is_default = true;
  3676. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3677. $files_jar = explode(",", $file_jar);
  3678. foreach ($files_jar as $one_file) {
  3679. $file = $fs->get_file_by_id($one_file);
  3680. if ($file)
  3681. $is_default &= ($file->get_itemid() == 0);
  3682. }
  3683. return $is_default;
  3684. }
  3685. /// Function for get form variables for add, edit, or copy iLM
  3686. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  3687. // @see settings_form.php
  3688. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  3689. // @param int $ilm_id Id of iLM
  3690. // @param string $action String with the action
  3691. // @return object Return an object with forms variables
  3692. static function add_edit_copy_ilm ($ilm_id, $action) {
  3693. global $USER, $DB, $CFG;
  3694. require_once('settings_form.php'); // put the form
  3695. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3696. $param = new stdClass();
  3697. $param->action = $action;
  3698. $param->ilm_id = $ilm_id;
  3699. $CFG->action_ilm = $action;
  3700. $CFG->ilm_id = $ilm_id;
  3701. if ($action == 'add') {
  3702. $param->title = get_string('add_ilm', 'iassign');
  3703. $param->name = "";
  3704. $param->version = "";
  3705. $param->url = "";
  3706. $param->description = "";
  3707. $param->extension = "";
  3708. $param->author = $USER->id;
  3709. $param->file_jar = "";
  3710. $param->file_jar_static = "";
  3711. $param->file_class = "";
  3712. $param->width = 800;
  3713. $param->height = 600;
  3714. $param->enable = 0; // 0 - hide / 1 - show
  3715. $param->timecreated = time();
  3716. $param->timemodified = time();
  3717. $param->evaluate = 0;
  3718. $param->parent = 0;
  3719. }
  3720. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  3721. if ($iassign_ilm) {
  3722. $description = json_decode($iassign_ilm->description);
  3723. $param->title = get_string('edit_ilm', 'iassign');
  3724. $param->id = $iassign_ilm->id;
  3725. $param->name_ilm = $iassign_ilm->name;
  3726. $param->name = $iassign_ilm->name;
  3727. $param->version = $iassign_ilm->version;
  3728. $param->ilm_type = $iassign_ilm->type;
  3729. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3730. $param->url = $iassign_ilm->url;
  3731. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  3732. if (!isset($description->{current_language()})) {
  3733. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  3734. else
  3735. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  3736. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  3737. }
  3738. else
  3739. $param->description = $description->{current_language()};
  3740. $param->description_lang = $iassign_ilm->description;
  3741. $param->extension = $iassign_ilm->extension;
  3742. $param->author = $iassign_ilm->author;
  3743. $param->file_jar = $iassign_ilm->file_jar;
  3744. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  3745. $param->file_class = $iassign_ilm->file_class;
  3746. $param->width = $iassign_ilm->width;
  3747. $param->height = $iassign_ilm->height;
  3748. $param->enable = $iassign_ilm->enable;
  3749. $param->timecreated = $iassign_ilm->timecreated;
  3750. $param->timemodified = time();
  3751. $param->evaluate = $iassign_ilm->evaluate;
  3752. $param->parent = $iassign_ilm->parent;
  3753. }
  3754. }
  3755. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  3756. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  3757. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3758. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  3759. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  3760. // echo "Sem dados<br/>"; exit;
  3761. return;
  3762. }
  3763. $description = json_decode($iassign_ilm->description);
  3764. if ($iassign_ilm) {
  3765. if ($iassign_ilm->parent == 0)
  3766. $iassign_ilm->parent = $ilm_id;
  3767. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  3768. $param->title = get_string('new_version_ilm', 'iassign');
  3769. $param->name_ilm = $iassign_ilm->name;
  3770. $param->name = $iassign_ilm->name;
  3771. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  3772. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  3773. $param->version = $iassign_ilm->version; // do not erase field 'version'
  3774. $param->ilm_type = $iassign_ilm->type;
  3775. $param->url = $iassign_ilm->url;
  3776. $param->description = $description->{current_language()};
  3777. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  3778. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3779. $param->extension = $iassign_ilm->extension;
  3780. $param->author = $USER->id;
  3781. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  3782. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  3783. $param->file_jar_static = '';
  3784. $param->file_class = $iassign_ilm->file_class;
  3785. $param->width = $iassign_ilm->width;
  3786. $param->height = $iassign_ilm->height;
  3787. $param->enable = 0;
  3788. $param->timecreated = time();
  3789. $param->timemodified = time();
  3790. $param->evaluate = $iassign_ilm->evaluate;
  3791. $param->parent = $iassign_ilm->parent;
  3792. }
  3793. }
  3794. elseif ($action == 'copy') {
  3795. $description = json_decode($iassign_ilm->description);
  3796. if ($iassign_ilm) {
  3797. if ($iassign_ilm->parent == 0)
  3798. $iassign_ilm->parent = $ilm_id;
  3799. $param->title = get_string('copy_ilm', 'iassign');
  3800. $param->id = $iassign_ilm->id;
  3801. $param->name_ilm = $iassign_ilm->name;
  3802. $param->name = $iassign_ilm->name;
  3803. $param->version = "";
  3804. $param->ilm_type = $iassign_ilm->type;
  3805. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3806. $param->url = $iassign_ilm->url;
  3807. $param->description = $description->{current_language()};
  3808. $param->description_lang = $iassign_ilm->description;
  3809. $param->extension = $iassign_ilm->extension;
  3810. $param->author = $USER->id;
  3811. $param->file_jar = '';
  3812. $param->file_jar_static = '';
  3813. $param->file_class = $iassign_ilm->file_class;
  3814. $param->width = $iassign_ilm->width;
  3815. $param->height = $iassign_ilm->height;
  3816. $param->enable = 0;
  3817. $param->timecreated = time();
  3818. $param->timemodified = time();
  3819. $param->evaluate = $iassign_ilm->evaluate;
  3820. $param->parent = $iassign_ilm->parent;
  3821. }
  3822. }
  3823. return $param;
  3824. } // static function add_edit_copy_ilm($ilm_id, $action)
  3825. /// Function for save iLM file in moodledata
  3826. // @param int $itemid Itemid of file save in draft (upload file)
  3827. // @param int $ilm_id Id of iLM
  3828. // @return string Return an string with ids of iLM files
  3829. static function new_file_ilm ($itemid, $iassign_ilm) {
  3830. global $CFG, $USER, $DB;
  3831. $return = null;
  3832. $file_jar = array();
  3833. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3834. $contextuser = context_user::instance($USER->id);
  3835. $contextsystem = context_system::instance();
  3836. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  3837. if ($files_ilm) {
  3838. foreach ($files_ilm as $value) {
  3839. // CHECK IF file is HTML type
  3840. if ($iassign_ilm->type == 1) {
  3841. // Check if the file extension is ZIP
  3842. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  3843. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  3844. if ((strtolower($ext) == 'zip')) {
  3845. // Coping...:
  3846. $destination = 'ilm_debug/' . $value->get_filename();
  3847. $value->copy_content_to($destination);
  3848. // Extracting content...:
  3849. $zip = new ZipArchive();
  3850. $extracted = './ilm';
  3851. $dir = "";
  3852. if ($zip->open($destination) === TRUE) {
  3853. $dir = './ilm/' . trim($zip->getNameIndex(0));
  3854. if (is_dir($dir)) {
  3855. $i = 1;
  3856. $previous = str_replace("/", "", $zip->getNameIndex(0));
  3857. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  3858. $i ++;
  3859. }
  3860. $name = $previous . "_" . $i;
  3861. $dir = './ilm/' . $name . "/";
  3862. $j = 0;
  3863. while ($item_name = $zip->getNameIndex($j)) {
  3864. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  3865. $j++;
  3866. }
  3867. $zip->close();
  3868. }
  3869. $zip->open($destination);
  3870. $zip->extractTo($extracted);
  3871. $zip->close();
  3872. // After the extraction, remove it from DEBUG
  3873. unlink($destination);
  3874. } else { // Error trying to open destination...
  3875. // After the extraction error, also remove it from DEBUG
  3876. unlink($destination);
  3877. print_error('error_add_ilm_zip', 'iassign');
  3878. }
  3879. return $dir;
  3880. }
  3881. } // if ($iassign_ilm->type == 1)
  3882. if ($value->get_filename() != '.') {
  3883. $file_ilm = array(
  3884. 'userid' => $USER->id,
  3885. 'contextid' => $contextsystem->id,
  3886. 'component' => 'mod_iassign',
  3887. 'filearea' => 'ilm',
  3888. 'itemid' => rand(1, 999999999),
  3889. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  3890. 'filename' => $value->get_filename());
  3891. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  3892. array_push($file_jar, $file_ilm->get_id());
  3893. }
  3894. }
  3895. if (!empty($file_jar)) {
  3896. $return = implode(",", $file_jar);
  3897. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  3898. foreach ($old_file_jar as $value) {
  3899. $file = $fs->get_file_by_id($value);
  3900. if ($file)
  3901. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  3902. }
  3903. }
  3904. }
  3905. else // if ($files_ilm)
  3906. $return = $iassign_ilm->file_jar;
  3907. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  3908. return $return;
  3909. } // static function new_file_ilm($itemid, $iassign_ilm)
  3910. /// Function for save in database an new iLM
  3911. // @param object $param An object with iLM params
  3912. static function new_ilm ($itemid) {
  3913. global $CFG, $USER, $OUTPUT;
  3914. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3915. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3916. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3917. }
  3918. $pathtemp = $CFG->dataroot . '/temp/';
  3919. $contextuser = context_user::instance($USER->id);
  3920. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3921. $zip = new zip_packer();
  3922. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3923. foreach ($files as $file) {
  3924. if (!$file->is_directory())
  3925. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3926. }
  3927. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3928. // Verifica se o pacote possui o XML
  3929. if (!$application_xml) {
  3930. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3931. return;
  3932. } else {
  3933. $missing = "";
  3934. if (!isset($application_xml->name)) {
  3935. $missing .= "name";
  3936. }
  3937. if (!isset($application_xml->version)) {
  3938. $missing .= ", version";
  3939. }
  3940. if (!isset($application_xml->type)) {
  3941. $missing .= ", type";
  3942. }
  3943. if (!isset($application_xml->extension)) {
  3944. $missing .= ", extension";
  3945. }
  3946. if (!isset($application_xml->file_jar)) {
  3947. $missing .= ", file_jar";
  3948. }
  3949. if (!isset($application_xml->file_class)) {
  3950. $missing .= ", file_class";
  3951. }
  3952. if (!isset($application_xml->width)) {
  3953. $missing .= ", width";
  3954. }
  3955. if (!isset($application_xml->height)) {
  3956. $missing .= ", height";
  3957. }
  3958. if (!isset($application_xml->evaluate)) {
  3959. $missing .= ", evaluate";
  3960. }
  3961. if (strlen($missing) > 2) {
  3962. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3963. return;
  3964. }
  3965. }
  3966. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3967. $typec = strtolower($application_xml->type);
  3968. require_once 'ilm_handlers/' . $typec . '.php';
  3969. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3970. return $retorno;
  3971. } // static function new_ilm($itemid)
  3972. /// Function for save in database an iLM edit
  3973. // @param object $param An object with iLM params
  3974. static function edit_ilm ($param, $itemid) {
  3975. // Descobrir o tipo de iLM:
  3976. global $DB, $USER, $CFG;
  3977. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  3978. $pathtemp = $CFG->dataroot . '/temp/';
  3979. $contextuser = context_user::instance($USER->id);
  3980. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3981. $zip = new zip_packer();
  3982. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3983. $files_extract = null;
  3984. foreach ($files as $file) {
  3985. if (!$file->is_directory())
  3986. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3987. }
  3988. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  3989. $typec = strtolower($iassign_t->type);
  3990. require_once 'ilm_handlers/' . $typec . '.php';
  3991. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  3992. }
  3993. /// Function for register the new iLM (in database and in the directory)
  3994. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  3995. // @param object $param An object with iLM params
  3996. static function copy_new_version_ilm ($param) {
  3997. global $DB, $CFG, $USER;
  3998. $itemid = $param->file;
  3999. $pathtemp = $CFG->dataroot . '/temp/';
  4000. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4001. //D echo "pathtemp=$pathtemp<br/>";
  4002. $contextuser = context_user::instance($USER->id);
  4003. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4004. $zip = new zip_packer();
  4005. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4006. $files_extract = null;
  4007. foreach ($files as $file) {
  4008. if (!$file->is_directory())
  4009. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4010. }
  4011. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4012. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4013. $typec = strtolower($iassign_t->type);
  4014. require_once 'ilm_handlers/' . $typec . '.php';
  4015. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4016. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4017. } // static function copy_new_version_ilm($param)
  4018. //VER::
  4019. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4020. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4021. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4022. /// Function for change visibility of iLM
  4023. // @param int $ilm_id Id of iLM
  4024. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4025. static function visible_ilm ($ilm_id, $status) {
  4026. global $DB;
  4027. if ($status == 0)
  4028. $visible = 1;
  4029. else
  4030. $visible = 0;
  4031. $newentry = new stdClass();
  4032. $newentry->id = $ilm_id;
  4033. $newentry->enable = $visible;
  4034. if (!$DB->update_record("iassign_ilm", $newentry))
  4035. error(get_string('error_edit_ilm', 'iassign'));
  4036. }
  4037. /// Function for confirm change default iLM
  4038. // @param int $ilm_id Id of iLM
  4039. // @param int $ilm_parent Id of parent iLM
  4040. // @return string Return with an string for create default page confirmation
  4041. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4042. global $OUTPUT, $DB;
  4043. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4044. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4045. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4046. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4047. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4048. return $return;
  4049. }
  4050. /// Function for change the default iLM
  4051. // @see settings_ilm.php
  4052. // @param int $ilm_id Id of iLM
  4053. // @return int Return Id of default iLM
  4054. static function default_ilm ($ilm_id) {
  4055. global $DB;
  4056. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4057. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4058. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4059. $iassign_ilm_default->id = $iassign_ilm->id;
  4060. $iassign_ilm_default->parent = 0;
  4061. $iassign_ilm->parent = $iassign_ilm_default->id;
  4062. $iassign_ilm->id = 0;
  4063. $iassign_ilm_default->enable = 1;
  4064. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4065. print_error('error_edit_ilm', 'iassign');
  4066. }
  4067. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4068. if (!$inserted) {
  4069. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4070. print_error($msg_error);
  4071. //xx print_error('error_add_ilm', 'iassign');
  4072. }
  4073. return $iassign_ilm_default->id;
  4074. } // static function default_ilm ($ilm_id)
  4075. /// Function for confirm delete iLM
  4076. // @param int $ilm_id Id of iLM
  4077. // @param int $ilm_parent Id of parent iLM
  4078. // @return string Return with an string for create delete page confirmation
  4079. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4080. global $OUTPUT, $DB;
  4081. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4082. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4083. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4084. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4085. }
  4086. /// Function for delete directory where the iLM is allocated.
  4087. // @param string $dirPath
  4088. // @throws InvalidArgumentException
  4089. public static function delete_dir ($dirPath) {
  4090. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4091. $dirPath .= '/';
  4092. }
  4093. $files = glob($dirPath . '*', GLOB_MARK);
  4094. foreach ($files as $file) {
  4095. if (is_dir($file)) {
  4096. ilm_settings::delete_dir($file);
  4097. } else {
  4098. unlink($file);
  4099. }
  4100. }
  4101. rmdir($dirPath);
  4102. }
  4103. /// Function for delete iLM
  4104. // @param int $ilm_id Id of iLM
  4105. // @return int Return Id of parent iLM
  4106. static function delete_ilm ($ilm_id) {
  4107. global $DB;
  4108. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4109. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4110. $typec = strtolower($iassign_ilm->type);
  4111. require_once 'ilm_handlers/' . $typec . '.php';
  4112. $retorno = $typec::delete_ilm($ilm_id);
  4113. return $retorno;
  4114. }
  4115. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4116. // @param int $ilm_id Id of iLM
  4117. static function export_ilm ($ilm_id) {
  4118. global $DB;
  4119. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4120. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4121. $typec = strtolower($iassign_ilm->type);
  4122. require_once 'ilm_handlers/' . $typec . '.php';
  4123. $typec::export_ilm($ilm_id);
  4124. } // static function export_ilm($ilm_id)
  4125. //TODO iLM_HTML5 :: //MOOC 2016
  4126. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4127. // @param int $ilm_id Id of iLM
  4128. static function export_update_ilm ($ilm_id) {
  4129. global $DB, $CFG;
  4130. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4131. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4132. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4133. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4134. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4135. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4136. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4137. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4138. $upgrade_descriptor .= '</upgrade>' . "\n";
  4139. file_put_contents($xml_filename, $upgrade_descriptor);
  4140. header("Pragma: public");
  4141. header("Expires: 0");
  4142. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4143. header("Cache-Control: private", false);
  4144. header('Content-Type: application/xml; charset=utf-8');
  4145. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4146. header("Content-Length: " . @filesize($xml_filename));
  4147. set_time_limit(0);
  4148. @readfile("$xml_filename") || die("File not found.");
  4149. unlink($xml_filename);
  4150. exit;
  4151. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4152. /// Function for save iLM from XML descriptor
  4153. // @param array $application_xml Data of XML descriptor
  4154. // @param array $files_extract Filenames of extract files
  4155. // @return array Return an array content id of JAR files
  4156. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4157. global $CFG, $USER;
  4158. // Tratamento diferenciado se for do tipo HTML5:
  4159. $source = "";
  4160. $diretorio = "";
  4161. if (strtolower($application_xml->type) == 'html5') {
  4162. $i = 0;
  4163. foreach ($files_extract as $key => $value) {
  4164. $file = $CFG->dataroot . '/temp/' . $key;
  4165. // Verifica se já existe a pasta no diretório dos iLM:
  4166. if ($i == 0) {
  4167. $source = $file;
  4168. if (file_exists("ilm/" . basename($file))) {
  4169. $j = 1;
  4170. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4171. $j ++;
  4172. }
  4173. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4174. // mkdir($diretorio, 0777, true);
  4175. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4176. }
  4177. else {
  4178. $diretorio = 'ilm/' . basename($file);
  4179. // mkdir($diretorio, 0777, true);
  4180. mkdir($diretorio, 0755, true);
  4181. }
  4182. break;
  4183. }
  4184. $i ++;
  4185. }
  4186. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4187. if ($item->isDir()) {
  4188. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4189. }
  4190. else {
  4191. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4192. }
  4193. }
  4194. ilm_settings::delete_dir($source);
  4195. return "./" . $diretorio;
  4196. }
  4197. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4198. $file_jar = array();
  4199. $files_ilm = explode(",", $application_xml->file_jar);
  4200. $contextsystem = context_system::instance();
  4201. foreach ($files_ilm as $value) {
  4202. $file_ilm = array(
  4203. 'userid' => $USER->id,
  4204. 'contextid' => $contextsystem->id,
  4205. 'component' => 'mod_iassign',
  4206. 'filearea' => 'ilm',
  4207. 'itemid' => rand(1, 999999999),
  4208. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4209. 'filename' => $value);
  4210. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4211. array_push($file_jar, $file_ilm->get_id());
  4212. }
  4213. foreach ($files_extract as $key => $value) {
  4214. $file = $CFG->dataroot . '/temp/' . $key;
  4215. if (file_exists($file))
  4216. unlink($file);
  4217. }
  4218. return $file_jar;
  4219. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4220. /// Function for import the iLM from an package
  4221. // @param int $itemid Itemid of zip file
  4222. static function import_ilm ($itemid) {
  4223. global $CFG, $USER, $OUTPUT;
  4224. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4225. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4226. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4227. }
  4228. $pathtemp = $CFG->dataroot . '/temp/';
  4229. $contextuser = context_user::instance($USER->id);
  4230. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4231. $zip = new zip_packer();
  4232. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4233. foreach ($files as $file) {
  4234. if (!$file->is_directory())
  4235. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4236. }
  4237. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4238. // Verifica se o pacote possui o XML
  4239. if (!$application_xml) {
  4240. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4241. return;
  4242. } else {
  4243. $missing = "";
  4244. if (!isset($application_xml->name)) {
  4245. $missing .= "name";
  4246. }
  4247. if (!isset($application_xml->version)) {
  4248. $missing .= ", version";
  4249. }
  4250. if (!isset($application_xml->type)) {
  4251. $missing .= ", type";
  4252. }
  4253. if (!isset($application_xml->extension)) {
  4254. $missing .= ", extension";
  4255. }
  4256. if (!isset($application_xml->file_jar)) {
  4257. $missing .= ", file_jar";
  4258. }
  4259. if (!isset($application_xml->file_class)) {
  4260. $missing .= ", file_class";
  4261. }
  4262. if (!isset($application_xml->width)) {
  4263. $missing .= ", width";
  4264. }
  4265. if (!isset($application_xml->height)) {
  4266. $missing .= ", height";
  4267. }
  4268. if (!isset($application_xml->evaluate)) {
  4269. $missing .= ", evaluate";
  4270. }
  4271. if (strlen($missing) > 2) {
  4272. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4273. return;
  4274. }
  4275. }
  4276. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4277. $typec = strtolower($application_xml->type);
  4278. require_once 'ilm_handlers/' . $typec . '.php';
  4279. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4280. } // static function import_ilm($itemid)
  4281. /// Function for list iLM defaults
  4282. // @return string Return an string with a table of iLM
  4283. static function list_ilm () {
  4284. global $DB, $OUTPUT;
  4285. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4286. $str = '';
  4287. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4288. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4289. if ($iassign_ilm) {
  4290. foreach ($iassign_ilm as $ilm) {
  4291. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4292. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4293. $str .= '<tr><td>';
  4294. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4295. $str .= '<tr>';
  4296. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4297. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4298. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4299. $str .= '</tr>';
  4300. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4301. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4302. $str .= '</table>';
  4303. $str .= '</td></tr>';
  4304. }
  4305. }
  4306. $str .= '</table>';
  4307. return $str;
  4308. }
  4309. /// Function for download and install an upgrade of an iLM
  4310. // @param int $ilm_id Id of iLM
  4311. static function upgrade_ilm ($ilm_id) {
  4312. global $DB, $CFG, $USER;
  4313. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4314. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4315. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4316. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4317. if (!$result)
  4318. print_error('error_upgrade_ilm', 'iassign');
  4319. else {
  4320. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4321. $extension = explode(".", $zip_filename);
  4322. if ($extension[count($extension) - 1] != 'ipz') {
  4323. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4324. die;
  4325. }
  4326. $zip = new zip_packer();
  4327. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4328. $contextuser = context_user::instance($USER->id);
  4329. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4330. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4331. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4332. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4333. if (file_exists($zip_filename))
  4334. unlink($zip_filename);
  4335. if (empty($file_jar)) {
  4336. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4337. print_error($msg_error);
  4338. //xx print_error('error_add_ilm', 'iassign');
  4339. }
  4340. else {
  4341. $newentry = new stdClass();
  4342. $newentry->name = (String) $application_xml->name;
  4343. $newentry->version = (String) $application_xml->version;
  4344. $newentry->url = (String) $application_xml->url;
  4345. $newentry->description = $description_str;
  4346. $newentry->extension = strtolower((String) $application_xml->extension);
  4347. $newentry->file_jar = implode(",", $file_jar);
  4348. $newentry->file_class = (String) $application_xml->file_class;
  4349. $newentry->width = (String) $application_xml->width;
  4350. $newentry->height = (String) $application_xml->height;
  4351. $newentry->enable = 0;
  4352. $newentry->timemodified = time();
  4353. $newentry->author = $USER->id;
  4354. $newentry->timecreated = time();
  4355. $newentry->evaluate = (String) $application_xml->evaluate;
  4356. $newentry->parent = $ilm_id;
  4357. }
  4358. }
  4359. return $iassign_ilm->id;
  4360. } // static function upgrade_ilm($ilm_id)
  4361. //MOOC2014 -- inicio
  4362. //TODO: REVIEW
  4363. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4364. // static function move_iassign($ilm_id)
  4365. //MOOC2014 -- final
  4366. /// Function for list iLM versions with all informations
  4367. // @return string Return an string with a table of iLM
  4368. static function view_ilm ($ilmid, $from) {
  4369. global $DB;
  4370. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4371. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4372. $typec = strtolower($iassign_ilm->type);
  4373. require_once 'ilm_handlers/' . $typec . '.php';
  4374. $retorno = $typec::view_ilm($ilmid, $from);
  4375. return $retorno;
  4376. }
  4377. /// Function for get form variables for add, edit, or copy iLM params
  4378. // @param int $ilm_param_id Id of iLM param
  4379. // @param string $action String with the action
  4380. // @return object Return an object with forms variables
  4381. static function add_edit_copy_param ($ilm_param_id, $action) {
  4382. global $DB;
  4383. require_once('params_form.php');
  4384. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4385. $param = new stdClass();
  4386. $param->action = $action;
  4387. $param->ilm_param_id = $ilm_param_id;
  4388. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4389. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4390. $type = $iassign_ilm_config->param_type;
  4391. if ($action == 'add') {
  4392. $param->title = get_string('add_ilm', 'iassign');
  4393. $param->iassign_ilmid = $ilm_param_id;
  4394. $param->param_name = "";
  4395. $param->param_value = "";
  4396. $param->description = "";
  4397. $param->visible = 1;
  4398. }
  4399. elseif ($action == 'edit') {
  4400. if ($iassign_ilm_config) {
  4401. $param->title = get_string('edit_ilm', 'iassign');
  4402. $param->id = $iassign_ilm_config->id;
  4403. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4404. $param->param_type = $type; //MOOC2014
  4405. $param->param_name = $iassign_ilm_config->param_name;
  4406. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4407. $param->param_value = $iassign_ilm_config->param_value;
  4408. else //MOOC2014
  4409. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4410. $param->param_value = $iassign_ilm_config->param_value;
  4411. $param->description = $iassign_ilm_config->description;
  4412. $param->visible = $iassign_ilm_config->visible;
  4413. }
  4414. }
  4415. elseif ($action == 'copy') {
  4416. if ($iassign_ilm_config) {
  4417. $param->title = get_string('copy_ilm', 'iassign');
  4418. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4419. $param->param_type = $type; //MOOC2014
  4420. $param->param_name = $iassign_ilm_config->param_name;
  4421. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4422. $param->param_value = $iassign_ilm_config->param_value;
  4423. else //MOOC2014
  4424. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4425. $param->description = $iassign_ilm_config->description;
  4426. $param->visible = $iassign_ilm_config->visible;
  4427. }
  4428. }
  4429. return $param;
  4430. } // static function add_edit_copy_param($ilm_param_id, $action)
  4431. /// Function for change visibility of iLM param
  4432. // @param int $ilm_param_id Id of iLM param
  4433. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4434. static function visible_param ($ilm_param_id, $status) {
  4435. global $DB, $CFG;
  4436. if ($status == 0)
  4437. $visible = 1;
  4438. else
  4439. $visible = 0;
  4440. $newentry = new stdClass();
  4441. $newentry->id = $ilm_param_id;
  4442. $newentry->visible = $visible;
  4443. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4444. error(get_string('error_edit_param', 'iassign'));
  4445. }
  4446. /// Function for save in database an new iLM param
  4447. // @param object $param An object with iLM params
  4448. static function add_param ($param) {
  4449. global $DB;
  4450. $newentry = new stdClass();
  4451. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4452. //MOOC2014 $newentry->param_name = $param->param_name;
  4453. $newentry->param_type = $param->param_type; //MOOC2014
  4454. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4455. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4456. $newentry->param_value = $param->param_value;
  4457. else //MOOC2014
  4458. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4459. $newentry->description = $param->description;
  4460. $newentry->visible = $param->visible;
  4461. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4462. if (!$newentry->id) {
  4463. print_error('error_add_param', 'iassign');
  4464. }
  4465. }
  4466. /// Function for save in database a iLM param edit
  4467. // @param object $param An object with iLM params
  4468. static function edit_param ($param) {
  4469. global $DB;
  4470. $updentry = new stdClass();
  4471. $updentry->id = $param->id;
  4472. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4473. $updentry->param_type = $param->param_type; //MOOC2014
  4474. // $updentry->param_name = $param->param_name;
  4475. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4476. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4477. $updentry->param_value = $param->param_value;
  4478. else //MOOC2014
  4479. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4480. $updentry->description = $param->description;
  4481. $updentry->visible = $param->visible;
  4482. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4483. error(get_string('error_edit_param', 'iassign'));
  4484. }
  4485. }
  4486. /// Function for save in database a iLM param copy
  4487. // @param object $param An object with iLM params
  4488. static function copy_param ($param) {
  4489. global $DB;
  4490. $newentry = new stdClass();
  4491. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4492. //$newentry->param_name = $param->param_name;
  4493. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4494. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4495. $newentry->param_value = $param->param_value;
  4496. else //MOOC2014
  4497. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4498. $newentry->description = $param->description;
  4499. $newentry->visible = $param->visible;
  4500. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4501. if (!$newentry->id) {
  4502. print_error('error_add_param', 'iassign');
  4503. }
  4504. }
  4505. /// Function for delete iLM param of database
  4506. // @param int $param_id Id of iLM param
  4507. static function delete_param ($param_id) {
  4508. global $DB;
  4509. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4510. print_error('error_delete_param', 'iassign');
  4511. }
  4512. }
  4513. } // class ilm_settings
  4514. /// Class for manage iLM files (editor).
  4515. class ilm_manager {
  4516. var $id; // course id
  4517. var $url;
  4518. var $from;
  4519. /// Constructor for the base ilm_manager class
  4520. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4521. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4522. function __construct ($id, $url, $from) {
  4523. $this->id = $id; // course id
  4524. $this->url = $url;
  4525. $this->from = $from;
  4526. }
  4527. /// Function to get iAssign content file in Moodle data (exercise)
  4528. // @calledby x function preview_ilm($iassign_ilm) :
  4529. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4530. function get_file_ilm () {
  4531. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4532. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4533. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4534. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4535. $md_file = $fs->get_file_by_id($fileid);
  4536. $ilm_content_file = $md_file->get_content();
  4537. return $ilm_content_file;
  4538. }
  4539. /// Function for creating a new file from the iLM online editor
  4540. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4541. function ilm_editor_new () {
  4542. global $CFG, $DB, $OUTPUT, $PAGE;
  4543. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4544. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4545. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4546. $context = context_course::instance($this->id);
  4547. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4548. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4549. if (!$iassign) {
  4550. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4551. die();
  4552. }
  4553. $temp = explode(",", $iassign->extension);
  4554. $extension = $temp[0]; // default extension for this iLM
  4555. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4556. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4557. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4558. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4559. if ($stringArchiveContent != NULL) {
  4560. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4561. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4562. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4563. $filename = optional_param('filename', NULL, PARAM_RAW);
  4564. //Leo $filename = iassign_utils::format_filename($filename); //
  4565. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4566. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4567. //2019/02 $arrayfilename = explode(".", $filename);
  4568. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4569. //2019/02 $count_dots = count($arrayfilename);
  4570. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4571. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4572. //2019/02 if ($last_name != $extension)
  4573. //2019/02 $filename = $filename . '.' . $extension;
  4574. //2019/02 }
  4575. //2019/02 else { // no extension...
  4576. //2019/02 $filename = $filename . '.' . $extension;
  4577. //2019/02 }
  4578. // Store the name of recent created file
  4579. $_SESSION['file_name'] = $filename;
  4580. //$this->write_file_iassign($string, $filename);
  4581. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4582. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4583. die();
  4584. }
  4585. else { // if ($stringArchiveContent != NULL)
  4586. // iLM On-line editor
  4587. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4588. $str_get_iLM = "window.frames.iLM";
  4589. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4590. }
  4591. else { // otherwise it is JAR named 'iLM'
  4592. $str_get_iLM = "document.iLM";
  4593. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4594. }
  4595. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4596. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4597. $files_array = '';
  4598. foreach ($files as $value) {
  4599. if ($value->get_filename() != ".")
  4600. $files_array .= "'" . $value->get_filename() . "',";
  4601. }
  4602. $files_array .= "''";
  4603. $file = null;
  4604. $ia_content = "";
  4605. $filename = "";
  4606. $error_files_exists = get_string('error_file_exists', 'iassign');
  4607. $output = "<script type='text/javascript'>
  4608. //<![CDATA[
  4609. //D alert('locallib.php: ilm_editor_new');
  4610. function submit_iLM_Answer () {
  4611. var docFormOnLineEditor = document.formEnvio;
  4612. var resposta_exerc = new Array(3);
  4613. var valor_resposta = new Array(3);
  4614. var sessao = new Array(3);
  4615. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4616. resposta_exerc[0] = doc_iLM.getAnswer();
  4617. valor_resposta[0] = doc_iLM.getEvaluation();
  4618. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4619. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4620. var files = new Array(" . $files_array . ");
  4621. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4622. if (docFormOnLineEditor.filename.value=='') {
  4623. // ERROR: the file name is empty
  4624. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4625. return false;
  4626. }
  4627. // }
  4628. for (i=0; i<files.length; i++) {
  4629. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4630. alert('" . $error_files_exists . "');
  4631. return false;
  4632. }
  4633. }
  4634. docFormOnLineEditor.submit();
  4635. return true;
  4636. }
  4637. //]]>
  4638. </script>\n";
  4639. $output .= "
  4640. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4641. $output .= $OUTPUT->box_start();
  4642. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4643. $output .= "
  4644. <table width='100%' cellpadding='20'>
  4645. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4646. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4647. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4648. </tr>
  4649. </table>\n";
  4650. $output .= $OUTPUT->box_end();
  4651. $output .= "<center>\n";
  4652. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4653. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4654. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4655. $output .= $output_ilm;
  4656. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4657. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4658. </center>
  4659. </form>\n";
  4660. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4661. $PAGE->navbar->add($title);
  4662. $PAGE->set_title($title);
  4663. $PAGE->set_heading($title); // insert title above the navigation bar
  4664. print $OUTPUT->header();
  4665. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4666. print $output;
  4667. print $OUTPUT->footer();
  4668. }
  4669. die();
  4670. } // function ilm_editor_new()
  4671. /// Function for editing an file in online editor
  4672. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  4673. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  4674. global $CFG, $DB, $OUTPUT, $PAGE;
  4675. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4676. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4677. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4678. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4679. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4680. // If iLM is not registered, error!
  4681. if (!$iassign) {
  4682. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  4683. die;
  4684. }
  4685. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  4686. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  4687. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  4688. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  4689. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4690. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4691. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  4692. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  4693. if ($stringArchiveContent != NULL) {
  4694. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  4695. die();
  4696. } else { // if ($stringArchiveContent != NULL)
  4697. $end_file = '';
  4698. if ($content_file) {
  4699. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  4700. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  4701. }
  4702. $temp = explode(",", $iassign->extension);
  4703. $extension = $temp[0]; // default extension for this iLM
  4704. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  4705. $str_get_iLM = "window.frames.iLM";
  4706. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4707. } else { // otherwise it is JAR named 'iLM'
  4708. $str_get_iLM = "document.iLM";
  4709. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4710. }
  4711. $output = "<script type='text/javascript'>
  4712. //<![CDATA[
  4713. function submit_iLM_Answer () {
  4714. var docFormEditor = document.formEnvio;
  4715. var activityAnswer; // to get activity answer (text)
  4716. var activityValue; // to get activity answer value (float)
  4717. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4718. //activityAnswer = doc_iLM.getAnswer();
  4719. //activityValue = doc_iLM.getEvaluation();
  4720. activityAnswer = " . $str_get_iLM . ".getAnswer();
  4721. activityValue = " . $str_get_iLM . ".getEvaluation();
  4722. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  4723. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  4724. docFormEditor.submit();
  4725. return true;
  4726. }
  4727. //]]>
  4728. </script>\n";
  4729. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4730. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  4731. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4732. // return true;
  4733. // }
  4734. $output .= "
  4735. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4736. $output .= $OUTPUT->box_start();
  4737. $output .= "
  4738. <table width='100%' cellpadding='20'>
  4739. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  4740. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  4741. <input type='hidden' name='filename' value='$filename'/></td>
  4742. <td>
  4743. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4744. </tr>
  4745. </table>\n";
  4746. $output .= $OUTPUT->box_end();
  4747. $output .= " <center>\n";
  4748. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  4749. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  4750. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  4751. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  4752. </center>
  4753. </form>\n";
  4754. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4755. $PAGE->navbar->add($title);
  4756. $PAGE->set_title($title);
  4757. $PAGE->set_heading($title); // insert title above the navigation bar
  4758. print $OUTPUT->header();
  4759. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4760. print $output;
  4761. print $OUTPUT->footer();
  4762. } // else if ($stringArchiveContent != NULL)
  4763. die();
  4764. } // function ilm_editor_update()
  4765. /// Function for write iAssign file in Moodle data (exercise)
  4766. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  4767. // @param string $stringArchiveContent Content of iassign file
  4768. // @param string $filename Filename of iassign file
  4769. function write_file_iassign ($stringArchiveContent, $filename) {
  4770. global $USER;
  4771. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4772. $context = context_course::instance($this->id);
  4773. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4774. $dirid = $this->get_dir_ilm('dirid');
  4775. $dir = $fs->get_file_by_id($dirid);
  4776. $fileinfo = array('contextid' => $context->id, // ID of course
  4777. 'component' => 'mod_iassign', // usually = table name
  4778. 'filearea' => 'activity', // usually = table name
  4779. 'itemid' => 0, // usually = ID of row in table
  4780. 'filepath' => '/', // any path beginning and ending whith '/'
  4781. 'userid' => $USER->id,
  4782. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4783. 'filename' => $filename); // any filename
  4784. // Create file containing text. '$stringArchiveContent'
  4785. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4786. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  4787. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  4788. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  4789. // 'Activité interactive enregistrée avec succès sous le nom:';
  4790. // 'Atividade interativa gravada com sucesso sob o nome:'
  4791. $output = "
  4792. <script type='text/javascript'>
  4793. //<![CDATA[
  4794. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  4795. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4796. //]]>
  4797. </script>";
  4798. print $output;
  4799. die();
  4800. }
  4801. /// Function for write iAssign file in Moodle data (exercise)
  4802. // @param string $stringArchiveContent Content of iassign file
  4803. // @param string $filename Filename of iassign file
  4804. // @param int $itemid Itemid of iassign file
  4805. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  4806. global $OUTPUT, $USER;
  4807. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4808. $context = context_course::instance($this->id);
  4809. $dirid = $this->get_dir_ilm('dirid');
  4810. if ($stringArchiveContent != (-1)) {
  4811. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4812. $file = $fs->get_file_by_id($fileid);
  4813. if (!$file) {
  4814. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  4815. die;
  4816. }
  4817. $fileinfo = array('contextid' => $context->id, // ID of context
  4818. 'component' => 'mod_iassign', // usually = table name
  4819. 'filearea' => 'activity', // usually = table name
  4820. 'itemid' => 0, // usually = ID of row in table
  4821. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  4822. 'userid' => $USER->id,
  4823. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4824. 'license' => 'allrightsreserved', // allrightsreserved
  4825. 'timecreated' => $file->get_timecreated(),
  4826. 'filename' => $file->get_filename()); // any filename
  4827. $file->delete();
  4828. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4829. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  4830. }
  4831. $output = "<script type='text/javascript'>
  4832. //<![CDATA[
  4833. alert('" . get_string('sucess_update', 'iassign') . "');\n
  4834. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4835. //]]>
  4836. </script>";
  4837. print $output;
  4838. die();
  4839. }
  4840. /// Function for create an tag for iAssign filter
  4841. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  4842. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4843. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  4844. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4845. // @param int $fileid Id of file
  4846. // @return string Return an string with an tag of iassign filter
  4847. function tag_ilm ($fileid) {
  4848. global $DB;
  4849. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4850. $width = '600';
  4851. $height = '400';
  4852. $file = $fs->get_file_by_id($fileid);
  4853. $filetype = explode(".", $file->get_filename());
  4854. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  4855. foreach ($iassign_ilm as $value) {
  4856. $extensions = explode(",", $value->extension);
  4857. if (in_array($filetype[1], $extensions)) {
  4858. $width = $value->width;
  4859. $height = $value->height;
  4860. }
  4861. }
  4862. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  4863. }
  4864. /// Function for delete iAssign file in Moodle data (exercise)
  4865. function delete_file_ilm () {
  4866. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4867. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4868. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  4869. $file = $fs->get_file_by_id($fileid);
  4870. if ($file)
  4871. $file->delete();
  4872. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4873. die();
  4874. }
  4875. /// Function for delete selected iAssign file in Moodle data (exercise)
  4876. function delete_selected_ilm () {
  4877. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4878. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4879. $context = context_course::instance($this->id);
  4880. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4881. $dirid = $this->get_dir_ilm('dirid');
  4882. foreach ($files_id as $file_id) {
  4883. $file = $fs->get_file_by_id($file_id);
  4884. if ($file) {
  4885. if (!$file->is_directory())
  4886. $file->delete();
  4887. else {
  4888. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4889. foreach ($files_delete as $value)
  4890. $value->delete();
  4891. $file->delete();
  4892. }
  4893. }
  4894. }
  4895. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4896. die();
  4897. }
  4898. /// Function for duplicate iAssign file from "online" edition
  4899. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  4900. function duplicate_file_ilm () {
  4901. global $USER, $COURSE;
  4902. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4903. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4904. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4905. $filename = optional_param('filename', NULL, PARAM_RAW);
  4906. $file = $fs->get_file_by_id($fileid);
  4907. $context = context_course::instance($this->id);
  4908. $fileinfo = array(
  4909. 'contextid' => $context->id, // ID of context
  4910. 'component' => 'mod_iassign', // usually = table name
  4911. 'filearea' => 'activity', // usually = table name
  4912. 'itemid' => 0, // usually = ID of row in table
  4913. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  4914. 'userid' => $USER->id,
  4915. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4916. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  4917. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  4918. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  4919. die();
  4920. }
  4921. /// Function for rename iAssign file
  4922. function rename_file_ilm () {
  4923. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4924. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4925. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4926. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4927. $file = $fs->get_file_by_id($fileid);
  4928. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  4929. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  4930. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4931. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  4932. die();
  4933. }
  4934. /// Function for get iassign file for iassign form
  4935. function add_ilm () {
  4936. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4937. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4938. $output = "
  4939. <script type='text/javascript'>
  4940. //<![CDATA[
  4941. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  4942. iassign_file_link.innerHTML = '$filename';
  4943. window.opener.document.forms['mform1'].file.value='$fileid';
  4944. window.opener.document.forms['mform1'].filename.value='$filename';
  4945. window.close();
  4946. //]]>
  4947. </script>";
  4948. print $output;
  4949. die();
  4950. }
  4951. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  4952. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  4953. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  4954. function preview_ilm ($courseid, $iassign_ilm) {
  4955. global $OUTPUT, $CFG, $USER;
  4956. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4957. $title = get_string('modulename', 'iassign'); // iAssign
  4958. print $OUTPUT->header();
  4959. print $OUTPUT->box_start();
  4960. $javascript = "
  4961. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  4962. <script type='text/javascript'>
  4963. //<![CDATA[
  4964. function submit_close () {
  4965. window.opener.location.reload();
  4966. window.close();
  4967. }
  4968. //]]>
  4969. </script>\n";
  4970. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  4971. // to the complete "applet" tag
  4972. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  4973. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  4974. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  4975. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  4976. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  4977. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  4978. if ($ilm_name != "ivprog") {
  4979. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  4980. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  4981. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  4982. } else {
  4983. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  4984. $content_or_id_from_ilm_security = $this->get_file_ilm();
  4985. $timecreated = time();
  4986. $token = md5($timecreated);
  4987. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  4988. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  4989. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  4990. $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)
  4991. }
  4992. $html = "
  4993. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4994. <table border='1'>
  4995. <tr><td>
  4996. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  4997. <!-- iLM calls : end -->
  4998. </td></tr>
  4999. </table>
  5000. <table>
  5001. <tr>
  5002. <td align='center'>
  5003. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5004. </td></tr>
  5005. </table>
  5006. </form>\n";
  5007. print $javascript . $html;
  5008. print $OUTPUT->box_end();
  5009. //NAO echo format_string($html); // Moodle 3.X
  5010. die();
  5011. } // function preview_ilm($courseid, $iassign_ilm)
  5012. //r_ function preview_ilm ($iassign_ilm)
  5013. //r_ /// Function for preview iassign file from iassign filter.
  5014. //r_ function preview_ilm() {
  5015. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5016. //r_ $tag_filter = $this->tag_ilm($fileid);
  5017. //r_ $javascript = "<script type='text/javascript'>
  5018. //r_ //<![CDATA[
  5019. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5020. //r_ //]]>
  5021. //r_ </script>";
  5022. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5023. //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>
  5024. //r_ </table></form></body></html>";
  5025. //r_ echo $javascript . format_text($html);
  5026. //r_ die;
  5027. //r_ }
  5028. /// Function for export an package (zip) of iassign files
  5029. function export_files_ilm () {
  5030. global $CFG;
  5031. $context = context_course::instance($this->id);
  5032. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5033. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5034. $zip = new zip_archive();
  5035. $zip->open($zip_filename);
  5036. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5037. foreach ($files_id as $file_id) {
  5038. $file = $fs->get_file_by_id($file_id);
  5039. if (!$file->is_directory())
  5040. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5041. else {
  5042. $zip->add_directory($file->get_filepath());
  5043. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5044. foreach ($files_zip as $value) {
  5045. if (!$value->is_directory())
  5046. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5047. else
  5048. $zip->add_directory($value->get_filepath());
  5049. }
  5050. }
  5051. }
  5052. $zip->close();
  5053. header("Pragma: public");
  5054. header("Expires: 0");
  5055. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5056. header("Cache-Control: private", false);
  5057. header("Content-Type: application/zip");
  5058. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5059. header("Content-Transfer-Encoding: binary");
  5060. header("Content-Length: " . @filesize($zip_filename));
  5061. set_time_limit(0);
  5062. @readfile("$zip_filename") || die("File not found.");
  5063. unlink($zip_filename);
  5064. exit;
  5065. }
  5066. /// Function of execute a command in button editor tinymce
  5067. // @param int $fileid Id of file
  5068. function tinymce_ilm ($fileid) {
  5069. $tag_filter = $this->tag_ilm($fileid);
  5070. $output = "<script type='text/javascript'>
  5071. //<![CDATA[
  5072. var tag_filter = '$tag_filter';
  5073. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5074. // all right, insert it
  5075. } else {
  5076. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5077. }
  5078. // window.close();
  5079. //]]>
  5080. </script>\n";
  5081. print $output;
  5082. die();
  5083. }
  5084. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5085. /// Function to add content to the Editor Window
  5086. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5087. // @param int $fileid Id of file
  5088. function editor_ilm ($fileid, $editor) {
  5089. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5090. $output1 = "<script type='text/javascript'>
  5091. //<![CDATA[
  5092. var tag_filter = '$tag_filter';\n";
  5093. if ($editor == 'atto') {
  5094. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5095. } elseif ($editor == 'tinyMCE') {
  5096. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5097. } else
  5098. $output2 = "";
  5099. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5100. window.close();
  5101. //]]>
  5102. </script>\n";
  5103. //D var_dump($output);
  5104. print $output1 . $output2 . $output3;
  5105. die();
  5106. }
  5107. /// Function to add content to the Atto Editor Window
  5108. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5109. // @param int $fileid Id of file
  5110. function atto_ilm ($fileid) {
  5111. global $CFG, $DB;
  5112. $tag_filter = $this->tag_ilm($fileid);
  5113. $output = "<script type='text/javascript'>
  5114. //<![CDATA[
  5115. var tag_filter = '$tag_filter';
  5116. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5117. // all right, insert iLM tag to this editor
  5118. } else {
  5119. // error trying to insert
  5120. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5121. }
  5122. //window.close();
  5123. //]]>
  5124. </script>\n";
  5125. print $output;
  5126. die();
  5127. }
  5128. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5129. // @param string $key Key for return information
  5130. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5131. function get_dir_ilm ($key) {
  5132. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5133. $context = context_course::instance($this->id);
  5134. $dirid = optional_param('dirid', 0, PARAM_INT);
  5135. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5136. if ($dirid == 0) {
  5137. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5138. $dirid = $dir->get_id();
  5139. }
  5140. else {
  5141. $dir = $fs->get_file_by_id($dirid);
  5142. $dir_base = $dir->get_filepath();
  5143. }
  5144. $dir_parent = $dir->get_parent_directory();
  5145. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5146. return $data[$key];
  5147. }
  5148. /// Function for create an new dir
  5149. function new_dir_ilm () {
  5150. global $USER;
  5151. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5152. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5153. $dir_base = $this->get_dir_ilm('dir_base');
  5154. $context = context_course::instance($this->id);
  5155. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5156. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5157. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5158. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5159. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5160. }
  5161. /// Function for delete an dir
  5162. function delete_dir_ilm () { //
  5163. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5164. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5165. $context = context_course::instance($this->id);
  5166. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5167. $dir_parent = $this->get_dir_ilm('dir_parent');
  5168. if ($dir) {
  5169. if ($dir->is_directory()) {
  5170. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5171. foreach ($files_delete as $value)
  5172. $value->delete();
  5173. $dir->delete();
  5174. }
  5175. }
  5176. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5177. die();
  5178. }
  5179. /// Function for rename an dir
  5180. function rename_dir_ilm () {
  5181. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5182. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5183. $context = context_course::instance($this->id);
  5184. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5185. $dir_parent = $this->get_dir_ilm('dir_parent');
  5186. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5187. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5188. if ($dir->is_directory()) {
  5189. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5190. foreach ($files_rename_path as $value)
  5191. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5192. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5193. }
  5194. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5195. die();
  5196. }
  5197. /// Function for move an dir and your content for other dir
  5198. function selected_move_ilm () {
  5199. global $PAGE, $OUTPUT, $CFG;
  5200. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5201. $context = context_course::instance($this->id);
  5202. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5203. $dirid = $this->get_dir_ilm('dirid');
  5204. $dir_base = $this->get_dir_ilm('dir_base');
  5205. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5206. $code_javascript_ilm = "
  5207. <script type='text/javascript'>
  5208. //<![CDATA[
  5209. function getRadiobutton () {
  5210. var radioButtons = document.getElementsByTagName('input');
  5211. var param = '';
  5212. for (var counter=0; counter < radioButtons.length; counter++) {
  5213. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5214. param = radioButtons[counter].value;
  5215. }
  5216. return param;
  5217. }
  5218. function move_selected_ilm () {
  5219. var msgAnswer;
  5220. if (getRadiobutton() != '') {
  5221. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5222. if (msgAnswer)
  5223. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5224. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5225. }
  5226. else
  5227. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5228. }
  5229. function cancel_selected_ilm () {
  5230. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5231. }
  5232. //]]>
  5233. </script>\n";
  5234. $title = get_string('move_files', 'iassign');
  5235. $PAGE->set_title($title);
  5236. $PAGE->set_pagelayout('base');
  5237. print $OUTPUT->header();
  5238. print $OUTPUT->heading($title);
  5239. $dir_paths = array();
  5240. print $OUTPUT->box_start();
  5241. print "<center>";
  5242. foreach ($files_id as $file_id) {
  5243. $file = $fs->get_file_by_id($file_id);
  5244. if ($file) {
  5245. if (!$file->is_directory())
  5246. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5247. else {
  5248. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5249. array_push($dir_paths, $file->get_filepath());
  5250. }
  5251. }
  5252. }
  5253. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5254. if ($dir_base != '/') {
  5255. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5256. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5257. }
  5258. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5259. foreach ($files_tree as $file) {
  5260. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5261. $is_parent = false;
  5262. foreach ($dir_paths as $dir) {
  5263. $path = explode("/", $dir);
  5264. array_pop($path);
  5265. $path[count($path) - 1] = '';
  5266. $path = implode("/", $path);
  5267. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5268. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5269. }
  5270. if ($is_parent == false) {
  5271. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5272. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5273. }
  5274. }
  5275. }
  5276. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5277. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5278. print "</center>";
  5279. print $OUTPUT->box_end();
  5280. print $OUTPUT->footer();
  5281. print $code_javascript_ilm;
  5282. die;
  5283. }
  5284. /// Function for move files for an dir
  5285. function move_files_ilm () {
  5286. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5287. $context = context_course::instance($this->id);
  5288. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5289. $dirid = $this->get_dir_ilm('dirid');
  5290. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5291. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5292. foreach ($files_id as $file_id) {
  5293. $file = $fs->get_file_by_id($file_id);
  5294. if ($file) {
  5295. if ($file->is_directory()) {
  5296. $pathname = explode("/", $file->get_filepath());
  5297. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5298. foreach ($files_move_path as $value) {
  5299. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5300. $value->rename($path_move, $value->get_filename());
  5301. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5302. }
  5303. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5304. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5305. $file->rename($path_move, $file->get_filename());
  5306. } else {
  5307. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5308. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5309. }
  5310. }
  5311. }
  5312. //die;
  5313. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5314. die();
  5315. } // function move_files_ilm()
  5316. /// Function for recover files in use on all activities of a course
  5317. function recover_files_ilm () {
  5318. global $DB, $USER;
  5319. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5320. $courseid = optional_param('id', NULL, PARAM_INT);
  5321. $dirid = $this->get_dir_ilm('dirid');
  5322. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5323. $contextfile = context_course::instance($this->id);
  5324. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5325. foreach ($iassigns as $iassign) {
  5326. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5327. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5328. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5329. $context = context_module::instance($cm->id);
  5330. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5331. if ($files) {
  5332. foreach ($files as $value) {
  5333. $extension = explode(".", $value->get_filename());
  5334. if (!$value->is_directory()) {
  5335. $fileinfo = array('contextid' => $contextfile->id,
  5336. 'component' => 'mod_iassign',
  5337. 'filearea' => 'activity',
  5338. 'itemid' => 0,
  5339. 'filepath' => $this->get_dir_ilm('dir_base'),
  5340. 'userid' => $USER->id,
  5341. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5342. 'license' => 'allrightsreserved',
  5343. 'timecreated' => time(),
  5344. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5345. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5346. }
  5347. }
  5348. } // if ($files)
  5349. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5350. } // foreach ($iassigns as $iassign)
  5351. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5352. die();
  5353. } // function recover_files_ilm()
  5354. /// Auxiliary function the get all files in a given context
  5355. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5356. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5357. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5358. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5359. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5360. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5361. // (NAO s_iassign_statement.file = s_files.id)
  5362. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5363. $dir_base = $this->get_dir_ilm('dir_base');
  5364. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5365. $countf = 0;
  5366. $array_files_id = array(); // all files from this context
  5367. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5368. //$filename = $item_fc->get_filename();
  5369. //$filepath = $item_fc->get_filepath();
  5370. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5371. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5372. // $array_files_aux[] = $item_fc;
  5373. $itemid = $item_fc->get_id();
  5374. if (!in_array($itemid, $array_files_id)) {
  5375. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5376. if ($fileuserid == $userid)
  5377. $filesfrommine[] = $item_fc;
  5378. else
  5379. $filesfromothers[] = $item_fc;
  5380. $array_files_id[] = $itemid;
  5381. $countf++;
  5382. }
  5383. }
  5384. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5385. return $countf;
  5386. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5387. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5388. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5389. function get_all_ilm_files_by_fileid ($fileid) {
  5390. global $DB, $USER;
  5391. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5392. //TODO Criar coluna 'authorid'
  5393. $str_query = "SELECT * FROM {iassign_statement} " .
  5394. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5395. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5396. return $array_iassign_ilm;
  5397. }
  5398. //NN
  5399. //NN
  5400. // Build string with JavaScript code with function to edit/remove/double iLM files
  5401. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5402. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5403. global $CFG;
  5404. $error_files_exists = get_string('error_file_exists', 'iassign');
  5405. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5406. $code_javascript_ilm = "
  5407. <script type='text/javascript'>
  5408. //<![CDATA[
  5409. function preview_ilm (fileid, ilmid) { //JavaScript function
  5410. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5411. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5412. }
  5413. function update_ilm (ilmid, fileid) { //JavaScript function
  5414. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5415. }
  5416. function delete_ilm (ilmid, fileid) { //JavaScript function
  5417. var msgAnswer;
  5418. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5419. if (msgAnswer) {
  5420. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5421. }
  5422. }
  5423. function delete_selected_ilm () { //JavaScript function
  5424. var msgAnswer;
  5425. var param = getCheckbox();
  5426. if (param.join() != '') {
  5427. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5428. if (msgAnswer)
  5429. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5430. }
  5431. else
  5432. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5433. }
  5434. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5435. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5436. }
  5437. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5438. var filenamecopy;
  5439. var i;
  5440. var files = new Array(" . $files_array . ");
  5441. do {
  5442. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5443. } while (filenamecopy == '');
  5444. if (filenamecopy == null)
  5445. return false;\n
  5446. else {
  5447. for (i=0;i<files.length;i++) {
  5448. if (files[i]==filenamecopy) {
  5449. alert('" . $error_files_exists . "');
  5450. return false;\n
  5451. }
  5452. }\n" .
  5453. // @see: function 'duplicate_file_ilm()' above
  5454. "
  5455. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5456. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5457. } // else
  5458. }
  5459. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5460. var filenamecopy;
  5461. var i;
  5462. var files = new Array($files_array);
  5463. do {
  5464. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5465. } while (filenamecopy == '');
  5466. if (filenamecopy == null)
  5467. return false;
  5468. else {
  5469. for (i=0;i<files.length;i++) {
  5470. if (files[i]==filenamecopy) {
  5471. alert('" . $error_files_exists . "');
  5472. return false;
  5473. }
  5474. }
  5475. 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;
  5476. }
  5477. }
  5478. function export_files_ilm () { //JavaScript function
  5479. var param = getCheckbox();
  5480. if (param.join() != '')
  5481. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5482. else
  5483. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5484. }
  5485. function select_all_ilm () { //JavaScript function
  5486. var checkBoxes = document.getElementsByTagName('input');
  5487. var selectAll = document.getElementById('select_all');
  5488. for (var counter=0; counter < checkBoxes.length; counter++) {
  5489. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5490. checkBoxes[counter].checked = selectAll.checked;
  5491. }
  5492. }
  5493. function getCheckbox () { //JavaScript function
  5494. var checkBoxes = document.getElementsByTagName('input');
  5495. var param = new Array();
  5496. for (var counter=0; counter < checkBoxes.length; counter++) {
  5497. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5498. param.push(checkBoxes[counter].value);
  5499. }
  5500. return param;
  5501. }
  5502. function new_dir_ilm () { //JavaScript function
  5503. var dirname = '';
  5504. var i;
  5505. var dirs = new Array(" . $dirs_array . ");
  5506. do {
  5507. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5508. } while (dirname == '');
  5509. if (dirname == null)
  5510. return false;\n
  5511. else {
  5512. for (i=0;i<dirs.length;i++) {
  5513. if (dirs[i]==dirname) {
  5514. alert('" . $error_dir_exists . "');
  5515. return false;\n
  5516. }
  5517. }
  5518. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5519. }
  5520. }
  5521. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5522. var msgAnswer;
  5523. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5524. if (msgAnswer) {
  5525. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5526. }
  5527. }
  5528. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5529. var dirnamecopy;
  5530. var i;
  5531. var dirs = new Array($dirs_array);
  5532. do {
  5533. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5534. } while (dirnamecopy == '');
  5535. if (dirnamecopy == null)
  5536. return false;\n
  5537. else {
  5538. for (i=0;i<dirs.length;i++) {
  5539. if (dirs[i]==dirnamecopy) {
  5540. alert('" . $error_dir_exists . "');
  5541. return false;\n
  5542. }
  5543. }
  5544. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5545. }
  5546. }
  5547. function move_selected_ilm (ilmid) { //JavaScript function
  5548. var param = getCheckbox();
  5549. if (param.join() != '')
  5550. 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();
  5551. else
  5552. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5553. }
  5554. function recover_files_ilm () { //JavaScript function
  5555. var msgAnswer;
  5556. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5557. if (msgAnswer) {
  5558. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5559. }
  5560. }
  5561. window.onload = function() { //JavaScript function
  5562. var xPosition = 0;
  5563. var yPosition = 0;
  5564. element=document.getElementById('new_file');
  5565. while(element) {
  5566. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5567. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5568. element = element.offsetParent;
  5569. }
  5570. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5571. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5572. location.hash = '#new_file';
  5573. };
  5574. //]]>
  5575. </script>\n"; // end of $code_javascript_ilm
  5576. return $code_javascript_ilm;
  5577. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5578. /// List iassign files from course directory
  5579. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5580. function view_files_ilm ($iassign_ilm_class, $extension) {
  5581. global $CFG, $DB, $USER, $OUTPUT;
  5582. $fs = get_file_storage();
  5583. $context = context_course::instance($this->id);
  5584. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5585. $dirid = $this->get_dir_ilm('dirid');
  5586. $dir_base = $this->get_dir_ilm('dir_base');
  5587. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5588. $files_array = '';
  5589. foreach ($files_course as $value) {
  5590. if (!$value->is_directory())
  5591. $files_array .= "'" . $value->get_filename() . "',";
  5592. }
  5593. $files_array .= "''";
  5594. $error_files_exists = get_string('error_file_exists', 'iassign');
  5595. $dirs_array = '';
  5596. foreach ($files_course as $value) {
  5597. if ($value->is_directory()) {
  5598. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  5599. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5600. }
  5601. }
  5602. $dirs_array .= "''";
  5603. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5604. // TODO Rever o preview pois só deixar ver uma vez.
  5605. $code_javascript_ilm = "
  5606. <script type='text/javascript'>
  5607. //<![CDATA[
  5608. function preview_ilm (fileid, ilmid) {
  5609. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5610. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5611. }
  5612. function update_ilm (ilmid, fileid) {
  5613. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5614. }
  5615. function delete_ilm (ilmid, fileid) {
  5616. var msgAnswer;
  5617. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5618. if (msgAnswer) {
  5619. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5620. }
  5621. }
  5622. function delete_selected_ilm () {
  5623. var msgAnswer;
  5624. var param = getCheckbox();
  5625. if (param.join() != '') {
  5626. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5627. if (msgAnswer)
  5628. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5629. }
  5630. else
  5631. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5632. }
  5633. function add_ilm_iassign (ilmid, filename, fileid) {
  5634. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5635. }
  5636. function duplicate_ilm (ilmid, filename, fileid) {
  5637. var filenamecopy;
  5638. var i;
  5639. var files = new Array($files_array);
  5640. do {
  5641. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5642. } while (filenamecopy == '');
  5643. if (filenamecopy == null)
  5644. return false;\n
  5645. else {
  5646. for (i=0;i<files.length;i++) {
  5647. if (files[i]==filenamecopy) {
  5648. alert('$error_files_exists');
  5649. return false;\n
  5650. }
  5651. }\n" .
  5652. // @see: function 'duplicate_file_ilm()' above
  5653. "
  5654. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5655. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5656. } // else
  5657. }
  5658. function rename_ilm (ilmid, filename, fileid) {
  5659. var filenamecopy;
  5660. var i;
  5661. var files = new Array($files_array);
  5662. do {
  5663. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5664. } while (filenamecopy == '');
  5665. if (filenamecopy == null)
  5666. return false;
  5667. else {
  5668. for (i=0;i<files.length;i++) {
  5669. if (files[i]==filenamecopy) {
  5670. alert('$error_files_exists');
  5671. return false;
  5672. }
  5673. }
  5674. 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;
  5675. }
  5676. }
  5677. function export_files_ilm () {
  5678. var param = getCheckbox();
  5679. if (param.join() != '')
  5680. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5681. else
  5682. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5683. }
  5684. function select_all_ilm () {
  5685. var checkBoxes = document.getElementsByTagName('input');
  5686. var selectAll = document.getElementById('select_all');
  5687. for (var counter=0; counter < checkBoxes.length; counter++) {
  5688. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5689. checkBoxes[counter].checked = selectAll.checked;
  5690. }
  5691. }
  5692. function getCheckbox () {
  5693. var checkBoxes = document.getElementsByTagName('input');
  5694. var param = new Array();
  5695. for (var counter=0; counter < checkBoxes.length; counter++) {
  5696. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5697. param.push(checkBoxes[counter].value);
  5698. }
  5699. return param;
  5700. }
  5701. function new_dir_ilm () {
  5702. var dirname = '';
  5703. var i;
  5704. var dirs = new Array($dirs_array);
  5705. do {
  5706. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5707. } while (dirname == '');
  5708. if (dirname == null)
  5709. return false;\n
  5710. else {
  5711. for (i=0;i<dirs.length;i++) {
  5712. if (dirs[i]==dirname) {
  5713. alert('$error_dir_exists');
  5714. return false;\n
  5715. }
  5716. }
  5717. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5718. }
  5719. }
  5720. function delete_dir_ilm (ilmid, dirid) {
  5721. var msgAnswer;
  5722. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5723. if (msgAnswer) {
  5724. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5725. }
  5726. }
  5727. function rename_dir_ilm (ilmid, dirname, dirid) {
  5728. var dirnamecopy;
  5729. var i;
  5730. var dirs = new Array($dirs_array);
  5731. do {
  5732. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5733. } while (dirnamecopy == '');
  5734. if (dirnamecopy == null)
  5735. return false;\n
  5736. else {
  5737. for (i=0;i<dirs.length;i++) {
  5738. if (dirs[i]==dirnamecopy) {
  5739. alert('$error_dir_exists');
  5740. return false;\n
  5741. }
  5742. }
  5743. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5744. }
  5745. }
  5746. function move_selected_ilm (ilmid) {
  5747. var param = getCheckbox();
  5748. if (param.join() != '')
  5749. 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();
  5750. else
  5751. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5752. }
  5753. function recover_files_ilm () {
  5754. var msgAnswer;
  5755. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5756. if (msgAnswer) {
  5757. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5758. }
  5759. }
  5760. window.onload = function() {
  5761. var xPosition = 0;
  5762. var yPosition = 0;
  5763. element=document.getElementById('new_file');
  5764. while(element) {
  5765. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5766. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5767. element = element.offsetParent;
  5768. }
  5769. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5770. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5771. location.hash = '#new_file';
  5772. };
  5773. //]]>
  5774. </script>\n";
  5775. $output = "";
  5776. $select_all = "";
  5777. $count_files = 0;
  5778. $extensions_allow = array();
  5779. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  5780. foreach ($iassign_ilm as $item_iassign_ilm)
  5781. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  5782. foreach ($files_course as $value) {
  5783. $filename = $value->get_filename();
  5784. $filepath = $value->get_filepath();
  5785. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  5786. $pathname = $pathname[count($pathname) - 1];
  5787. $fileid = $value->get_id();
  5788. $tmp = explode(".", $filename);
  5789. $filetype = $tmp[1];
  5790. $author = $value->get_author();
  5791. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  5792. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  5793. $extensions = explode(",", $extension);
  5794. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  5795. $count_files ++;
  5796. // buscar fileid nas tabelas do iassign
  5797. $list_filein_use = "";
  5798. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5799. if ($iassign_statement_activity_list) {
  5800. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5801. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  5802. }
  5803. }
  5804. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  5805. if (!$iassign_ilm) {
  5806. $iassign_ilm = new stdClass();
  5807. $iassign_ilm->id = $ilmid;
  5808. }
  5809. // Do not use $var inside "..." - problem with some "unusual" operational system
  5810. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  5811. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  5812. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  5813. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  5814. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5815. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5816. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5817. $check_select = "";
  5818. $link_rename = "";
  5819. $link_delete = "";
  5820. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5821. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5822. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5823. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  5824. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5825. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5826. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5827. if ($value->get_userid() == $USER->id) {
  5828. if ($iassign_statement_activity_list) {
  5829. $check_select = "";
  5830. $link_edit = iassign_icons::insert('edit_iassign_disable');
  5831. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  5832. $link_rename = "";
  5833. } else {
  5834. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  5835. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  5836. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  5837. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  5838. }
  5839. }
  5840. if (!in_array($filetype, $extensions_allow)) {
  5841. $link_edit = "";
  5842. $link_add_ilm_iassign = "";
  5843. $link_add_ilm_tinymce = "";
  5844. $link_add_ilm_atto = "";
  5845. $link_filter = "";
  5846. }
  5847. if ($value->is_directory()) {
  5848. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  5849. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  5850. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  5851. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  5852. <td><center>$author</center></td>
  5853. <td><center>$timecreated</center></td>
  5854. <td><center>$timemodified</center></td></tr>\n";
  5855. }
  5856. else if ($this->from == 'iassign') {
  5857. $new_id = "";
  5858. $new_class = "";
  5859. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  5860. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  5861. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  5862. }
  5863. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  5864. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5865. <td><center>$author</center></td>
  5866. <td><center>$timecreated</center></td>
  5867. <td><center>$timemodified</center></td></tr>\n";
  5868. }
  5869. else if ($this->from == 'block') {
  5870. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  5871. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5872. <td><center>$author</center></td>
  5873. <td><center>$timecreated</center></td>
  5874. <td><center>$timemodified</center></td></tr>\n";
  5875. }
  5876. else if ($this->from == 'tinymce') {
  5877. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  5878. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5879. <td><center>$author</center></td>
  5880. <td><center>$timecreated</center></td>
  5881. <td><center>$timemodified</center></td></tr>\n";
  5882. }
  5883. else if ($this->from == 'atto') {
  5884. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  5885. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5886. <td><center>$author</center></td>
  5887. <td><center>$timecreated</center></td>
  5888. <td><center>$timemodified</center></td></tr>\n";
  5889. }
  5890. }
  5891. }
  5892. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  5893. $dir_base = "";
  5894. $header = "";
  5895. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  5896. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  5897. foreach ($basename as $value) {
  5898. $dir_base .= $value . "/";
  5899. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  5900. if ($dir_id) {
  5901. if ($value == "") {
  5902. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5903. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  5904. } else {
  5905. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5906. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  5907. }
  5908. }
  5909. } // foreach ($basename as $value)
  5910. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  5911. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  5912. $html .= "
  5913. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  5914. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  5915. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  5916. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  5917. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  5918. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  5919. </table>\n";
  5920. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  5921. $html .= "<table width='100%'><tr>\n";
  5922. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  5923. if ($count_files != 0) {
  5924. $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";
  5925. $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";
  5926. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  5927. }
  5928. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  5929. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  5930. $html .= "</form>\n";
  5931. print $code_javascript_ilm;
  5932. print $html;
  5933. } // function view_files_ilm($extension)
  5934. } // class ilm_manager
  5935. /// Class to insert of icons
  5936. class iassign_icons {
  5937. static function insert ($icon) {
  5938. global $CFG;
  5939. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  5940. return $string;
  5941. }
  5942. }
  5943. /// Class with util functions for plugin manage
  5944. class iassign_utils {
  5945. /// Function to return the filename extension
  5946. // @param string The $filename as an string
  5947. // @return string Return an string (last group after '.')
  5948. static function filename_extension ($filename) {
  5949. if ($filename == null || $filename == '') {
  5950. return null;
  5951. }
  5952. $itens = explode('.', $filename);
  5953. $num = count($itens);
  5954. if ($num < 2) {
  5955. return null;
  5956. }
  5957. return $itens[$num - 1];
  5958. }
  5959. /// Use the PHP class/package ZipArchive to create a Zip file
  5960. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  5961. // 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
  5962. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  5963. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  5964. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  5965. $zip = new zip_archive(); //2
  5966. $res = $zip->open($full_path_zip_filename);
  5967. $total_vet = count($vet_student_filename);
  5968. for ($ii=0; $ii<$total_vet; $ii++) {
  5969. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  5970. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  5971. }
  5972. $ret = $zip->close();
  5973. iassign_utils::download_file($full_path_zip_filename);
  5974. $filenameZip = $zip->filename;
  5975. return array($ret, $zip);
  5976. }
  5977. static function download_file ($zip_filename) {
  5978. header("Pragma: public");
  5979. header("Expires: 0");
  5980. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5981. header("Cache-Control: private", false);
  5982. header("Content-Type: application/zip");
  5983. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5984. header("Content-Transfer-Encoding: binary");
  5985. header("Content-Length: " . @filesize($zip_filename));
  5986. set_time_limit(0);
  5987. @readfile("$zip_filename") || die("File not found.");
  5988. unlink($zip_filename);
  5989. }
  5990. /// Function for format filename remove special caracters
  5991. // @param string $text String for clean
  5992. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  5993. // @return string Return an string in clean format
  5994. static function format_filename ($text) {
  5995. if ($text != '.') {
  5996. //D $text = htmlspecialchars(urldecode($text));
  5997. //D echo "locallib.php: format_filename: $text<br/>";
  5998. if (is_object($text)) // with iAssign did not filtered text from JSON format
  5999. $text = json_decode($text)->{current_language()};
  6000. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6001. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6002. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6003. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6004. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6005. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6006. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6007. // E.g. text = "exerc_midpoint.course.geo"
  6008. // 0123456789012345678901234
  6009. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6010. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6011. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6012. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6013. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6014. //$ext = strrpos($text, ".");
  6015. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6016. //$text = str_replace($array1, $array2, $text);
  6017. }
  6018. return $text;
  6019. }
  6020. /// Function to filter characters to the file name to iLM content
  6021. // @param string $text String for clean
  6022. // @param string $ext String ot the extension of the iLM
  6023. // @return string Return an string in clean format
  6024. static function filter_filename_extension ($filename, $ext) {
  6025. if ($filename != '.') {
  6026. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6027. $arrTo = array("_","","","","","","","","","","","","");
  6028. $filename = str_replace($arrFrom, $arrTo, $filename);
  6029. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6030. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6031. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6032. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6033. $index_lastposition = strlen($filenameF);
  6034. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6035. $text = str_replace(".", "_", $text); // erase all other "."
  6036. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6037. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6038. }
  6039. else
  6040. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6041. return $filenameF;
  6042. }
  6043. /// Function for format pathname remove special caracters
  6044. // @param string $text String for clean
  6045. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6046. // @return string Return an string in clean format
  6047. static function format_pathname ($text, $is_lowercase = true) {
  6048. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6049. $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", "-", "_", "", "", "");
  6050. $text = str_replace($array1, $array2, $text);
  6051. if ($is_lowercase)
  6052. $text = strtolower($text);
  6053. return $text;
  6054. }
  6055. /// Function for format file name from iLM original name
  6056. // @param string $text String to build the file neam
  6057. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6058. // @return string Return an string in clean format
  6059. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6060. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6061. $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", "-", "_", "", "", "");
  6062. $index_firstposition_blank = strpos($ilm_name, " ");
  6063. if ($index_firstposition_blank) { // truncate the name!
  6064. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6065. }
  6066. $index_firstposition_dots = strpos($ilm_name, ":");
  6067. if ($index_firstposition_dots) { // truncate the name!
  6068. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6069. }
  6070. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6071. if ($is_lowercase)
  6072. $namefiltered = strtolower($namefiltered);
  6073. return $namefiltered;
  6074. }
  6075. /// Function for insert version in the filename
  6076. // @param string $filename Name of file
  6077. // @return string Return the filename with version
  6078. static function version_filename ($filename) {
  6079. $array_filename = explode('.', $filename);
  6080. if (count($array_filename) > 1)
  6081. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6082. else
  6083. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6084. return $filename;
  6085. }
  6086. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6087. static function remove_code_message ($string) {
  6088. $array = explode("&lt;ia_uc&gt;", $string);
  6089. return $array[0];
  6090. }
  6091. }
  6092. // class iassign_utils
  6093. /// Class with language functions for plugin manage
  6094. class iassign_language {
  6095. /// Function for return text in language or get default language (en)
  6096. // @param string $lang Code of language
  6097. // @param string $description JSON text content all languages
  6098. // @return string Return an string in the language selected
  6099. static function get_description_lang ($lang, $descriptions) {
  6100. $description_lang = "";
  6101. $description = json_decode($descriptions);
  6102. if ($description == null) {
  6103. $description_lang = $descriptions;
  6104. }
  6105. else {
  6106. if (isset($description->{$lang}))
  6107. $description_lang = $description->{$lang};
  6108. else
  6109. if (isset($description->en)) //MOOC2014
  6110. $description_lang = $description->en;
  6111. else //MOOC2014
  6112. $description_lang = "en"; //MOOC2014
  6113. }
  6114. return $description_lang;
  6115. }
  6116. /// Function for return all language supported by iLM
  6117. // @param string $descriptions JSON text content all languages
  6118. // @return string Return as string with all languages
  6119. static function get_all_lang ($descriptions) {
  6120. $langs = "";
  6121. $description = json_decode($descriptions);
  6122. if ($description) {
  6123. foreach ($description as $key => $value) {
  6124. $langs .= $key . " ; ";
  6125. }
  6126. $langs = substr($langs, 0, strlen($langs) - 3);
  6127. }
  6128. return $langs;
  6129. }
  6130. /// Function for convert json in xml //MOOC2014
  6131. // @param string $json JSON text
  6132. // @return string Return as string with xml tags
  6133. static function json_to_xml ($json) {
  6134. $xml = "";
  6135. $json = json_decode($json);
  6136. foreach ($json as $key => $value) {
  6137. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6138. }
  6139. return $xml;
  6140. }
  6141. }
  6142. // class iassign_language
  6143. /// Class with log functions for plugin manage.
  6144. class iassign_log {
  6145. /// Function for insert log event
  6146. // @param string $action Code action of event
  6147. // @param string $information Text for describe action of event
  6148. // @param int $cmid Id of context module
  6149. // @param int $ilmid Id of iLM
  6150. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6151. global $COURSE, $CFG, $USER, $DB;
  6152. $newentry = new stdClass();
  6153. $newentry->time = time();
  6154. $newentry->userid = $USER->id;
  6155. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6156. $newentry->course = $COURSE->id;
  6157. $newentry->cmid = $cmid;
  6158. $newentry->ilmid = $ilmid;
  6159. $newentry->action = $action;
  6160. $newentry->info = $information;
  6161. $newentry->language = current_language();
  6162. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6163. if (ini_get("browscap") && function_exists('get_browse')) {
  6164. $browser = get_browse(null, true);
  6165. $newentry->javascript = $browser['javascript'];
  6166. $newentry->java = $browser['javaapplets'];
  6167. }
  6168. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6169. print_error('error_add_log', 'iassign');
  6170. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6171. } // class iassign_log