locallib.php 291 KB

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