locallib.php 320 KB

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