locallib.php 320 KB

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