locallib.php 290 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061
  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. } else
  2822. print_error('error_add', 'iassign');
  2823. } // function new_iassign($param)
  2824. /// Add the calendar entries for this iassign
  2825. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  2826. // @return bool
  2827. static function add_calendar ($iassignid) {
  2828. global $DB, $CFG;
  2829. require_once($CFG->dirroot . '/calendar/lib.php');
  2830. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  2831. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  2832. $event = new stdClass();
  2833. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  2834. $event->description = $iassign_statement_activity_item->name;
  2835. $event->courseid = $iassign->course;
  2836. $event->groupid = 0;
  2837. $event->userid = 0;
  2838. $event->modulename = 'iassign';
  2839. $event->instance = $iassign->id;
  2840. $event->eventtype = 'due';
  2841. $event->timestart = $iassign_statement_activity_item->timeavailable;
  2842. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  2843. calendar_event::create($event);
  2844. }
  2845. /// Update the calendar entries for this iassign
  2846. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  2847. // @return bool
  2848. function update_calendar ($iassignid, $olddescription) {
  2849. global $DB, $CFG;
  2850. require_once($CFG->dirroot . '/calendar/lib.php');
  2851. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  2852. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  2853. $event = new stdClass();
  2854. $event->id = 0;
  2855. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  2856. if ($events) {
  2857. foreach ($events as $value) {
  2858. if ($value->description == $olddescription) {
  2859. $event->id = $value->id;
  2860. }
  2861. }
  2862. }
  2863. if ($event->id != 0) {
  2864. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  2865. $event->description = $iassign_statement_activity_item->name;
  2866. $event->timestart = $iassign_statement_activity_item->timeavailable;
  2867. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  2868. $calendarevent = calendar_event::load($event->id);
  2869. $calendarevent->update($event);
  2870. } else
  2871. $this->add_calendar($iassignid);
  2872. }
  2873. /// Update the calendar entries for this iassign
  2874. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  2875. // @return bool
  2876. function delete_calendar ($iassignid) {
  2877. global $DB, $CFG;
  2878. require_once($CFG->dirroot . '/calendar/lib.php');
  2879. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  2880. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  2881. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  2882. if ($events) {
  2883. foreach ($events as $value) {
  2884. if ($value->description == $iassign_statement_activity_item->name) {
  2885. $DB->delete_records('event', array('id' => $value->id));
  2886. }
  2887. }
  2888. }
  2889. }
  2890. /// Update interactive activities
  2891. function update_iassign ($param) {
  2892. global $DB;
  2893. $component = 'mod_iassign';
  2894. $filearea = 'exercise';
  2895. $fs = get_file_storage();
  2896. $file = $fs->get_file_by_id($param->file);
  2897. $fileold = $fs->get_file_by_id($param->fileold);
  2898. if ($param->file != $param->fileold) {
  2899. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  2900. $itemid = $file->get_itemid() + $param->iassign_id;
  2901. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  2902. $param->file = $newfile->get_itemid();
  2903. } else
  2904. $param->file = $file->get_itemid();
  2905. if ($fileold) {
  2906. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  2907. foreach ($fileoldarea as $value) {
  2908. $value->delete();
  2909. }
  2910. }
  2911. } else {
  2912. $param->file = $file->get_itemid();
  2913. }
  2914. $newentry = new stdClass();
  2915. $newentry->id = $param->iassign_id;
  2916. $newentry->name = $param->name;
  2917. $newentry->type_iassign = $param->type_iassign;
  2918. $newentry->proposition = $param->proposition;
  2919. $newentry->iassign_ilmid = $param->iassign_ilmid;
  2920. $newentry->file = $param->file;
  2921. $newentry->grade = $param->grade;
  2922. $newentry->author_modified_name = $param->author_modified_name;
  2923. $newentry->timemodified = time();
  2924. if ($param->type_iassign == 1) {
  2925. $newentry->timedue = 0;
  2926. $newentry->timeavailable = 0;
  2927. } // if ($param->type_iassign == 1)
  2928. else {
  2929. $newentry->timedue = $param->timedue;
  2930. $newentry->timeavailable = $param->timeavailable;
  2931. }
  2932. $newentry->preventlate = $param->preventlate;
  2933. $newentry->test = $param->test;
  2934. $newentry->special_param1 = $param->special_param1;
  2935. $newentry->visible = $param->visible;
  2936. $newentry->max_experiment = $param->max_experiment;
  2937. $newentry->dependency = $param->dependency;
  2938. $newentry->automatic_evaluate = $param->automatic_evaluate;
  2939. $newentry->show_answer = $param->show_answer;
  2940. if (!$DB->update_record("iassign_statement", $newentry))
  2941. print_error('error_update', 'iassign');
  2942. if ($param->type_iassign == 3) {
  2943. iassign::update_grade_iassign($param->iassignid);
  2944. }
  2945. //$id = $newentry->id; // MOOC 2016 --- inicio
  2946. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  2947. //if ($iassign_activity_item_configs) {
  2948. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  2949. // $newentry = new stdClass();
  2950. // $newentry->id = $iassign_activity_item_config->id;
  2951. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  2952. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  2953. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  2954. // if (!$DB->update_record("iassign_statement_config", $newentry))
  2955. // print_error('error_edit_param', 'iassign');
  2956. // }
  2957. // } // MOOC 2016 --- final
  2958. // log event --------------------------------------------------------------------------------------
  2959. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  2960. // log event --------------------------------------------------------------------------------------
  2961. return $newentry->id;
  2962. // if ($param->type_iassign==3)
  2963. // $this->update_grade_iassign($param->iassignid);
  2964. } // function update_iassign($param)
  2965. /// Show information of activity
  2966. function show_info_iassign () {
  2967. global $DB, $OUTPUT;
  2968. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  2969. if ($this->activity->type_iassign == 3) {
  2970. if ($this->activity->dependency == 0) {
  2971. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  2972. } else {
  2973. $dependencys = explode(';', $this->activity->dependency);
  2974. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  2975. foreach ($dependencys as $dependency) {
  2976. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2977. if ($dependencyiassign)
  2978. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  2979. } // foreach ($dependencys as $dependency)
  2980. } // if ($iassign_statement_activity_item->dependency == 0)
  2981. if ($this->activity->max_experiment == 0)
  2982. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  2983. else
  2984. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  2985. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  2986. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2987. print $OUTPUT->box($output);
  2988. } // function show_info_iassign()
  2989. /// Shows date of opening and closing activities
  2990. function view_dates () {
  2991. global $USER, $CFG, $DB, $OUTPUT;
  2992. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  2993. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2994. $status_iassign = "";
  2995. $status_iassign1 = "";
  2996. $status_iassign2 = "";
  2997. if ($this->activity->type_iassign == 1) // activity of type example
  2998. $type_iassign = get_string('example_iassign', 'iassign');
  2999. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3000. $type_iassign = get_string('test_iassign', 'iassign');
  3001. if ($this->activity->timeavailable > time()) {
  3002. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3003. } elseif ($this->activity->timedue < time()) {
  3004. $status_iassign = get_string('last_timedue', 'iassign');
  3005. }
  3006. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3007. $type_iassign = get_string('exercise_iassign', 'iassign');
  3008. if ($this->activity->timeavailable > time()) {
  3009. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3010. } elseif ($this->activity->timedue < time()) { // after delivery
  3011. $status_iassign = get_string('last_timedue', 'iassign');
  3012. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3013. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3014. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3015. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3016. if ($this->activity->test == 1) // allowed to test after of deadline
  3017. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3018. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3019. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3020. } // elseif ($iassign_statement_activity_item->test == 0)
  3021. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3022. } // elseif ($iassign_statement_activity_item->timedue < time())
  3023. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3024. $output = '<table width=100% >' . "\n";
  3025. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3026. $output .= '<tr>' . "\n";
  3027. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3028. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3029. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3030. // leo $output .= '<td width=80%>' . $type_iassign;
  3031. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3032. // $output .= '</td>' . "\n";
  3033. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3034. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3035. $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>";
  3036. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3037. } else {
  3038. $link_next = "";
  3039. $link_previous = "";
  3040. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3041. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3042. // previous_activity
  3043. if ($iassign_previous) {
  3044. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3045. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3046. } // next_activity
  3047. if ($iassign_next) {
  3048. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3049. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3050. }
  3051. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3052. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3053. $output .= '</tr></table>' . "\n";
  3054. $output .= '<table width=100% >' . "\n";
  3055. if ($this->activity->type_iassign > 1) {
  3056. if ($this->activity->timeavailable)
  3057. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3058. if ($this->activity->timedue)
  3059. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3060. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3061. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3062. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3063. $output .= '</table>' . "\n";
  3064. print $OUTPUT->box($output);
  3065. } // function view_dates()
  3066. } // class activity
  3067. /// Class to manage Interactive Learning Module (iLM)
  3068. class ilm {
  3069. var $ilm;
  3070. /// Constructor of class
  3071. // @param int $id Id of iLM
  3072. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3073. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3074. function __construct ($id) {
  3075. global $DB;
  3076. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3077. if (empty($this->ilm))
  3078. $this->ilm = null;
  3079. }
  3080. /// Shows activity in iLM
  3081. // @calledby view_iassign_current()
  3082. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3083. global $USER, $CFG, $DB;
  3084. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3085. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3086. $typec = strtolower($iassign_ilm->type);
  3087. require_once 'ilm_handlers/' . $typec . '.php';
  3088. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3089. return $retorno;
  3090. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3091. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3092. // @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);
  3093. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3094. // @param Object $file File in use in activity
  3095. // @return int Return the id of log
  3096. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3097. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3098. $newentry = new stdClass();
  3099. $newentry->iassign_statementid = $iassign_activity_itemid;
  3100. $newentry->userid = $USER->id;
  3101. $newentry->file = $content_or_id_from_ilm_security;
  3102. $newentry->timecreated = time();
  3103. $newentry->view = 1;
  3104. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3105. if (!$id_iLM_security) {
  3106. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3107. } // from (!$DB->insert_record("iassign_security", $newentry))
  3108. return $id_iLM_security;
  3109. }
  3110. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3111. // @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);
  3112. // @param int $userid
  3113. // @param int $iassign_activity_itemid Id of iassign statement
  3114. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3115. global $DB;
  3116. // 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")
  3117. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3118. }
  3119. } // class ilm
  3120. /// Class to manage settings of iLM.
  3121. class ilm_settings {
  3122. /// Function to prepare tag to load iLM (that is stored in Moodle filesystem - usually /var/moodledata/filedir/).
  3123. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3124. // @param int $ilm_id Id of iLM
  3125. // @param array $options An array with options for create dynamic tag html APPLET
  3126. // @return string Return with a tag html APPLET created
  3127. static function build_ilm_tags ($ilm_id, $options = array()) {
  3128. global $DB;
  3129. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3130. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3131. $typec = strtolower($iassign_ilm->type);
  3132. require_once 'ilm_handlers/' . $typec . '.php';
  3133. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3134. return $retorno;
  3135. } // static function build_ilm_tags($ilm_id, $options = array())
  3136. /// Function for get modified date of iLM file
  3137. // @param string $file_jar String with Ids of iLM files
  3138. // @return string Return with the filenames and modified date
  3139. static function applet_filetime ($file_jar) {
  3140. $filetime = "";
  3141. $fs = get_file_storage();
  3142. $files_jar = explode(",", $file_jar);
  3143. foreach ($files_jar as $one_file) {
  3144. $file = $fs->get_file_by_id($one_file);
  3145. if ($file)
  3146. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3147. }
  3148. return $filetime;
  3149. }
  3150. /// Function for verify an default applet
  3151. // @param String $file_jar String containing an list de ids of applet files
  3152. // @return boolean Return true or fale if applet is default
  3153. static function applet_default ($file_jar) {
  3154. $is_default = true;
  3155. $fs = get_file_storage();
  3156. $files_jar = explode(",", $file_jar);
  3157. foreach ($files_jar as $one_file) {
  3158. $file = $fs->get_file_by_id($one_file);
  3159. if ($file)
  3160. $is_default &= ($file->get_itemid() == 0);
  3161. }
  3162. return $is_default;
  3163. }
  3164. /// Function for get form variables for add, edit, or copy iLM
  3165. // @param int $ilm_id Id of iLM
  3166. // @param string $action String with the action
  3167. // @return object Return an object with forms variables
  3168. static function add_edit_copy_ilm ($ilm_id, $action) {
  3169. global $USER, $DB, $CFG;
  3170. require_once('settings_form.php');
  3171. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3172. $param = new stdClass();
  3173. $param->action = $action;
  3174. $param->ilm_id = $ilm_id;
  3175. $CFG->action_ilm = $action;
  3176. $CFG->ilm_id = $ilm_id;
  3177. if ($action == 'add') {
  3178. $param->title = get_string('add_ilm', 'iassign');
  3179. $param->name = "";
  3180. $param->version = "";
  3181. $param->url = "";
  3182. $param->description = "";
  3183. $param->extension = "";
  3184. $param->author = $USER->id;
  3185. $param->file_jar = "";
  3186. $param->file_jar_static = "";
  3187. $param->file_class = "";
  3188. $param->width = 800;
  3189. $param->height = 600;
  3190. $param->enable = 0; // 0 - hide / 1 - show
  3191. $param->timecreated = time();
  3192. $param->timemodified = time();
  3193. $param->evaluate = 0;
  3194. $param->parent = 0;
  3195. } elseif ($action == 'edit') {
  3196. if ($iassign_ilm) {
  3197. $description = json_decode($iassign_ilm->description);
  3198. $param->title = get_string('edit_ilm', 'iassign');
  3199. $param->id = $iassign_ilm->id;
  3200. $param->name_ilm = $iassign_ilm->name;
  3201. $param->name = $iassign_ilm->name;
  3202. $param->version = $iassign_ilm->version;
  3203. $param->ilm_type = $iassign_ilm->type;
  3204. $param->url = $iassign_ilm->url;
  3205. $param->description = $description->{current_language()};
  3206. $param->description_lang = $iassign_ilm->description;
  3207. $param->extension = $iassign_ilm->extension;
  3208. $param->author = $iassign_ilm->author;
  3209. $param->file_jar = $iassign_ilm->file_jar;
  3210. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  3211. $param->file_class = $iassign_ilm->file_class;
  3212. $param->width = $iassign_ilm->width;
  3213. $param->height = $iassign_ilm->height;
  3214. $param->enable = $iassign_ilm->enable;
  3215. $param->timecreated = $iassign_ilm->timecreated;
  3216. $param->timemodified = time();
  3217. $param->evaluate = $iassign_ilm->evaluate;
  3218. $param->parent = $iassign_ilm->parent;
  3219. }
  3220. } elseif ($action == 'new_version') {
  3221. $description = json_decode($iassign_ilm->description);
  3222. if ($iassign_ilm) {
  3223. if ($iassign_ilm->parent == 0)
  3224. $iassign_ilm->parent = $ilm_id;
  3225. $param->title = get_string('new_version_ilm', 'iassign');
  3226. $param->name_ilm = $iassign_ilm->name;
  3227. $param->name = $iassign_ilm->name;
  3228. $param->version = "";
  3229. $param->ilm_type = $iassign_ilm->type;
  3230. $param->url = $iassign_ilm->url;
  3231. $param->description = $description->{current_language()};
  3232. $param->description_lang = $iassign_ilm->description;
  3233. $param->extension = $iassign_ilm->extension;
  3234. $param->author = $USER->id;
  3235. $param->file_jar = '';
  3236. $param->file_jar_static = '';
  3237. $param->file_class = $iassign_ilm->file_class;
  3238. $param->width = $iassign_ilm->width;
  3239. $param->height = $iassign_ilm->height;
  3240. $param->enable = 0;
  3241. $param->timecreated = time();
  3242. $param->timemodified = time();
  3243. $param->evaluate = $iassign_ilm->evaluate;
  3244. $param->parent = $iassign_ilm->parent;
  3245. }
  3246. } elseif ($action == 'copy') {
  3247. $description = json_decode($iassign_ilm->description);
  3248. if ($iassign_ilm) {
  3249. if ($iassign_ilm->parent == 0)
  3250. $iassign_ilm->parent = $ilm_id;
  3251. $param->title = get_string('copy_ilm', 'iassign');
  3252. $param->id = $iassign_ilm->id;
  3253. $param->name_ilm = $iassign_ilm->name;
  3254. $param->name = $iassign_ilm->name;
  3255. $param->version = "";
  3256. $param->ilm_type = $iassign_ilm->type;
  3257. $param->url = $iassign_ilm->url;
  3258. $param->description = $description->{current_language()};
  3259. $param->description_lang = $iassign_ilm->description;
  3260. $param->extension = $iassign_ilm->extension;
  3261. $param->author = $USER->id;
  3262. $param->file_jar = '';
  3263. $param->file_jar_static = '';
  3264. $param->file_class = $iassign_ilm->file_class;
  3265. $param->width = $iassign_ilm->width;
  3266. $param->height = $iassign_ilm->height;
  3267. $param->enable = 0;
  3268. $param->timecreated = time();
  3269. $param->timemodified = time();
  3270. $param->evaluate = $iassign_ilm->evaluate;
  3271. $param->parent = $iassign_ilm->parent;
  3272. }
  3273. }
  3274. return $param;
  3275. } // static function add_edit_copy_ilm($ilm_id, $action)
  3276. /// Function for save iLM file in moodledata
  3277. // @param int $itemid Itemid of file save in draft (upload file)
  3278. // @param int $ilm_id Id of iLM
  3279. // @return string Return an string with ids of iLM files
  3280. static function new_file_ilm ($itemid, $iassign_ilm) {
  3281. global $CFG, $USER, $DB;
  3282. $return = null;
  3283. $file_jar = array();
  3284. $fs = get_file_storage();
  3285. $contextuser = context_user::instance($USER->id);
  3286. $contextsystem = context_system::instance();
  3287. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  3288. if ($files_ilm) {
  3289. foreach ($files_ilm as $value) {
  3290. // VERIFICA SE e' DO TIPO HTML5
  3291. if ($iassign_ilm->type == 1) {
  3292. // Verifica a extensão do arquivo iLM para verificar se é ZIP
  3293. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  3294. // CASO SEJA ZIP: COPIA O ARQUIVO, PARA O ilm_debug E DESCOMPACTA no diretorio 'ilm'
  3295. if ((strtolower($ext) == 'zip')) {
  3296. // COPIA:
  3297. $destination = 'ilm_debug/' . $value->get_filename();
  3298. $value->copy_content_to($destination);
  3299. // EXTRAIR CONTEUDO:
  3300. $zip = new ZipArchive();
  3301. $extracted = './ilm';
  3302. $dir = "";
  3303. if ($zip->open($destination) === TRUE) {
  3304. $dir = './ilm/' . trim($zip->getNameIndex(0));
  3305. if (is_dir($dir)) {
  3306. $i = 1;
  3307. $previous = str_replace("/", "", $zip->getNameIndex(0));
  3308. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  3309. $i ++;
  3310. }
  3311. $name = $previous . "_" . $i;
  3312. $dir = './ilm/' . $name . "/";
  3313. $j = 0;
  3314. while ($item_name = $zip->getNameIndex($j)) {
  3315. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  3316. $j++;
  3317. }
  3318. $zip->close();
  3319. }
  3320. $zip->open($destination);
  3321. $zip->extractTo($extracted);
  3322. $zip->close();
  3323. // Apos extrair, remover do DEBUG:
  3324. unlink($destination);
  3325. } else {
  3326. // APÓS NAO CONSEGUIR EXTRAIR, apagar O ZIP:
  3327. unlink($destination);
  3328. print_error('error_add_ilm_zip', 'iassign');
  3329. }
  3330. return $dir;
  3331. }
  3332. }
  3333. if ($value->get_filename() != '.') {
  3334. $file_ilm = array(
  3335. 'userid' => $USER->id,
  3336. 'contextid' => $contextsystem->id,
  3337. 'component' => 'mod_iassign',
  3338. 'filearea' => 'ilm',
  3339. 'itemid' => rand(1, 999999999),
  3340. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  3341. 'filename' => $value->get_filename());
  3342. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  3343. array_push($file_jar, $file_ilm->get_id());
  3344. }
  3345. }
  3346. if (!empty($file_jar)) {
  3347. $return = implode(",", $file_jar);
  3348. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  3349. foreach ($old_file_jar as $value) {
  3350. $file = $fs->get_file_by_id($value);
  3351. if ($file)
  3352. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  3353. }
  3354. }
  3355. } else
  3356. $return = $iassign_ilm->file_jar;
  3357. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  3358. return $return;
  3359. }
  3360. /// Function for save in database an new iLM
  3361. // @param object $param An object with iLM params
  3362. static function new_ilm ($itemid) {
  3363. global $CFG, $USER, $OUTPUT;
  3364. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3365. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3366. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3367. }
  3368. $pathtemp = $CFG->dataroot . '/temp/';
  3369. $contextuser = context_user::instance($USER->id);
  3370. $fs = get_file_storage();
  3371. $zip = new zip_packer();
  3372. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3373. foreach ($files as $file) {
  3374. if (!$file->is_directory())
  3375. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3376. }
  3377. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3378. // Verifica se o pacote possui o XML
  3379. if (!$application_xml) {
  3380. echo($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3381. return;
  3382. } else {
  3383. $missing = "";
  3384. if (!isset($application_xml->name)) {
  3385. $missing .= "name";
  3386. }
  3387. if (!isset($application_xml->version)) {
  3388. $missing .= ", version";
  3389. }
  3390. if (!isset($application_xml->type)) {
  3391. $missing .= ", type";
  3392. }
  3393. if (!isset($application_xml->extension)) {
  3394. $missing .= ", extension";
  3395. }
  3396. if (!isset($application_xml->file_jar)) {
  3397. $missing .= ", file_jar";
  3398. }
  3399. if (!isset($application_xml->file_class)) {
  3400. $missing .= ", file_class";
  3401. }
  3402. if (!isset($application_xml->width)) {
  3403. $missing .= ", width";
  3404. }
  3405. if (!isset($application_xml->height)) {
  3406. $missing .= ", height";
  3407. }
  3408. if (!isset($application_xml->evaluate)) {
  3409. $missing .= ", evaluate";
  3410. }
  3411. if (strlen($missing) > 2) {
  3412. echo($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3413. return;
  3414. }
  3415. }
  3416. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3417. $typec = strtolower($application_xml->type);
  3418. require_once 'ilm_handlers/' . $typec . '.php';
  3419. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3420. return $retorno;
  3421. }
  3422. /// Function for save in database an iLM edit
  3423. // @param object $param An object with iLM params
  3424. static function edit_ilm ($param, $itemid) {
  3425. // Descobrir o tipo de iLM:
  3426. global $DB, $USER, $CFG;
  3427. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  3428. $pathtemp = $CFG->dataroot . '/temp/';
  3429. $contextuser = context_user::instance($USER->id);
  3430. $fs = get_file_storage();
  3431. $zip = new zip_packer();
  3432. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3433. $files_extract = null;
  3434. foreach ($files as $file) {
  3435. if (!$file->is_directory())
  3436. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3437. }
  3438. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3439. $typec = strtolower($iassign_t->type);
  3440. require_once 'ilm_handlers/' . $typec . '.php';
  3441. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser);
  3442. }
  3443. /// Function for save in database an iLM copy
  3444. // @param object $param An object with iLM params
  3445. static function copy_new_version_ilm ($param) {
  3446. global $DB, $CFG, $USER;
  3447. $itemid = $param->file;
  3448. $pathtemp = $CFG->dataroot . '/temp/';
  3449. $contextuser = context_user::instance($USER->id);
  3450. $fs = get_file_storage();
  3451. $zip = new zip_packer();
  3452. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3453. $files_extract = null;
  3454. foreach ($files as $file) {
  3455. if (!$file->is_directory())
  3456. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3457. }
  3458. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3459. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  3460. $typec = strtolower($iassign_t->type);
  3461. require_once 'ilm_handlers/' . $typec . '.php';
  3462. $typec::copy_new_version_ilm($param, $files_extract);
  3463. }
  3464. //VER::
  3465. //Notice: Undefined variable: output_ilm in C:\Users\Igor\OneDrive\htdocs\moodleteste\moodle\mod\iassign\locallib.php on line 5054
  3466. // Notice: Trying to get property of non-object in C:\Users\Igor\OneDrive\htdocs\moodleteste\moodle\mod\iassign\locallib.php on line 192
  3467. //Notice: Trying to get property of non-object in C:\Users\Igor\OneDrive\htdocs\moodleteste\moodle\mod\iassign\locallib.php on line 194
  3468. /// Function for change visibility of iLM
  3469. // @param int $ilm_id Id of iLM
  3470. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  3471. static function visible_ilm ($ilm_id, $status) {
  3472. global $DB;
  3473. if ($status == 0)
  3474. $visible = 1;
  3475. else
  3476. $visible = 0;
  3477. $newentry = new stdClass();
  3478. $newentry->id = $ilm_id;
  3479. $newentry->enable = $visible;
  3480. if (!$DB->update_record("iassign_ilm", $newentry))
  3481. error(get_string('error_edit_ilm', 'iassign'));
  3482. }
  3483. /// Function for confirm change default iLM
  3484. // @param int $ilm_id Id of iLM
  3485. // @param int $ilm_parent Id of parent iLM
  3486. // @return string Return with an string for create default page confirmation
  3487. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  3488. global $OUTPUT, $DB;
  3489. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3490. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3491. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3492. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  3493. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  3494. return $return;
  3495. }
  3496. /// Function for change default iLM
  3497. // @param int $ilm_id Id of iLM
  3498. // @return int Return Id of default iLM
  3499. static function default_ilm ($ilm_id) {
  3500. global $DB;
  3501. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  3502. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  3503. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  3504. $iassign_ilm_default->id = $iassign_ilm->id;
  3505. $iassign_ilm_default->parent = 0;
  3506. $iassign_ilm->parent = $iassign_ilm_default->id;
  3507. $iassign_ilm->id = 0;
  3508. $iassign_ilm_default->enable = 1;
  3509. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default))
  3510. print_error('error_edit_ilm', 'iassign');
  3511. if (!$DB->insert_record("iassign_ilm", $iassign_ilm))
  3512. print_error('error_add_ilm', 'iassign');
  3513. return $iassign_ilm_default->id;
  3514. }
  3515. /// Function for confirm delete iLM
  3516. // @param int $ilm_id Id of iLM
  3517. // @param int $ilm_parent Id of parent iLM
  3518. // @return string Return with an string for create delete page confirmation
  3519. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  3520. global $OUTPUT, $DB;
  3521. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3522. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3523. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3524. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  3525. }
  3526. /// Function for delete directory where the iLM is allocated.
  3527. // @param string $dirPath
  3528. // @throws InvalidArgumentException
  3529. public static function delete_dir ($dirPath) {
  3530. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  3531. $dirPath .= '/';
  3532. }
  3533. $files = glob($dirPath . '*', GLOB_MARK);
  3534. foreach ($files as $file) {
  3535. if (is_dir($file)) {
  3536. ilm_settings::delete_dir($file);
  3537. } else {
  3538. unlink($file);
  3539. }
  3540. }
  3541. rmdir($dirPath);
  3542. }
  3543. /// Function for delete iLM
  3544. // @param int $ilm_id Id of iLM
  3545. // @return int Return Id of parent iLM
  3546. static function delete_ilm ($ilm_id) {
  3547. global $DB;
  3548. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3549. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3550. $typec = strtolower($iassign_ilm->type);
  3551. require_once 'ilm_handlers/' . $typec . '.php';
  3552. $retorno = $typec::delete_ilm($ilm_id);
  3553. return $retorno;
  3554. }
  3555. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  3556. // @param int $ilm_id Id of iLM
  3557. static function export_ilm ($ilm_id) {
  3558. global $DB;
  3559. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3560. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3561. $typec = strtolower($iassign_ilm->type);
  3562. require_once 'ilm_handlers/' . $typec . '.php';
  3563. $typec::export_ilm($ilm_id);
  3564. } // static function export_ilm($ilm_id)
  3565. //TODO iLM_HTML5 :: //MOOC 2016
  3566. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  3567. // @param int $ilm_id Id of iLM
  3568. static function export_update_ilm ($ilm_id) {
  3569. global $DB, $CFG;
  3570. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3571. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  3572. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  3573. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  3574. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  3575. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  3576. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  3577. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  3578. $upgrade_descriptor .= '</upgrade>' . "\n";
  3579. file_put_contents($xml_filename, $upgrade_descriptor);
  3580. header("Pragma: public");
  3581. header("Expires: 0");
  3582. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  3583. header("Cache-Control: private", false);
  3584. header('Content-Type: application/xml; charset=utf-8');
  3585. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  3586. header("Content-Length: " . @filesize($xml_filename));
  3587. set_time_limit(0);
  3588. @readfile("$xml_filename") || die("File not found.");
  3589. unlink($xml_filename);
  3590. exit;
  3591. } // static function export_update_ilm($ilm_id) //MOOC 2016
  3592. /// Function for save iLM from XML descriptor
  3593. // @param array $application_xml Data of XML descriptor
  3594. // @param array $files_extract Filenames of extract files
  3595. // @return array Return an array content id of JAR files
  3596. static function save_ilm_by_xml ($application_xml, $files_extract) {
  3597. global $CFG, $USER;
  3598. // Tratamento diferenciado se for do tipo HTML5:
  3599. $source = "";
  3600. $diretorio = "";
  3601. if (strtolower($application_xml->type) == 'html5') {
  3602. $i = 0;
  3603. foreach ($files_extract as $key => $value) {
  3604. $file = $CFG->dataroot . '/temp/' . $key;
  3605. // Verifica se já existe a pasta no diretório dos iLM:
  3606. if ($i == 0) {
  3607. $source = $file;
  3608. if (file_exists("ilm/" . basename($file))) {
  3609. $j = 1;
  3610. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  3611. $j ++;
  3612. }
  3613. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  3614. mkdir($diretorio, 0777, true);
  3615. } else {
  3616. $diretorio = 'ilm/' . basename($file);
  3617. mkdir($diretorio, 0777, true);
  3618. }
  3619. break;
  3620. }
  3621. $i ++;
  3622. }
  3623. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  3624. if ($item->isDir()) {
  3625. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  3626. } else {
  3627. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  3628. }
  3629. }
  3630. ilm_settings::delete_dir($source);
  3631. return "./" . $diretorio;
  3632. }
  3633. $fs = get_file_storage();
  3634. $file_jar = array();
  3635. $files_ilm = explode(",", $application_xml->file_jar);
  3636. $contextsystem = context_system::instance();
  3637. foreach ($files_ilm as $value) {
  3638. $file_ilm = array(
  3639. 'userid' => $USER->id,
  3640. 'contextid' => $contextsystem->id,
  3641. 'component' => 'mod_iassign',
  3642. 'filearea' => 'ilm',
  3643. 'itemid' => rand(1, 999999999),
  3644. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  3645. 'filename' => $value);
  3646. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  3647. array_push($file_jar, $file_ilm->get_id());
  3648. }
  3649. foreach ($files_extract as $key => $value) {
  3650. $file = $CFG->dataroot . '/temp/' . $key;
  3651. if (file_exists($file))
  3652. unlink($file);
  3653. }
  3654. return $file_jar;
  3655. }
  3656. /// Function for import the iLM from an package
  3657. // @param int $itemid Itemid of zip file
  3658. static function import_ilm ($itemid) {
  3659. global $CFG, $USER, $OUTPUT;
  3660. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3661. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3662. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3663. }
  3664. $pathtemp = $CFG->dataroot . '/temp/';
  3665. $contextuser = context_user::instance($USER->id);
  3666. $fs = get_file_storage();
  3667. $zip = new zip_packer();
  3668. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3669. foreach ($files as $file) {
  3670. if (!$file->is_directory())
  3671. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3672. }
  3673. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3674. // Verifica se o pacote possui o XML
  3675. if (!$application_xml) {
  3676. echo($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3677. return;
  3678. } else {
  3679. $missing = "";
  3680. if (!isset($application_xml->name)) {
  3681. $missing .= "name";
  3682. }
  3683. if (!isset($application_xml->version)) {
  3684. $missing .= ", version";
  3685. }
  3686. if (!isset($application_xml->type)) {
  3687. $missing .= ", type";
  3688. }
  3689. if (!isset($application_xml->extension)) {
  3690. $missing .= ", extension";
  3691. }
  3692. if (!isset($application_xml->file_jar)) {
  3693. $missing .= ", file_jar";
  3694. }
  3695. if (!isset($application_xml->file_class)) {
  3696. $missing .= ", file_class";
  3697. }
  3698. if (!isset($application_xml->width)) {
  3699. $missing .= ", width";
  3700. }
  3701. if (!isset($application_xml->height)) {
  3702. $missing .= ", height";
  3703. }
  3704. if (!isset($application_xml->evaluate)) {
  3705. $missing .= ", evaluate";
  3706. }
  3707. if (strlen($missing) > 2) {
  3708. echo($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3709. return;
  3710. }
  3711. }
  3712. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3713. $typec = strtolower($application_xml->type);
  3714. require_once 'ilm_handlers/' . $typec . '.php';
  3715. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3716. } // static function import_ilm($itemid)
  3717. /// Function for list iLM defaults
  3718. // @return string Return an string with a table of iLM
  3719. static function list_ilm () {
  3720. global $DB, $OUTPUT;
  3721. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  3722. $str = '';
  3723. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  3724. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  3725. if ($iassign_ilm) {
  3726. foreach ($iassign_ilm as $ilm) {
  3727. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  3728. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  3729. $str .= '<tr><td>';
  3730. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  3731. $str .= '<tr>';
  3732. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  3733. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  3734. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  3735. $str .= '</tr>';
  3736. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  3737. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  3738. $str .= '</table>';
  3739. $str .= '</td></tr>';
  3740. }
  3741. }
  3742. $str .= '</table>';
  3743. return $str;
  3744. }
  3745. /// Function for download and install an upgrade of an iLM
  3746. // @param int $ilm_id Id of iLM
  3747. static function upgrade_ilm ($ilm_id) {
  3748. global $DB, $CFG, $USER;
  3749. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3750. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  3751. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  3752. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  3753. if (!$result)
  3754. print_error('error_upgrade_ilm', 'iassign');
  3755. else {
  3756. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  3757. $extension = explode(".", $zip_filename);
  3758. if ($extension[count($extension) - 1] != 'ipz') {
  3759. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  3760. die;
  3761. }
  3762. $zip = new zip_packer();
  3763. $fs = get_file_storage();
  3764. $contextuser = context_user::instance($USER->id);
  3765. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  3766. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3767. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  3768. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  3769. if (file_exists($zip_filename))
  3770. unlink($zip_filename);
  3771. if (empty($file_jar))
  3772. print_error('error_add_ilm', 'iassign');
  3773. else {
  3774. $newentry = new stdClass();
  3775. $newentry->name = (String) $application_xml->name;
  3776. $newentry->version = (String) $application_xml->version;
  3777. $newentry->url = (String) $application_xml->url;
  3778. $newentry->description = $description_str;
  3779. $newentry->extension = strtolower((String) $application_xml->extension);
  3780. $newentry->file_jar = implode(",", $file_jar);
  3781. $newentry->file_class = (String) $application_xml->file_class;
  3782. $newentry->width = (String) $application_xml->width;
  3783. $newentry->height = (String) $application_xml->height;
  3784. $newentry->enable = 0;
  3785. $newentry->timemodified = time();
  3786. $newentry->author = $USER->id;
  3787. $newentry->timecreated = time();
  3788. $newentry->evaluate = (String) $application_xml->evaluate;
  3789. $newentry->parent = $ilm_id;
  3790. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  3791. }
  3792. }
  3793. return $iassign_ilm->id;
  3794. }
  3795. //MOOC2014 -- inicio
  3796. //TODO: REVIEW
  3797. // static function confirm_move_iassign($ilmid, $ilm_parent)
  3798. // static function move_iassign($ilm_id)
  3799. //MOOC2014 -- final
  3800. /// Function for list iLM versions with all informations
  3801. // @return string Return an string with a table of iLM
  3802. static function view_ilm ($ilmid, $from) {
  3803. global $DB;
  3804. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  3805. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3806. $typec = strtolower($iassign_ilm->type);
  3807. require_once 'ilm_handlers/' . $typec . '.php';
  3808. $retorno = $typec::view_ilm($ilmid, $from);
  3809. return $retorno;
  3810. }
  3811. /// Function for get form variables for add, edit, or copy iLM params
  3812. // @param int $ilm_param_id Id of iLM param
  3813. // @param string $action String with the action
  3814. // @return object Return an object with forms variables
  3815. static function add_edit_copy_param ($ilm_param_id, $action) {
  3816. global $DB;
  3817. require_once('params_form.php');
  3818. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  3819. $param = new stdClass();
  3820. $param->action = $action;
  3821. $param->ilm_param_id = $ilm_param_id;
  3822. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  3823. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  3824. $type = $iassign_ilm_config->param_type;
  3825. if ($action == 'add') {
  3826. $param->title = get_string('add_ilm', 'iassign');
  3827. $param->iassign_ilmid = $ilm_param_id;
  3828. $param->param_name = "";
  3829. $param->param_value = "";
  3830. $param->description = "";
  3831. $param->visible = 1;
  3832. } elseif ($action == 'edit') {
  3833. if ($iassign_ilm_config) {
  3834. $param->title = get_string('edit_ilm', 'iassign');
  3835. $param->id = $iassign_ilm_config->id;
  3836. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  3837. $param->param_type = $type; //MOOC2014
  3838. $param->param_name = $iassign_ilm_config->param_name;
  3839. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  3840. $param->param_value = $iassign_ilm_config->param_value;
  3841. else //MOOC2014
  3842. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  3843. $param->param_value = $iassign_ilm_config->param_value;
  3844. $param->description = $iassign_ilm_config->description;
  3845. $param->visible = $iassign_ilm_config->visible;
  3846. }
  3847. } elseif ($action == 'copy') {
  3848. if ($iassign_ilm_config) {
  3849. $param->title = get_string('copy_ilm', 'iassign');
  3850. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  3851. $param->param_type = $type; //MOOC2014
  3852. $param->param_name = $iassign_ilm_config->param_name;
  3853. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  3854. $param->param_value = $iassign_ilm_config->param_value;
  3855. else //MOOC2014
  3856. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  3857. $param->description = $iassign_ilm_config->description;
  3858. $param->visible = $iassign_ilm_config->visible;
  3859. }
  3860. }
  3861. return $param;
  3862. } // static function add_edit_copy_param($ilm_param_id, $action)
  3863. /// Function for change visibility of iLM param
  3864. // @param int $ilm_param_id Id of iLM param
  3865. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  3866. static function visible_param ($ilm_param_id, $status) {
  3867. global $DB, $CFG;
  3868. if ($status == 0)
  3869. $visible = 1;
  3870. else
  3871. $visible = 0;
  3872. $newentry = new stdClass();
  3873. $newentry->id = $ilm_param_id;
  3874. $newentry->visible = $visible;
  3875. if (!$DB->update_record("iassign_ilm_config", $newentry))
  3876. error(get_string('error_edit_param', 'iassign'));
  3877. }
  3878. /// Function for save in database an new iLM param
  3879. // @param object $param An object with iLM params
  3880. static function add_param ($param) {
  3881. global $DB;
  3882. $newentry = new stdClass();
  3883. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3884. //MOOC2014 $newentry->param_name = $param->param_name;
  3885. $newentry->param_type = $param->param_type; //MOOC2014
  3886. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  3887. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  3888. $newentry->param_value = $param->param_value;
  3889. else //MOOC2014
  3890. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  3891. $newentry->description = $param->description;
  3892. $newentry->visible = $param->visible;
  3893. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  3894. if (!$newentry->id) {
  3895. print_error('error_add_param', 'iassign');
  3896. }
  3897. }
  3898. /// Function for save in database a iLM param edit
  3899. // @param object $param An object with iLM params
  3900. static function edit_param($param) {
  3901. global $DB;
  3902. $updentry = new stdClass();
  3903. $updentry->id = $param->id;
  3904. $updentry->iassign_ilmid = $param->iassign_ilmid;
  3905. $updentry->param_type = $param->param_type; //MOOC2014
  3906. // $updentry->param_name = $param->param_name;
  3907. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  3908. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  3909. $updentry->param_value = $param->param_value;
  3910. else //MOOC2014
  3911. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  3912. $updentry->description = $param->description;
  3913. $updentry->visible = $param->visible;
  3914. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  3915. error(get_string('error_edit_param', 'iassign'));
  3916. }
  3917. }
  3918. /// Function for save in database a iLM param copy
  3919. // @param object $param An object with iLM params
  3920. static function copy_param ($param) {
  3921. global $DB;
  3922. $newentry = new stdClass();
  3923. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3924. //$newentry->param_name = $param->param_name;
  3925. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  3926. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  3927. $newentry->param_value = $param->param_value;
  3928. else //MOOC2014
  3929. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  3930. $newentry->description = $param->description;
  3931. $newentry->visible = $param->visible;
  3932. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  3933. if (!$newentry->id) {
  3934. print_error('error_add_param', 'iassign');
  3935. }
  3936. }
  3937. /// Function for delete iLM param of database
  3938. // @param int $param_id Id of iLM param
  3939. static function delete_param ($param_id) {
  3940. global $DB;
  3941. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  3942. print_error('error_delete_param', 'iassign');
  3943. }
  3944. }
  3945. } // class ilm_settings
  3946. /// Class for manage iLM files (editor).
  3947. class ilm_manager {
  3948. var $id; // course id
  3949. var $url;
  3950. var $from;
  3951. /// Constructor for the base ilm_manager class
  3952. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3953. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  3954. function __construct ($id, $url, $from) {
  3955. $this->id = $id; // course id
  3956. $this->url = $url;
  3957. $this->from = $from;
  3958. }
  3959. /// Function to get iAssign content file in Moodle data (exercise)
  3960. // @calledby x function preview_ilm($iassign_ilm) :
  3961. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  3962. function get_file_ilm () {
  3963. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  3964. $fileid = optional_param('fileid', NULL, PARAM_INT);
  3965. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  3966. $fs = get_file_storage();
  3967. $md_file = $fs->get_file_by_id($fileid);
  3968. $ilm_content_file = $md_file->get_content();
  3969. return $ilm_content_file;
  3970. }
  3971. /// Function for creating an new file in online editor
  3972. function ilm_editor_new () {
  3973. global $CFG, $DB, $OUTPUT, $PAGE;
  3974. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  3975. $dirid = optional_param('dirid', NULL, PARAM_INT);
  3976. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  3977. $context = context_course::instance($this->id);
  3978. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=$this->from&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  3979. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  3980. if (!$iassign) {
  3981. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  3982. die();
  3983. }
  3984. $temp = explode(",", $iassign->extension);
  3985. $extension = $temp[0]; // default extension for this iLM
  3986. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  3987. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  3988. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  3989. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  3990. if ($stringArchiveContent != NULL) {
  3991. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  3992. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  3993. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  3994. $filename = optional_param('filename', NULL, PARAM_RAW);
  3995. $filename = iassign_utils::format_filename($filename);
  3996. $arrayfilename = explode(".", $filename);
  3997. // if (count ( $arrayfilename ) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  3998. $count_dots = count($arrayfilename);
  3999. if ($count_dots > 0) { // at least one dot mark
  4000. $last_name = $arrayfilename[$count_dots - 1];
  4001. if ($last_name != $extension)
  4002. $filename = $filename . '.' . $extension;
  4003. }
  4004. else { // no extension...
  4005. $filename = $filename . '.' . $extension;
  4006. }
  4007. //$this->write_file_iassign ($string, $filename);
  4008. $this->write_file_iassign($stringArchiveContent, $filename);
  4009. die();
  4010. } else { // if ($stringArchiveContent != NULL)
  4011. // iLM On-line editor
  4012. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4013. $str_get_iLM = "window.frames.iLM";
  4014. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4015. } else { // otherwise it is JAR named 'iLM'
  4016. $str_get_iLM = "document.iLM";
  4017. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4018. }
  4019. $fs = get_file_storage();
  4020. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4021. $files_array = '';
  4022. foreach ($files as $value) {
  4023. if ($value->get_filename() != ".")
  4024. $files_array .= "'" . $value->get_filename() . "',";
  4025. }
  4026. $files_array .= "''";
  4027. $file = null;
  4028. $ia_content = "";
  4029. $filename = "";
  4030. $error_files_exists = get_string('error_file_exists', 'iassign');
  4031. $output = "<script type='text/javascript'>
  4032. //<![CDATA[
  4033. //D alert('locallib.php: ilm_editor_new');
  4034. function submit_iLM_Answer () {
  4035. var docFormOnLineEditor = document.formEnvio;
  4036. var resposta_exerc = new Array(3);
  4037. var valor_resposta = new Array(3);
  4038. var sessao = new Array(3);
  4039. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4040. resposta_exerc[0] = doc_iLM.getAnswer();
  4041. valor_resposta[0] = doc_iLM.getEvaluation();
  4042. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4043. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4044. var files = new Array(" . $files_array . ");
  4045. var filename=docFormOnLineEditor.filename.value+'.'+'$extension';
  4046. " .
  4047. //D alert('#files = ' + files.length);
  4048. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4049. // if (resposta_exerc[0] == -1) {
  4050. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4051. // return false;
  4052. // } else {
  4053. "
  4054. if (docFormOnLineEditor.filename.value=='') {
  4055. // ERRO: O nome do arquivo está vazio.
  4056. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4057. return false;
  4058. }
  4059. // }
  4060. for (i=0; i<files.length; i++) {
  4061. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4062. alert('" . $error_files_exists . "');
  4063. return false;
  4064. }
  4065. }
  4066. docFormOnLineEditor.submit();
  4067. return true;
  4068. }
  4069. //]]>
  4070. </script>\n";
  4071. $output .= "
  4072. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4073. $output .= $OUTPUT->box_start();
  4074. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4075. $output .= "
  4076. <table width='100%' cellpadding='20'>
  4077. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4078. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4079. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4080. </tr>
  4081. </table>\n";
  4082. $output .= $OUTPUT->box_end();
  4083. $output .= "<center>\n";
  4084. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4085. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4086. $output_ilm .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4087. $output .= $output_ilm;
  4088. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4089. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4090. </center>
  4091. </form>\n";
  4092. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4093. $PAGE->navbar->add($title);
  4094. $PAGE->set_title($title);
  4095. $PAGE->set_heading($title); // insert title above the navigation bar
  4096. print $OUTPUT->header();
  4097. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4098. print $output;
  4099. print $OUTPUT->footer();
  4100. }
  4101. die();
  4102. } // function ilm_editor_new()
  4103. /// Function for editing an file in online editor
  4104. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  4105. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  4106. global $CFG, $DB, $OUTPUT, $PAGE;
  4107. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4108. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4109. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4110. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4111. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=$this->from&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4112. // If iLM is not registered, error!
  4113. if (!$iassign) {
  4114. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  4115. die;
  4116. }
  4117. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  4118. //2017/03/12 $fs = get_file_storage(); // from Moodle data
  4119. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  4120. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  4121. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4122. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4123. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  4124. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  4125. if ($stringArchiveContent != NULL) {
  4126. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  4127. die();
  4128. } else { // if ($stringArchiveContent != NULL)
  4129. $end_file = '';
  4130. if ($content_file) {
  4131. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  4132. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  4133. }
  4134. $temp = explode(",", $iassign->extension);
  4135. $extension = $temp[0]; // default extension for this iLM
  4136. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  4137. $str_get_iLM = "window.frames.iLM";
  4138. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4139. } else { // otherwise it is JAR named 'iLM'
  4140. $str_get_iLM = "document.iLM";
  4141. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4142. }
  4143. $output = "<script type='text/javascript'>
  4144. //<![CDATA[
  4145. function submit_iLM_Answer () {
  4146. var docFormEditor = document.formEnvio;
  4147. var activityAnswer; // to get activity answer (text)
  4148. var activityValue; // to get activity answer value (float)
  4149. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4150. //alert('locallib.php: ilm_editor_update: submit_iLM_Answer(): ' + doc_iLM);
  4151. //activityAnswer = doc_iLM.getAnswer();
  4152. //activityValue = doc_iLM.getEvaluation();
  4153. activityAnswer = " . $str_get_iLM . ".getAnswer();
  4154. activityValue = " . $str_get_iLM . ".getEvaluation();
  4155. //alert('locallib.php: ilm_editor_update: submit_iLM_Answer(): ' + activityAnswer);
  4156. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  4157. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  4158. alert('locallib.php: ilm_editor_update: submit_iLM_Answer(): ' + activityAnswer);
  4159. docFormEditor.submit();
  4160. return true;
  4161. }
  4162. //]]>
  4163. </script>\n";
  4164. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4165. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  4166. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4167. // return true;
  4168. // }
  4169. $output .= "
  4170. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4171. $output .= $OUTPUT->box_start();
  4172. $output .= "
  4173. <table width='100%' cellpadding='20'>
  4174. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  4175. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  4176. <input type='hidden' name='filename' value='$filename'/></td>
  4177. <td>
  4178. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4179. </tr>
  4180. </table>\n";
  4181. $output .= $OUTPUT->box_end();
  4182. $output .= " <center>\n";
  4183. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  4184. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  4185. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  4186. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  4187. </center>
  4188. </form>\n";
  4189. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4190. $PAGE->navbar->add($title);
  4191. $PAGE->set_title($title);
  4192. $PAGE->set_heading($title); // insert title above the navigation bar
  4193. print $OUTPUT->header();
  4194. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4195. print $output;
  4196. print $OUTPUT->footer();
  4197. } // else if ($stringArchiveContent != NULL)
  4198. die();
  4199. } // function ilm_editor_update()
  4200. /// Function for write iAssign file in Moodle data (exercise)
  4201. // @param string $stringArchiveContent Content of iassign file
  4202. // @param string $filename Filename of iassign file
  4203. function write_file_iassign ($stringArchiveContent, $filename) {
  4204. global $USER;
  4205. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4206. $context = context_course::instance($this->id);
  4207. $fs = get_file_storage();
  4208. $dirid = $this->get_dir_ilm('dirid');
  4209. $dir = $fs->get_file_by_id($dirid);
  4210. $fileinfo = array('contextid' => $context->id, // ID of course
  4211. 'component' => 'mod_iassign', // usually = table name
  4212. 'filearea' => 'activity', // usually = table name
  4213. 'itemid' => 0, // usually = ID of row in table
  4214. 'filepath' => $dir->get_filepath(), // any path beginning and ending whith '/'
  4215. 'userid' => $USER->id,
  4216. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4217. 'filename' => $filename); // any filename
  4218. // Create file containing text. '$stringArchiveContent'
  4219. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  4220. $output = "
  4221. <script type='text/javascript'>
  4222. //<![CDATA[
  4223. alert('" . get_string('sucess_write', 'iassign') . "');\n
  4224. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4225. //]]>
  4226. </script>";
  4227. print $output;
  4228. die();
  4229. }
  4230. /// Function for write iAssign file in Moodle data (exercise)
  4231. // @param string $stringArchiveContent Content of iassign file
  4232. // @param string $filename Filename of iassign file
  4233. // @param int $itemid Itemid of iassign file
  4234. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  4235. global $OUTPUT, $USER;
  4236. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4237. $context = context_course::instance($this->id);
  4238. $dirid = $this->get_dir_ilm('dirid');
  4239. if ($stringArchiveContent != (-1)) {
  4240. $fs = get_file_storage();
  4241. $file = $fs->get_file_by_id($fileid);
  4242. if (!$file) {
  4243. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  4244. die;
  4245. }
  4246. $fileinfo = array('contextid' => $context->id, // ID of context
  4247. 'component' => 'mod_iassign', // usually = table name
  4248. 'filearea' => 'activity', // usually = table name
  4249. 'itemid' => 0, // usually = ID of row in table
  4250. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  4251. 'userid' => $USER->id,
  4252. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4253. 'license' => 'allrightsreserved', // allrightsreserved
  4254. 'timecreated' => $file->get_timecreated(),
  4255. 'filename' => $file->get_filename()); // any filename
  4256. $file->delete();
  4257. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  4258. }
  4259. $output = "<script type='text/javascript'>
  4260. //<![CDATA[
  4261. alert('" . get_string('sucess_update', 'iassign') . "');\n
  4262. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4263. //]]>
  4264. </script>";
  4265. print $output;
  4266. die();
  4267. }
  4268. /// Function for create an tag for iAssign filter
  4269. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  4270. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4271. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  4272. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4273. // @param int $fileid Id of file
  4274. // @return string Return an string with an tag of iassign filter
  4275. function tag_ilm ($fileid) {
  4276. global $DB;
  4277. $fs = get_file_storage();
  4278. $width = '600';
  4279. $height = '400';
  4280. $file = $fs->get_file_by_id($fileid);
  4281. $filetype = explode(".", $file->get_filename());
  4282. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  4283. foreach ($iassign_ilm as $value) {
  4284. $extensions = explode(",", $value->extension);
  4285. if (in_array($filetype[1], $extensions)) {
  4286. $width = $value->width;
  4287. $height = $value->height;
  4288. }
  4289. }
  4290. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  4291. }
  4292. /// Function for delete iAssign file in Moodle data (exercise)
  4293. function delete_file_ilm () {
  4294. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4295. $fs = get_file_storage();
  4296. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  4297. $file = $fs->get_file_by_id($fileid);
  4298. if ($file)
  4299. $file->delete();
  4300. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4301. die();
  4302. }
  4303. /// Function for delete selected iAssign file in Moodle data (exercise)
  4304. function delete_selected_ilm () {
  4305. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4306. $fs = get_file_storage();
  4307. $context = context_course::instance($this->id);
  4308. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4309. $dirid = $this->get_dir_ilm('dirid');
  4310. foreach ($files_id as $file_id) {
  4311. $file = $fs->get_file_by_id($file_id);
  4312. if ($file) {
  4313. if (!$file->is_directory())
  4314. $file->delete();
  4315. else {
  4316. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4317. foreach ($files_delete as $value)
  4318. $value->delete();
  4319. $file->delete();
  4320. }
  4321. }
  4322. }
  4323. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4324. die();
  4325. }
  4326. /// Function for duplicate iAssign file from "online" edition
  4327. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  4328. function duplicate_file_ilm() {
  4329. global $USER, $COURSE;
  4330. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4331. $fs = get_file_storage();
  4332. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4333. $filename = optional_param('filename', NULL, PARAM_RAW);
  4334. $file = $fs->get_file_by_id($fileid);
  4335. $context = context_course::instance($this->id);
  4336. $fileinfo = array(
  4337. 'contextid' => $context->id, // ID of context
  4338. 'component' => 'mod_iassign', // usually = table name
  4339. 'filearea' => 'activity', // usually = table name
  4340. 'itemid' => 0, // usually = ID of row in table
  4341. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  4342. 'userid' => $USER->id,
  4343. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4344. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  4345. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  4346. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  4347. die();
  4348. }
  4349. /// Function for rename iAssign file
  4350. function rename_file_ilm () {
  4351. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4352. $fs = get_file_storage();
  4353. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4354. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4355. $file = $fs->get_file_by_id($fileid);
  4356. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  4357. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  4358. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4359. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  4360. die();
  4361. }
  4362. /// Function for get iassign file for iassign form
  4363. function add_ilm () {
  4364. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4365. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4366. $output = "
  4367. <script type='text/javascript'>
  4368. //<![CDATA[
  4369. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  4370. iassign_file_link.innerHTML = '$filename';
  4371. window.opener.document.forms['mform1'].file.value='$fileid';
  4372. window.opener.document.forms['mform1'].filename.value='$filename';
  4373. window.close();
  4374. //]]>
  4375. </script>";
  4376. print $output;
  4377. die();
  4378. }
  4379. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  4380. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  4381. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  4382. function preview_ilm ($courseid, $iassign_ilm) {
  4383. global $OUTPUT, $CFG, $USER;
  4384. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4385. $title = get_string('modulename', 'iassign'); // iAssign
  4386. print $OUTPUT->header();
  4387. print $OUTPUT->box_start();
  4388. $javascript = "
  4389. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  4390. <script type='text/javascript'>
  4391. //<![CDATA[
  4392. function submit_close () {
  4393. window.opener.location.reload();
  4394. window.close();
  4395. }
  4396. //]]>
  4397. </script>\n";
  4398. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  4399. // to the complete "applet" tag
  4400. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  4401. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  4402. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  4403. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  4404. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  4405. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  4406. if ($ilm_name != "ivprog") {
  4407. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  4408. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  4409. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  4410. } else {
  4411. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  4412. $content_or_id_from_ilm_security = $this->get_file_ilm();
  4413. $timecreated = time();
  4414. $token = md5($timecreated);
  4415. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  4416. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  4417. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  4418. $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)
  4419. }
  4420. $html = "
  4421. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4422. <table border='1'>
  4423. <tr><td>
  4424. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  4425. <!-- iLM calls : end -->
  4426. </td></tr>
  4427. </table>
  4428. <table>
  4429. <tr>
  4430. <td align='center'>
  4431. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  4432. </td></tr>
  4433. </table>
  4434. </form>\n";
  4435. print $javascript . $html;
  4436. print $OUTPUT->box_end();
  4437. //NAO echo format_string($html); // Moodle 3.X
  4438. die();
  4439. }
  4440. // function preview_ilm($iassign_ilm)
  4441. //r_ /// Function for preview iassign file from iassign filter.
  4442. //r_ function preview_ilm() {
  4443. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4444. //r_ $tag_filter = $this->tag_ilm($fileid);
  4445. //r_ $javascript = "<script type='text/javascript'>
  4446. //r_ //<![CDATA[
  4447. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  4448. //r_ //]]>
  4449. //r_ </script>";
  4450. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4451. //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>
  4452. //r_ </table></form></body></html>";
  4453. //r_ echo $javascript . format_text($html);
  4454. //r_ die;
  4455. //r_ }
  4456. /// Function for export an package (zip) of iassign files
  4457. function export_files_ilm () {
  4458. global $CFG;
  4459. $context = context_course::instance($this->id);
  4460. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4461. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  4462. $zip = new zip_archive();
  4463. $zip->open($zip_filename);
  4464. $fs = get_file_storage();
  4465. foreach ($files_id as $file_id) {
  4466. $file = $fs->get_file_by_id($file_id);
  4467. if (!$file->is_directory())
  4468. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  4469. else {
  4470. $zip->add_directory($file->get_filepath());
  4471. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4472. foreach ($files_zip as $value) {
  4473. if (!$value->is_directory())
  4474. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  4475. else
  4476. $zip->add_directory($value->get_filepath());
  4477. }
  4478. }
  4479. }
  4480. $zip->close();
  4481. header("Pragma: public");
  4482. header("Expires: 0");
  4483. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4484. header("Cache-Control: private", false);
  4485. header("Content-Type: application/zip");
  4486. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  4487. header("Content-Transfer-Encoding: binary");
  4488. header("Content-Length: " . @filesize($zip_filename));
  4489. set_time_limit(0);
  4490. @readfile("$zip_filename") || die("File not found.");
  4491. unlink($zip_filename);
  4492. exit;
  4493. }
  4494. /// Function of execute a command in button editor tinymce
  4495. // @param int $fileid Id of file
  4496. function tinymce_ilm ($fileid) {
  4497. $tag_filter = $this->tag_ilm($fileid);
  4498. $output = "<script type='text/javascript'>
  4499. //<![CDATA[
  4500. var tag_filter = '$tag_filter';
  4501. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  4502. // all right, insert it
  4503. } else {
  4504. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  4505. }
  4506. // window.close();
  4507. //]]>
  4508. </script>\n";
  4509. print $output;
  4510. die();
  4511. }
  4512. //D sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  4513. /// Function to add content to the Editor Window
  4514. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  4515. // @param int $fileid Id of file
  4516. function editor_ilm ($fileid, $editor) {
  4517. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  4518. $output1 = "<script type='text/javascript'>
  4519. //<![CDATA[
  4520. var tag_filter = '$tag_filter';\n";
  4521. if ($editor == 'atto') {
  4522. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  4523. } elseif ($editor == 'tinyMCE') {
  4524. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  4525. } else
  4526. $output2 = "";
  4527. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  4528. window.close();
  4529. //]]>
  4530. </script>\n";
  4531. //D var_dump($output);
  4532. print $output1 . $output2 . $output3;
  4533. die();
  4534. }
  4535. /// Function to add content to the Atto Editor Window
  4536. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  4537. // @param int $fileid Id of file
  4538. function atto_ilm($fileid) {
  4539. global $CFG, $DB;
  4540. $tag_filter = $this->tag_ilm($fileid);
  4541. $output = "<script type='text/javascript'>
  4542. //<![CDATA[
  4543. var tag_filter = '$tag_filter';
  4544. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  4545. // all right, insert iLM tag to this editor
  4546. } else {
  4547. // error trying to insert
  4548. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  4549. }
  4550. //window.close();
  4551. //]]>
  4552. </script>\n";
  4553. print $output;
  4554. die();
  4555. }
  4556. /// Function for get path and infos of dirs: dirid, dir_base, dir_parent, dir_home
  4557. // @param string $key Key for return information
  4558. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  4559. function get_dir_ilm ($key) {
  4560. $fs = get_file_storage();
  4561. $context = context_course::instance($this->id);
  4562. $dirid = optional_param('dirid', 0, PARAM_INT);
  4563. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  4564. if ($dirid == 0) {
  4565. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  4566. $dirid = $dir->get_id();
  4567. } else {
  4568. $dir = $fs->get_file_by_id($dirid);
  4569. $dir_base = $dir->get_filepath();
  4570. }
  4571. $dir_parent = $dir->get_parent_directory();
  4572. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  4573. return $data[$key];
  4574. }
  4575. /// Function for create an new dir
  4576. function new_dir_ilm () {
  4577. global $USER;
  4578. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4579. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  4580. $dir_base = $this->get_dir_ilm('dir_base');
  4581. $context = context_course::instance($this->id);
  4582. $fs = get_file_storage();
  4583. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  4584. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  4585. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  4586. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4587. }
  4588. /// Function for delete an dir
  4589. function delete_dir_ilm () { //
  4590. $fs = get_file_storage();
  4591. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4592. $context = context_course::instance($this->id);
  4593. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  4594. $dir_parent = $this->get_dir_ilm('dir_parent');
  4595. if ($dir) {
  4596. if ($dir->is_directory()) {
  4597. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  4598. foreach ($files_delete as $value)
  4599. $value->delete();
  4600. $dir->delete();
  4601. }
  4602. }
  4603. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  4604. die();
  4605. }
  4606. /// Function for rename an dir
  4607. function rename_dir_ilm () {
  4608. $fs = get_file_storage();
  4609. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4610. $context = context_course::instance($this->id);
  4611. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  4612. $dir_parent = $this->get_dir_ilm('dir_parent');
  4613. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  4614. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  4615. if ($dir->is_directory()) {
  4616. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  4617. foreach ($files_rename_path as $value)
  4618. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  4619. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  4620. }
  4621. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  4622. die();
  4623. }
  4624. /// Function for move an dir and your content for other dir
  4625. function selected_move_ilm() {
  4626. global $PAGE, $OUTPUT, $CFG;
  4627. $fs = get_file_storage();
  4628. $context = context_course::instance($this->id);
  4629. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4630. $dirid = $this->get_dir_ilm('dirid');
  4631. $dir_base = $this->get_dir_ilm('dir_base');
  4632. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4633. $code_javascript_ilm = "
  4634. <script type='text/javascript'>
  4635. //<![CDATA[
  4636. function getRadiobutton () {
  4637. var radioButtons = document.getElementsByTagName('input');
  4638. var param = '';
  4639. for (var counter=0; counter < radioButtons.length; counter++) {
  4640. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  4641. param = radioButtons[counter].value;
  4642. }
  4643. return param;
  4644. }
  4645. function move_selected_ilm () {
  4646. var msgAnswer;
  4647. if (getRadiobutton() != '') {
  4648. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  4649. if (msgAnswer)
  4650. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  4651. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  4652. }
  4653. else
  4654. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  4655. }
  4656. function cancel_selected_ilm () {
  4657. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  4658. }
  4659. //]]>
  4660. </script>\n";
  4661. $title = get_string('move_files', 'iassign');
  4662. $PAGE->set_title($title);
  4663. $PAGE->set_pagelayout('base');
  4664. print $OUTPUT->header();
  4665. print $OUTPUT->heading($title);
  4666. $dir_paths = array();
  4667. print $OUTPUT->box_start();
  4668. print "<center>";
  4669. foreach ($files_id as $file_id) {
  4670. $file = $fs->get_file_by_id($file_id);
  4671. if ($file) {
  4672. if (!$file->is_directory())
  4673. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  4674. else {
  4675. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  4676. array_push($dir_paths, $file->get_filepath());
  4677. }
  4678. }
  4679. }
  4680. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  4681. if ($dir_base != '/') {
  4682. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  4683. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  4684. }
  4685. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  4686. foreach ($files_tree as $file) {
  4687. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  4688. $is_parent = false;
  4689. foreach ($dir_paths as $dir) {
  4690. $path = explode("/", $dir);
  4691. array_pop($path);
  4692. $path[count($path) - 1] = '';
  4693. $path = implode("/", $path);
  4694. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  4695. $is_parent |= ($file->get_filepath() != $path ? false : true);
  4696. }
  4697. if ($is_parent == false) {
  4698. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  4699. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  4700. }
  4701. }
  4702. }
  4703. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  4704. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  4705. print "</center>";
  4706. print $OUTPUT->box_end();
  4707. print $OUTPUT->footer();
  4708. print $code_javascript_ilm;
  4709. die;
  4710. }
  4711. /// Function for move files for an dir
  4712. function move_files_ilm () {
  4713. $fs = get_file_storage();
  4714. $context = context_course::instance($this->id);
  4715. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4716. $dirid = $this->get_dir_ilm('dirid');
  4717. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  4718. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4719. foreach ($files_id as $file_id) {
  4720. $file = $fs->get_file_by_id($file_id);
  4721. if ($file) {
  4722. if ($file->is_directory()) {
  4723. $pathname = explode("/", $file->get_filepath());
  4724. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4725. foreach ($files_move_path as $value) {
  4726. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  4727. $value->rename($path_move, $value->get_filename());
  4728. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  4729. }
  4730. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  4731. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  4732. $file->rename($path_move, $file->get_filename());
  4733. } else {
  4734. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  4735. $file->rename($dir_move->get_filepath(), $file->get_filename());
  4736. }
  4737. }
  4738. }
  4739. //die;
  4740. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  4741. die();
  4742. } // function move_files_ilm()
  4743. /// Function for recover files in use on all activities of a course
  4744. function recover_files_ilm() {
  4745. global $DB, $USER;
  4746. $fs = get_file_storage();
  4747. $courseid = optional_param('id', NULL, PARAM_INT);
  4748. $dirid = $this->get_dir_ilm('dirid');
  4749. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4750. $contextfile = context_course::instance($this->id);
  4751. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  4752. foreach ($iassigns as $iassign) {
  4753. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  4754. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  4755. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  4756. $context = context_module::instance($cm->id);
  4757. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  4758. if ($files) {
  4759. foreach ($files as $value) {
  4760. $extension = explode(".", $value->get_filename());
  4761. if (!$value->is_directory()) {
  4762. $fileinfo = array('contextid' => $contextfile->id,
  4763. 'component' => 'mod_iassign',
  4764. 'filearea' => 'activity',
  4765. 'itemid' => 0,
  4766. 'filepath' => $this->get_dir_ilm('dir_base'),
  4767. 'userid' => $USER->id,
  4768. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4769. 'license' => 'allrightsreserved',
  4770. 'timecreated' => time(),
  4771. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  4772. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  4773. }
  4774. }
  4775. } // if ($files)
  4776. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  4777. } // foreach ($iassigns as $iassign)
  4778. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4779. die();
  4780. } // function recover_files_ilm()
  4781. /// List iassign files from course directory
  4782. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  4783. function view_files_ilm($iassign_ilm_class, $extension) {
  4784. global $CFG, $DB, $USER, $OUTPUT;
  4785. $fs = get_file_storage();
  4786. $context = context_course::instance($this->id);
  4787. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4788. $dirid = $this->get_dir_ilm('dirid');
  4789. $dir_base = $this->get_dir_ilm('dir_base');
  4790. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  4791. $files_array = '';
  4792. foreach ($files_course as $value) {
  4793. if (!$value->is_directory())
  4794. $files_array .= "'" . $value->get_filename() . "',";
  4795. }
  4796. $files_array .= "''";
  4797. $error_files_exists = get_string('error_file_exists', 'iassign');
  4798. $dirs_array = '';
  4799. foreach ($files_course as $value) {
  4800. if ($value->is_directory()) {
  4801. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  4802. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  4803. }
  4804. }
  4805. $dirs_array .= "''";
  4806. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  4807. // TODO Rever o preview pois só deixar ver uma vez.
  4808. $code_javascript_ilm = "
  4809. <script type='text/javascript'>
  4810. //<![CDATA[
  4811. function preview_ilm (fileid, ilmid) {
  4812. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  4813. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  4814. }
  4815. function update_ilm (ilmid, fileid) {
  4816. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  4817. }
  4818. function delete_ilm (ilmid, fileid) {
  4819. var msgAnswer;
  4820. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  4821. if (msgAnswer) {
  4822. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  4823. }
  4824. }
  4825. function delete_selected_ilm () {
  4826. var msgAnswer;
  4827. var param = getCheckbox();
  4828. if (param.join() != '') {
  4829. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  4830. if (msgAnswer)
  4831. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  4832. }
  4833. else
  4834. alert('" . get_string('error_file_not_selected_to_delete', 'iassign') . "');
  4835. }
  4836. function add_ilm_iassign (ilmid, filename, fileid) {
  4837. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  4838. }
  4839. function duplicate_ilm (ilmid, filename, fileid) {
  4840. var filenamecopy;
  4841. var i;
  4842. var files = new Array($files_array);
  4843. do {
  4844. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  4845. } while (filenamecopy == '');
  4846. if (filenamecopy == null)
  4847. return false;\n
  4848. else {
  4849. for (i=0;i<files.length;i++) {
  4850. if (files[i]==filenamecopy) {
  4851. alert('$error_files_exists');
  4852. return false;\n
  4853. }
  4854. }\n" .
  4855. // @see: function 'duplicate_file_ilm()' above
  4856. "
  4857. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  4858. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  4859. } // else
  4860. }
  4861. function rename_ilm (ilmid, filename, fileid) {
  4862. var filenamecopy;
  4863. var i;
  4864. var files = new Array($files_array);
  4865. do {
  4866. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  4867. } while (filenamecopy == '');
  4868. if (filenamecopy == null)
  4869. return false;
  4870. else {
  4871. for (i=0;i<files.length;i++) {
  4872. if (files[i]==filenamecopy) {
  4873. alert('$error_files_exists');
  4874. return false;
  4875. }
  4876. }
  4877. 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;
  4878. }
  4879. }
  4880. function export_files_ilm () {
  4881. var param = getCheckbox();
  4882. if (param.join() != '')
  4883. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  4884. else
  4885. alert('" . get_string('error_file_not_selected_to_export', 'iassign') . "');
  4886. }
  4887. function select_all_ilm () {
  4888. var checkBoxes = document.getElementsByTagName('input');
  4889. var selectAll = document.getElementById('select_all');
  4890. for (var counter=0; counter < checkBoxes.length; counter++) {
  4891. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  4892. checkBoxes[counter].checked = selectAll.checked;
  4893. }
  4894. }
  4895. function getCheckbox () {
  4896. var checkBoxes = document.getElementsByTagName('input');
  4897. var param = new Array();
  4898. for (var counter=0; counter < checkBoxes.length; counter++) {
  4899. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  4900. param.push(checkBoxes[counter].value);
  4901. }
  4902. return param;
  4903. }
  4904. function new_dir_ilm () {
  4905. var dirname = '';
  4906. var i;
  4907. var dirs = new Array($dirs_array);
  4908. do {
  4909. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  4910. } while (dirname == '');
  4911. if (dirname == null)
  4912. return false;\n
  4913. else {
  4914. for (i=0;i<dirs.length;i++) {
  4915. if (dirs[i]==dirname) {
  4916. alert('$error_dir_exists');
  4917. return false;\n
  4918. }
  4919. }
  4920. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  4921. }
  4922. }
  4923. function delete_dir_ilm (ilmid, dirid) {
  4924. var msgAnswer;
  4925. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  4926. if (msgAnswer) {
  4927. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  4928. }
  4929. }
  4930. function rename_dir_ilm (ilmid, dirname, dirid) {
  4931. var dirnamecopy;
  4932. var i;
  4933. var dirs = new Array($dirs_array);
  4934. do {
  4935. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  4936. } while (dirnamecopy == '');
  4937. if (dirnamecopy == null)
  4938. return false;\n
  4939. else {
  4940. for (i=0;i<dirs.length;i++) {
  4941. if (dirs[i]==dirnamecopy) {
  4942. alert('$error_dir_exists');
  4943. return false;\n
  4944. }
  4945. }
  4946. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  4947. }
  4948. }
  4949. function move_selected_ilm (ilmid) {
  4950. var param = getCheckbox();
  4951. if (param.join() != '')
  4952. 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();
  4953. else
  4954. alert('" . get_string('error_file_not_selected_to_move', 'iassign') . "');
  4955. }
  4956. function recover_files_ilm () {
  4957. var msgAnswer;
  4958. msgAnswer = confirm('" . get_string('question_recover_files_ilm', 'iassign') . "');
  4959. if (msgAnswer) {
  4960. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  4961. }
  4962. }
  4963. //]]>
  4964. </script>\n";
  4965. $output = "";
  4966. $select_all = "";
  4967. $count_files = 0;
  4968. $extensions_allow = array();
  4969. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  4970. foreach ($iassign_ilm as $item_iassign_ilm)
  4971. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  4972. foreach ($files_course as $value) {
  4973. $filename = $value->get_filename();
  4974. $filepath = $value->get_filepath();
  4975. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  4976. $pathname = $pathname[count($pathname) - 1];
  4977. $fileid = $value->get_id();
  4978. $tmp = explode(".", $filename);
  4979. $filetype = $tmp[1];
  4980. $author = $value->get_author();
  4981. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  4982. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  4983. $extensions = explode(",", $extension);
  4984. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  4985. $count_files ++;
  4986. // buscar fileid nas tabelas do iassign
  4987. $list_filein_use = "";
  4988. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  4989. if ($iassign_statement_activity_list) {
  4990. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  4991. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  4992. }
  4993. }
  4994. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'parent' => '0', 'enable' => '1'));
  4995. if (!$iassign_ilm) {
  4996. $iassign_ilm = new stdClass();
  4997. $iassign_ilm->id = $ilmid;
  4998. }
  4999. $url = "{$CFG->wwwroot}/pluginfile.php/{$value->get_contextid()}/mod_iassign/activity";
  5000. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  5001. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  5002. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  5003. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5004. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5005. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5006. $check_select = "";
  5007. $link_rename = "";
  5008. $link_delete = "";
  5009. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5010. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5011. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5012. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  5013. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5014. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5015. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5016. if ($value->get_userid() == $USER->id) {
  5017. if ($iassign_statement_activity_list) {
  5018. $check_select = "";
  5019. $link_edit = iassign_icons::insert('edit_iassign_disable');
  5020. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  5021. $link_rename = "";
  5022. } else {
  5023. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  5024. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  5025. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  5026. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  5027. }
  5028. }
  5029. if (!in_array($filetype, $extensions_allow)) {
  5030. $link_edit = "";
  5031. $link_add_ilm_iassign = "";
  5032. $link_add_ilm_tinymce = "";
  5033. $link_add_ilm_atto = "";
  5034. $link_filter = "";
  5035. }
  5036. if ($value->is_directory()) {
  5037. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  5038. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  5039. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  5040. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  5041. <td><center>$author</center></td>
  5042. <td><center>$timecreated</center></td>
  5043. <td><center>$timemodified</center></td></tr>\n";
  5044. } else if ($this->from == 'iassign') {
  5045. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  5046. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5047. <td><center>$author</center></td>
  5048. <td><center>$timecreated</center></td>
  5049. <td><center>$timemodified</center></td></tr>\n";
  5050. } else if ($this->from == 'block') {
  5051. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  5052. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5053. <td><center>$author</center></td>
  5054. <td><center>$timecreated</center></td>
  5055. <td><center>$timemodified</center></td></tr>\n";
  5056. } else if ($this->from == 'tinymce') {
  5057. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  5058. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5059. <td><center>$author</center></td>
  5060. <td><center>$timecreated</center></td>
  5061. <td><center>$timemodified</center></td></tr>\n";
  5062. } else if ($this->from == 'atto') {
  5063. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  5064. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5065. <td><center>$author</center></td>
  5066. <td><center>$timecreated</center></td>
  5067. <td><center>$timemodified</center></td></tr>\n";
  5068. }
  5069. }
  5070. }
  5071. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  5072. $dir_base = "";
  5073. $header = "";
  5074. foreach ($basename as $value) {
  5075. $dir_base .= "$value/";
  5076. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  5077. if ($dir_id) {
  5078. if ($value == "") {
  5079. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5080. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  5081. } else {
  5082. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5083. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  5084. }
  5085. }
  5086. }
  5087. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  5088. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  5089. $html .= "
  5090. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  5091. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  5092. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  5093. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  5094. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  5095. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  5096. </table>\n";
  5097. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  5098. $html .= "<table width='100%'><tr>\n";
  5099. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  5100. if ($count_files != 0) {
  5101. $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";
  5102. $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";
  5103. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  5104. }
  5105. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  5106. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  5107. $html .= "</form>\n";
  5108. print $code_javascript_ilm;
  5109. print $html;
  5110. } // function view_files_ilm($extension)
  5111. } // class ilm_manager
  5112. /// Class to insert of icons
  5113. class iassign_icons {
  5114. static function insert ($icon) {
  5115. global $CFG;
  5116. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  5117. return $string;
  5118. }
  5119. }
  5120. /// Class with util functions for plugin manage
  5121. class iassign_utils {
  5122. /// Function to return the filename extension
  5123. // @param string The $filename as an string
  5124. // @return string Return an string (last group after '.')
  5125. static function filename_extension ($filename) {
  5126. if ($filename == null || $filename == '') {
  5127. return null;
  5128. }
  5129. $itens = explode('.', $filename);
  5130. $num = count($itens);
  5131. if ($num < 2) {
  5132. return null;
  5133. }
  5134. return $itens[$num - 1];
  5135. }
  5136. /// Function for format filename remove special caracters
  5137. // @param string $text String for clean
  5138. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  5139. // @return string Return an string in clean format
  5140. static function format_filename ($text) {
  5141. if ($text != '.') {
  5142. $text = htmlspecialchars(urldecode($text));
  5143. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê",
  5144. "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?");
  5145. $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",
  5146. "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C", "-", "_", "", "");
  5147. // E.g. text = "exerc_midpoint.course.geo"
  5148. // 0123456789012345678901234
  5149. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  5150. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  5151. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  5152. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  5153. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  5154. //$ext = strrpos($text, ".");
  5155. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  5156. //$text = str_replace($array1, $array2, $text);
  5157. }
  5158. return $text;
  5159. }
  5160. /// Function for format pathname remove special caracters
  5161. // @param string $text String for clean
  5162. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5163. // @return string Return an string in clean format
  5164. static function format_pathname ($text, $is_lowercase = true) {
  5165. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5166. $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", "-", "_", "", "", "");
  5167. $text = str_replace($array1, $array2, $text);
  5168. if ($is_lowercase)
  5169. $text = strtolower($text);
  5170. return $text;
  5171. }
  5172. /// Function for insert version in the filename
  5173. // @param string $filename Name of file
  5174. // @return string Return the filename with version
  5175. static function version_filename ($filename) {
  5176. $array_filename = explode('.', $filename);
  5177. if (count($array_filename) > 1)
  5178. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  5179. else
  5180. $filename = $array_filename[0] . '-' . date("Ymd-His");
  5181. return $filename;
  5182. }
  5183. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  5184. static function remove_code_message ($string) {
  5185. $array = explode("&lt;ia_uc&gt;", $string);
  5186. return $array[0];
  5187. }
  5188. }
  5189. // class iassign_utils
  5190. /// Class with language functions for plugin manage
  5191. class iassign_language {
  5192. /// Function for return text in language or get default language (en)
  5193. // @param string $lang Code of language
  5194. // @param string $description JSON text content all languages
  5195. // @return string Return an string in the language selected
  5196. static function get_description_lang ($lang, $descriptions) {
  5197. $description_lang = "";
  5198. $description = json_decode($descriptions);
  5199. if ($description == null) {
  5200. $description_lang = $descriptions;
  5201. } else {
  5202. if (isset($description->{$lang}))
  5203. $description_lang = $description->{$lang};
  5204. else
  5205. if (isset($description->en)) //MOOC2014
  5206. $description_lang = $description->en;
  5207. else //MOOC2014
  5208. $description_lang = "en"; //MOOC2014
  5209. }
  5210. return $description_lang;
  5211. }
  5212. /// Function for return all language supported by iLM
  5213. // @param string $descriptions JSON text content all languages
  5214. // @return string Return as string with all languages
  5215. static function get_all_lang ($descriptions) {
  5216. $langs = "";
  5217. $description = json_decode($descriptions);
  5218. if ($description) {
  5219. foreach ($description as $key => $value) {
  5220. $langs .= $key . " ; ";
  5221. }
  5222. $langs = substr($langs, 0, strlen($langs) - 3);
  5223. }
  5224. return $langs;
  5225. }
  5226. /// Function for convert json in xml //MOOC2014
  5227. // @param string $json JSON text
  5228. // @return string Return as string with xml tags
  5229. static function json_to_xml ($json) {
  5230. $xml = "";
  5231. $json = json_decode($json);
  5232. foreach ($json as $key => $value) {
  5233. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  5234. }
  5235. return $xml;
  5236. }
  5237. }
  5238. // class iassign_language
  5239. /// Class with log functions for plugin manage.
  5240. class iassign_log {
  5241. /// Function for insert log event
  5242. // @param string $action Code action of event
  5243. // @param string $information Text for describe action of event
  5244. // @param int $cmid Id of context module
  5245. // @param int $ilmid Id of iLM
  5246. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  5247. global $COURSE, $CFG, $USER, $DB;
  5248. $newentry = new stdClass();
  5249. $newentry->time = time();
  5250. $newentry->userid = $USER->id;
  5251. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  5252. $newentry->course = $COURSE->id;
  5253. $newentry->cmid = $cmid;
  5254. $newentry->ilmid = $ilmid;
  5255. $newentry->action = $action;
  5256. $newentry->info = $information;
  5257. $newentry->language = current_language();
  5258. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  5259. if (ini_get("browscap") && function_exists('get_browse')) {
  5260. $browser = get_browse(null, true);
  5261. $newentry->javascript = $browser['javascript'];
  5262. $newentry->java = $browser['javaapplets'];
  5263. }
  5264. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  5265. print_error('error_add_log', 'iassign');
  5266. }
  5267. }
  5268. // class iassign_log