locallib.php 327 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.2 2019/03/13
  7. * + Several fixes to allow iLM under HTML stack
  8. *
  9. * - v 4.9.1 2017/11/02
  10. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  11. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  12. *
  13. * - v 4.9 2017/03/13
  14. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  15. *
  16. * - v 4.8 2016/05/12
  17. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  18. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  19. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  20. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  21. * replaced by
  22. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  23. * - v 4.7 2016/02/17
  24. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  25. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  26. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  27. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  28. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  29. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  30. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  31. *
  32. * --------------- (code bellow was used at our MOOC 2014)
  33. * - v 4.6 2014/02/25
  34. * + Fix bugs in filter function for open applets.
  35. * - v 4.5 2014/02/24
  36. * + Fix bugs in params.
  37. * + Insert new param type.
  38. * - v 4.4 2014/01/24
  39. * + Allow select type of params.
  40. * + Insert the use of applet params specific for activities.
  41. * - v 4.3 2014/01/23
  42. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  43. * - v 4.2 2016/02/13
  44. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  45. * --------------- (above code used at our MOOC 2014)
  46. *
  47. * - v 4.1 2013/12/13
  48. * + Insert log in iAssign actions.
  49. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  50. * + Insert class for Log actions in system.
  51. * - v 4.0 2013/10/31
  52. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  53. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  54. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  55. * - v 3.9 2013/10/25
  56. * + Insert support of upgrade iLM.
  57. * + Insert support for more than one extension in iLM.
  58. * + Fix bugs in verion control.
  59. * - v 3.8 2013/09/19
  60. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  61. * - v 3.7 2013/09/12
  62. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  63. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  64. * - v 3.6 2013/09/05
  65. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  66. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  67. * + Change tag APPLET in function ilm_settings::view_ilm.
  68. * - v 3.5 2013/08/26
  69. * + Fix bug in download package iassign without answers (iassign::report).
  70. * - v 3.4 2013/08/23
  71. * + Fix bug in export package iassign.
  72. * - v 3.3 2013/08/22
  73. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  74. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  75. * - v 3.2 2013/08/21
  76. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  77. * + Change functions for import files for ilm_manager.php.
  78. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  79. * - v 3.1 2013/08/15
  80. * + Change return file selected (ilm_manager::add_ilm).
  81. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  82. * - v 3.0 2013/08/02
  83. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  84. * - v 2.9 2013/08/01
  85. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  86. * - v 2.8 2013/07/25
  87. * + Insert the activity name in header of view (activity::view_dates).
  88. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  89. * - v 2.7 2013/07/24
  90. * + Create link previous and next for student view in one activity (activity::view_dates).
  91. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  92. * - v 2.6 2013/07/23
  93. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  94. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  95. * - v 2.5 2013/07/12
  96. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  97. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  98. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  99. *
  100. * @author Patricia Alves Rodrigues
  101. * @author Leônidas O. Brandão
  102. * @contributor Igor Moreira Félix (2018-)
  103. * @contributor Márcio de Lima Passos (2014)
  104. * @version v 4.9.2 2019/03/13
  105. * @version v 4.8 2016/05/12
  106. * @package mod_iassign_lib
  107. * @since 2010/09/27
  108. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  109. *
  110. * <b>License</b>
  111. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  112. */
  113. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  114. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  115. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  116. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  117. /**
  118. * Standard base class for all iAssign
  119. */
  120. class iassign {
  121. var $cm;
  122. var $course;
  123. var $iassign;
  124. var $striassign;
  125. var $striassigns;
  126. var $context;
  127. var $activity;
  128. var $iassign_up;
  129. var $iassign_down;
  130. var $action;
  131. var $iassign_submission_current;
  132. var $userid_iassign;
  133. var $bottonPost;
  134. var $write_solution;
  135. var $view_iassign;
  136. // 3.1 update PHP 7.0 compatibility for all moodle versions
  137. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  138. /// Constructor for the base iassign class
  139. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  140. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  141. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  142. function __construct ($iassign, $cm, $course) {
  143. global $COURSE, $CFG, $USER, $DB;
  144. $botton = optional_param('botton', NULL, PARAM_TEXT);
  145. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  146. if (!is_null($botton))
  147. $USER->iassignEdit = $botton;
  148. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  149. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  150. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  151. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  152. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  153. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  154. $this->action = optional_param('action', NULL, PARAM_TEXT);
  155. $this->cm = $cm;
  156. $this->context = context_module::instance($this->cm->id);
  157. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  158. $this->userid_iassign = $USER->id;
  159. if ($course) {
  160. $this->course = $course;
  161. }
  162. else if ($this->cm->course == $COURSE->id) {
  163. $this->course = $COURSE;
  164. }
  165. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  166. print_error('invalidid', 'iassign');
  167. }
  168. $this->coursecontext = context_course::instance($this->course->id);
  169. if ($iassign) {
  170. $this->iassign = $iassign;
  171. }
  172. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  173. print_error('invalidid', 'iassign');
  174. }
  175. $USER->context = context_module::instance($this->cm->id);
  176. $USER->cm = $this->cm->id;
  177. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  178. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  179. $this->context = context_module::instance($this->cm->id);
  180. $this->striassign = get_string('modulename', 'iassign');
  181. $this->striassigns = get_string('modulenameplural', 'iassign');
  182. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  183. $this->bottonPost = 0;
  184. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  185. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  186. $this->view();
  187. } // function __construct($iassign, $cm, $course)
  188. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  189. // This method provides the page to view each iLM with any interactive activity
  190. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  191. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  192. global $USER, $DB, $OUTPUT;
  193. // $iassign_statementid = $this->iassign->iassign_statementid;
  194. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  195. $iassign_statementid = $this->activity->get_activity()->id;
  196. else
  197. $iassign_statementid = "";
  198. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  199. // If this user has no capability to View 'iassign': stop here
  200. require_capability('mod/iassign:view', $this->context);
  201. // Trigger module view event
  202. $event = \mod_iassign\event\course_module_viewed::create(array(
  203. 'objectid' => $this->iassign->id,
  204. 'context' => $this->context
  205. ));
  206. $event->add_record_snapshot('course', $this->course);
  207. $event->trigger();
  208. if ($this->action) { // when student do/redo activity or teacher see student solution
  209. $this->action(); // calls '$this->view_iLM();'
  210. }
  211. else {
  212. print $OUTPUT->header();
  213. $this->view_iassigns(); // show the iLM with the content
  214. print $OUTPUT->footer();
  215. }
  216. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  217. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  218. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  219. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  220. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  221. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  222. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  223. //D else echo "Apagou!<br/>";
  224. die();
  225. } // function view()
  226. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  227. function action () {
  228. global $USER;
  229. // action:
  230. // up - move up activity (mover atividade para cima)
  231. // down - move down activity (mover atividade para baixo)
  232. // visible - view/hide activity (exibir/ocultar atividade)
  233. // delete - delete activity (excluir atividade)
  234. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  235. // deleteno - does not erase activity (não apaga atividade)
  236. // add - add activity (adicionar atividade)
  237. // edit - edit activity (modificar atividade)
  238. $action_iassign = array(
  239. 'newcomment' => '$this->get_answer();',
  240. 'view' => '$this->view_iassign_current();',
  241. 'get_answer' => '$this->get_answer();',
  242. 'repeat' => '$this->view_iassign_current();',
  243. 'overwrite' => '$this->get_answer();',
  244. 'stats_student' => '$this->stats_students();',
  245. 'download_answer' => '$this->export_file_answer();',
  246. 'download_all_answer' => '$this->export_package_answer();');
  247. $action_iassign_limit = array(
  248. 'view' => '$this->view_iassign_current();',
  249. 'newcomment' => '$this->get_answer();',
  250. 'viewsubmission' => '$this->view_iassign_current();',
  251. 'edit_status' => '$this->edit_status();',
  252. 'edit_grade' => '$this->edit_grade();',
  253. 'export_csv' => '$this->export_csv();',
  254. 'report' => '$this->report();',
  255. 'print' => '$this->report();',
  256. 'stats' => '$this->stats();',
  257. 'printstats' => '$this->stats();');
  258. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  259. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  260. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  261. 'visible' => '$this->activity->visible_iassign($this->return);',
  262. 'delete' => '$this->activity->delete($this->return);',
  263. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  264. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  265. 'add' => '$this->add_edit_iassign();',
  266. 'edit' => '$this->add_edit_iassign();',
  267. 'get_answer' => '$this->get_answer();',
  268. 'duplicate_activity' => '$this->duplicate_activity();',
  269. 'move_activity' => '$this->move_activity();',
  270. 'auto_evaluate' => '$this->auto_evaluate();');
  271. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  272. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  273. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  274. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  275. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  276. }
  277. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  278. eval($action_iassign_limit[$this->action]);
  279. }
  280. else { // Student reaches this point
  281. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  282. // Arrive here with: "get_answer"; "view"
  283. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  284. }
  285. } // function action()
  286. /// This method runs activities auto evaluation in teacher area
  287. function auto_evaluate () {
  288. global $COURSE, $CFG, $USER, $DB, $OUTPUT;
  289. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  290. exit;
  291. print $OUTPUT->header();
  292. print $OUTPUT->footer();
  293. }
  294. /// This method moves an iAssign activity
  295. function move_activity () {
  296. global $USER, $CFG, $DB, $COURSE;
  297. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  298. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  299. $update_entry_new_iassign = new stdClass();
  300. $update_entry_new_iassign->id = $iassign_id;
  301. $update_entry_new_iassign->iassignid = $iassign_destiny;
  302. // Update the iassign_statement
  303. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  304. // Update file context
  305. $c_i = context_module::instance($this->cm->id);
  306. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  307. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  308. $path_module = context_course::instance($COURSE->id);
  309. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  310. if ($context_file) {
  311. $id_context = $context_file->id;
  312. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  313. $fs = get_file_storage(); // Get reference to all files in Moodle data
  314. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  315. foreach ($files as $value) {
  316. if ($value->get_filename() != ".") {
  317. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  318. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  319. $updateentry = new stdClass();
  320. $updateentry->id = $iassign_id;
  321. $updateentry->file = $newfile->get_itemid();
  322. $DB->update_record("iassign_statement", $updateentry);
  323. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  324. break;
  325. }
  326. }
  327. }
  328. $this->return_home_course('moved_activity');
  329. exit;
  330. }
  331. /// This method duplicates an iAssign activity
  332. function duplicate_activity () {
  333. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  334. $id = $this->cm->id;
  335. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  336. $context = context_module::instance($this->cm->id);
  337. $contextuser = context_user::instance($USER->id);
  338. // Get the the iAssign acitivity to be duplicated
  339. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  340. // Remove the current id of activity
  341. $iassign_statement->id=0;
  342. // Get the information about current author, and add this information in author_modified field
  343. $author = $DB->get_record("user", array('id' => $USER->id));
  344. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  345. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  346. // Store the activity in the table
  347. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  348. // Duplicate activity file
  349. $fs = get_file_storage(); // Get reference to all files in Moodle data
  350. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  351. foreach ($files as $value) {
  352. if ($value->get_filename() != ".") {
  353. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  354. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  355. $updateentry = new stdClass();
  356. $updateentry->id = $id_;
  357. $updateentry->file = $newfile->get_itemid();
  358. // Update the duplicated iLM iAssign with new file id
  359. $DB->update_record("iassign_statement", $updateentry);
  360. }
  361. }
  362. }
  363. // log event --------------------------------------------------------------------------------------
  364. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  365. $this->return_home_course('duplicated_activity');
  366. exit;
  367. }
  368. /// This method gets the content from the iLM and register it
  369. // It could be the "exercise template" (teacher) or an answer (student)
  370. function get_answer () {
  371. global $USER, $CFG, $DB, $OUTPUT;
  372. $id = $this->cm->id;
  373. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  374. $comment = false;
  375. if ($submission_comment)
  376. $comment = $this->write_comment_submission();
  377. // receives data of iLM using the current activity
  378. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  379. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  380. // receives data of submission of current activity
  381. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  382. // receives post and get
  383. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  384. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  385. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  386. $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)
  387. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  388. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  389. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  390. $msg = '';
  391. // Feedback
  392. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  393. $str_action = "view"; // repeat
  394. if (strtolower($iassign_ilm->name) == "igeom") {
  395. }
  396. $title = get_string('evaluate_iassign', 'iassign');
  397. print $OUTPUT->header();
  398. print $OUTPUT->box_start();
  399. // Action = { view ; repeat ; viewsubmission }
  400. // * '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")
  401. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  402. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  403. $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;
  404. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  405. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  406. print '<table width=100% >';
  407. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  408. //TODO alterar aqui???
  409. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  410. // empty_answer_post = No solution was posted.
  411. if ($comment)
  412. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  413. else
  414. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  415. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  416. } else {
  417. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  418. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  419. // Correct answer!!
  420. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  421. $this->write_solution = 1; //
  422. $status = 3;
  423. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  424. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  425. // log record
  426. $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;
  427. // Trigger module viewed event.
  428. $event = \mod_iassign\event\submission_created::create(array(
  429. 'objectid' => $this->iassign->id,
  430. 'context' => $this->context,
  431. 'other' => $info
  432. ));
  433. $event->add_record_snapshot('course', $this->course);
  434. $event->trigger();
  435. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  436. // Wrong answer...: get_answer_incorrect
  437. $status = 2;
  438. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  439. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  440. // log record
  441. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  442. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  443. // Trigger module viewed event.
  444. $event = \mod_iassign\event\submission_created::create(array(
  445. 'objectid' => $this->iassign->id,
  446. 'context' => $this->context,
  447. 'other' => $info
  448. ));
  449. $event->add_record_snapshot('course', $this->course);
  450. $event->trigger();
  451. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  452. // Presents to the learner the result of the automatic evaluate?
  453. if ($this->activity->get_activity()->show_answer == 0) { // no...
  454. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  455. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  456. print '<tr>';
  457. // log record
  458. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  459. // Trigger module viewed event.
  460. $event = \mod_iassign\event\submission_created::create(array(
  461. 'objectid' => $this->iassign->id,
  462. 'context' => $this->context,
  463. 'other' => $info
  464. ));
  465. $event->add_record_snapshot('course', $this->course);
  466. $event->trigger();
  467. } else { // yes!!!
  468. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  469. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  470. print '<tr>';
  471. print $msg;
  472. }
  473. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  474. $status = 1;
  475. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  476. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  477. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  478. print '<tr>';
  479. // log record
  480. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  481. $event = \mod_iassign\event\submission_created::create(array(
  482. 'objectid' => $this->iassign->id,
  483. 'context' => $this->context,
  484. 'other' => $info
  485. ));
  486. $event->add_record_snapshot('course', $this->course);
  487. $event->trigger();
  488. } // if ($iassign_ilm->evaluate == 1)
  489. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  490. print '</tr></table>';
  491. print $OUTPUT->box_end();
  492. // add or update evaluate
  493. if ($this->write_solution == 1) {
  494. $timenow = time();
  495. // new record
  496. if (!$iassign_submission) {
  497. $newentry = new stdClass();
  498. $newentry->userid = $this->userid_iassign;
  499. // $newentry->userid = $USER->id;
  500. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  501. $newentry->timecreated = $timenow;
  502. $newentry->timemodified = $timenow;
  503. $newentry->answer = $iLM_PARAM_ArchiveContent;
  504. $newentry->grade = $grade_student;
  505. $newentry->status = $status;
  506. $newentry->experiment = 1;
  507. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  508. print_error('error_insert', 'iassign');
  509. } else {
  510. // Trigger module viewed event.
  511. $event = \mod_iassign\event\submission_created::create(array(
  512. 'objectid' => $this->iassign->id,
  513. 'context' => $this->context
  514. ));
  515. $event->add_record_snapshot('course', $this->course);
  516. $event->trigger();
  517. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  518. }
  519. } elseif ($iassign_submission->status != 3) {
  520. $newentry = new stdClass();
  521. $newentry->id = $iassign_submission->id;
  522. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  523. $newentry->userid = $iassign_submission->userid;
  524. $newentry->timecreated = $iassign_submission->timecreated;
  525. $newentry->timemodified = $timenow;
  526. $newentry->answer = $iLM_PARAM_ArchiveContent;
  527. $newentry->grade = $grade_student;
  528. $newentry->status = $status;
  529. $newentry->experiment = $iassign_submission->experiment + 1;
  530. if (!$DB->update_record("iassign_submission", $newentry)) {
  531. print_error('error_update', 'iassign');
  532. //D depurar...
  533. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  534. //D $fp = fopen("teste1.txt","w");
  535. //D fwrite($fp,$stringAux);
  536. } else {
  537. // Trigger module viewed event.
  538. $event = \mod_iassign\event\submission_updated::create(array(
  539. 'objectid' => $this->iassign->id,
  540. 'context' => $this->context
  541. ));
  542. $event->add_record_snapshot('course', $this->course);
  543. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  544. }
  545. } else {
  546. if ($return_get_answer == 1) {
  547. $newentry = new stdClass();
  548. $newentry->id = $iassign_submission->id;
  549. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  550. $newentry->userid = $iassign_submission->userid;
  551. $newentry->timecreated = $iassign_submission->timecreated;
  552. $newentry->timemodified = $timenow;
  553. $newentry->answer = $iLM_PARAM_ArchiveContent;
  554. $newentry->grade = $grade_student;
  555. $newentry->status = $status;
  556. $newentry->experiment = $iassign_submission->experiment + 1;
  557. if (!$DB->update_record("iassign_submission", $newentry))
  558. print_error('error_update', 'iassign');
  559. else {
  560. $event = \mod_iassign\event\submission_updated::create(array(
  561. 'objectid' => $this->iassign->id,
  562. 'context' => $this->context
  563. ));
  564. $event->add_record_snapshot('course', $this->course);
  565. $event->trigger();
  566. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  567. print $OUTPUT->box_start();
  568. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  569. print $OUTPUT->box_end();
  570. }
  571. } elseif ($return_get_answer == 2) {
  572. print $OUTPUT->box_start();
  573. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  574. print $OUTPUT->box_end();
  575. } else {
  576. print $OUTPUT->box_start();
  577. print "
  578. <script type='text/javascript'>
  579. //<![CDATA[
  580. function overwrite () {
  581. document.formEnvio.return_get_answer.value = 1;
  582. document.formEnvio.submit();
  583. }
  584. function nooverwrite () {
  585. document.formEnvio.return_get_answer.value = 2;
  586. document.formEnvio.submit();
  587. }
  588. //]]>
  589. </script>";
  590. $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;
  591. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  592. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  593. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  594. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  595. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  596. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  597. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  598. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  599. <input type='hidden' name='return_get_answer'/> ";
  600. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  601. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  602. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  603. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  604. print " </form>";
  605. print $OUTPUT->box_end();
  606. }
  607. }
  608. } // if ($this->write_solution == 1)
  609. print $OUTPUT->footer();
  610. die();
  611. } // function get_answer()
  612. /// Export in file the answer of student.
  613. function export_file_answer () {
  614. global $DB;
  615. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  616. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  617. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  618. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  619. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  620. $extensions = explode(",", $iassign_ilm->extension);
  621. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  622. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  623. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  624. header("Pragma: public");
  625. header("Expires: 0");
  626. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  627. header("Cache-Control: private", false);
  628. header("Content-Type: document/unknown");
  629. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  630. set_time_limit(0);
  631. print($iassign_submission->answer);
  632. exit;
  633. } // function export_file_answer()
  634. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  635. // @calledby $this->export_package_answer()
  636. //TODO Precisa terminar! //TODO_HTML
  637. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  638. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  639. <head>
  640. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  641. $str_html .= " </head>
  642. <body>\n";
  643. $tam = sizeof($array_iassign_name);
  644. for ($ii=0; $ii<$tam; $ii++) {
  645. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  646. }
  647. $str_html .= "
  648. </body>\n</html>";
  649. return $str_html;
  650. }
  651. /// Export an package (zip) with all answer of students
  652. // @calledby $this->action()
  653. function export_package_answer () {
  654. global $DB, $CFG, $OUTPUT;
  655. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  656. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  657. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  658. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  659. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  660. $userid = optional_param('userid', NULL, PARAM_INT);
  661. $iassign_user = $DB->get_record("user", array("id" => $userid));
  662. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  663. //TODO_HTML echo "username=$username<br/>"; exit;
  664. $current_date = date('Y_m_d_H');
  665. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  666. // If temporary directory under Moodle data does not exists => create it
  667. if (!is_dir($diretorio)) {
  668. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  669. // created directory with permissions to be seen by everyone
  670. }
  671. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  672. if (!is_writable($diretorio)) { // send a highlighted message!
  673. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  674. exit; // just in case
  675. }
  676. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  677. $zip = new zip_archive(); // create ZIP
  678. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  679. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  680. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  681. $vet_student_filename = array();
  682. $vet_student_content = array();
  683. foreach ($iassign_statements as $iassign_statement) {
  684. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  685. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  686. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  687. $extensions = explode(",", $iassign_ilm->extension);
  688. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  689. if ($iassign_submission) {
  690. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  691. $student_content = $iassign_submission->answer;
  692. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  693. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  694. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  695. if ($resp) {
  696. $vet_student_filename[] = $student_filename;
  697. $vet_student_content[] = $student_content;
  698. }
  699. else { // send a highlighted message!
  700. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  701. exit; // just in case
  702. }
  703. }
  704. }
  705. $zip->close(); // close the ZIP file
  706. if (count($vet_student_filename)>0) {
  707. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  708. $result_tf = $vet_result[0];
  709. $filenameZip = $vet_result[1]->filename;
  710. }
  711. iassign_utils::download_file($zip_filename); // download the ZIP file
  712. exit;
  713. } // function export_package_answer()
  714. /// Editing status of interactive activities
  715. function edit_status () {
  716. global $USER, $DB, $OUTPUT;
  717. $newentry = new stdClass();
  718. $newentry->id = $this->iassign_submission_current;
  719. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  720. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  721. if ($iassign_submission->status != 0 && $newentry->status == 0)
  722. $newentry->status = $iassign_submission->status;
  723. $newentry->teacher = $USER->id;
  724. if (!$DB->update_record('iassign_submission', $newentry))
  725. print_error('error_update', 'iassign');
  726. else {
  727. // Trigger module viewed event.
  728. $event = \mod_iassign\event\submission_updated::create(array(
  729. 'objectid' => $this->iassign->id,
  730. 'context' => $this->context
  731. ));
  732. $event->add_record_snapshot('course', $this->course);
  733. $event->trigger();
  734. $this->action = 'viewsubmission';
  735. $this->view_iassign_current();
  736. } // if (!$DB->update_record('iassign_submission', $newentry))
  737. } // function edit_status()
  738. /// Editing grade of interactive activities
  739. function edit_grade () {
  740. global $USER, $DB, $OUTPUT;
  741. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  742. if ($newgrade && $newgrade >= 0) {
  743. $newentry = new stdClass();
  744. $newentry->id = $this->iassign_submission_current;
  745. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  746. $newentry->teacher = $USER->id;
  747. if (!$DB->update_record('iassign_submission', $newentry))
  748. print_error('error_update', 'iassign');
  749. else {
  750. // Trigger module viewed event.
  751. $event = \mod_iassign\event\submission_updated::create(array(
  752. 'objectid' => $this->iassign->id,
  753. 'context' => $this->context
  754. ));
  755. $event->add_record_snapshot('course', $this->course);
  756. $event->trigger();
  757. }
  758. } // if ($newgrade >= 0)
  759. $this->action = 'viewsubmission';
  760. $this->view_iassign_current();
  761. }
  762. /// Add or Edit interactive activities
  763. // @calledby $this->action()
  764. function add_edit_iassign () {
  765. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  766. require_once('iassign_form.php');
  767. $id = $this->cm->id;
  768. $iassignid = $this->iassign->id;
  769. $param = new stdClass();
  770. $param->action = $this->action; // oculto
  771. $param->id = $id; // oculto
  772. $COURSE->cm = $id;
  773. $COURSE->iassignid = $iassignid;
  774. $COURSE->iassign_file_id = NULL;
  775. $context = context_module::instance($this->cm->id);
  776. $contextuser = context_user::instance($USER->id);
  777. $component = 'mod_iassign';
  778. $filearea = 'exercise';
  779. if (!empty($this->iassign_current))
  780. $COURSE->iassign_id = $this->iassign_current;
  781. else
  782. $COURSE->iassign_id = 0;
  783. $total_of_activities = 0; // get the total number of activities in this iAssign block
  784. if ($this->action == 'add') {
  785. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  786. $total_of_activities = count($iassign_data);
  787. $params = array('iassignid' => $iassignid);
  788. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  789. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  790. $param->iassignid = $iassignid;
  791. $param->name = "";
  792. $param->oldname = "";
  793. $param->type_iassign = 3;
  794. $param->proposition = "";
  795. $author = $DB->get_record("user", array("id" => $USER->id));
  796. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  797. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  798. $param->author = $param->author_name;
  799. $param->author_modified = $param->author_modified_name;
  800. $COURSE->iassign_list = array();
  801. $param->iassign_list = array();
  802. if ($iassign_statement) {
  803. foreach ($iassign_statement as $iassign) {
  804. $iassignid = $iassign->id;
  805. $param->iassign_list[$iassignid] = 0;
  806. $COURSE->iassign_list[$iassignid] = new stdClass();
  807. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  808. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  809. $COURSE->iassign_list[$iassignid]->enable = 1;
  810. } // foreach ($iassign_statement as $iassign)
  811. }
  812. $param->iassign_ilmid = 0;
  813. //echo "locallib.php: add_edit_iassign(): add<br/>";
  814. $param->file = 0;
  815. $param->fileold = 0;
  816. $param->filename = "";
  817. $param->grade = $iassign_data->grade;
  818. $param->timemodified = time();
  819. $param->timecreated = time();
  820. $param->timeavailable = $iassign_data->timeavailable;
  821. $param->timedue = $iassign_data->timedue;
  822. $param->preventlate = $iassign_data->preventlate;
  823. $param->test = $iassign_data->test;
  824. $param->special_param1 = 0;
  825. $param->visible = 1;
  826. $param->max_experiment = $iassign_data->max_experiment;
  827. $param->dependency = 0;
  828. $param->automatic_evaluate = 1;
  829. $param->show_answer = 1;
  830. } // if ($this->action == 'add')
  831. elseif ($this->action == 'edit') {
  832. $COURSE->iassign_list = array();
  833. $this_activity = $this->activity->get_activity();
  834. if ($this_activity != null) {
  835. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  836. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  837. $param->iassign_id = $iassign_statement_current->id; // oculto
  838. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  839. $param->name = $iassign_statement_current->name;
  840. $param->oldname = $iassign_statement_current->name;
  841. $param->type_iassign = $iassign_statement_current->type_iassign;
  842. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  843. //2019 $param->proposition = $iassign_statement_current->proposition;
  844. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  845. $param->author_name = $iassign_statement_current->author_name; // oculto
  846. $param->author = $iassign_statement_current->author_name;
  847. $author = $DB->get_record("user", array('id' => $USER->id));
  848. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  849. $param->author_modified = $param->author_modified_name;
  850. $dependency = explode(';', $iassign_statement_current->dependency);
  851. $param->iassign_list = array();
  852. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  853. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  854. $array_dependency = array();
  855. $subdependency = "";
  856. $sub_subdependency = "";
  857. // dependent on this exercise
  858. if ($iassign_statement_dependency) {
  859. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  860. // to whom this exercise depends
  861. foreach ($inter as $tmp)
  862. $sub_subdependency .= $this->search_sub_dependency($tmp);
  863. $list_dependency = $subdependency . $sub_subdependency;
  864. $array_dependency = explode(";", $list_dependency);
  865. }
  866. // Get all activity with the same iLM - iassignid
  867. $str_query = "SELECT id, name FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' ORDER BY s.position ASC";
  868. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  869. $total_of_activities = count($all_others_iassign_statement) + 1;
  870. $inter = array();
  871. if ($all_others_iassign_statement) {
  872. foreach ($all_others_iassign_statement as $iassign)
  873. if (in_array($iassign->id, $dependency))
  874. $inter[] = $iassign->id;
  875. }
  876. if ($all_others_iassign_statement) {
  877. foreach ($all_others_iassign_statement as $iassign) {
  878. $iassignid = $iassign->id;
  879. $COURSE->iassign_list[$iassignid] = new stdClass();
  880. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  881. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  882. if (in_array($iassignid, $dependency))
  883. $param->iassign_list[$iassignid] = 1;
  884. else
  885. $param->iassign_list[$iassignid] = 0;
  886. if (in_array($iassignid, $array_dependency))
  887. $COURSE->iassign_list[$iassignid]->enable = 0;
  888. else
  889. $COURSE->iassign_list[$iassignid]->enable = 1;
  890. } // foreach ($all_others_iassign_statement as $iassign)
  891. }
  892. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  893. $param->fileold = 0;
  894. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  895. $param->filename = '';
  896. $param->grade = $iassign_statement_current->grade;
  897. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  898. $param->timeavailable = $iassign_statement_current->timeavailable;
  899. $param->timedue = $iassign_statement_current->timedue;
  900. $param->preventlate = $iassign_statement_current->preventlate;
  901. $param->test = $iassign_statement_current->test;
  902. $param->special_param1 = $iassign_statement_current->special_param1;
  903. $param->position = $iassign_statement_current->position; // oculto
  904. $param->visible = $iassign_statement_current->visible;
  905. $param->max_experiment = $iassign_statement_current->max_experiment;
  906. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  907. $param->show_answer = $iassign_statement_current->show_answer;
  908. $fs = get_file_storage(); // Get reference to all files in Moodle data
  909. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  910. if ($files) {
  911. foreach ($files as $file) {
  912. if ($file->get_filename() != '.') {
  913. $param->filename = $file->get_filename();
  914. $param->file = $file->get_id();
  915. $param->fileold = $file->get_id();
  916. $COURSE->iassign_file_id = $file->get_id();
  917. }
  918. }
  919. }
  920. //TODO //MOOC2014 -- inicio
  921. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  922. //D if ($iassign_ilm_configs) {
  923. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  924. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  925. //D } //MOOC2014 -- fim
  926. } // if ($this_activity != null)
  927. } // elseif ($this->action == 'edit')
  928. // Get all iActivity in the iAssign block with id = $this->iassign->id
  929. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  930. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  931. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  932. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  933. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  934. $param->position = $total_of_activities;
  935. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  936. $mform->set_data($param);
  937. if ($mform->is_cancelled()) {
  938. $this->return_home_course('iassign_cancel');
  939. exit;
  940. }
  941. else { // if ($mform->is_cancelled())
  942. $result = $mform->get_data();
  943. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  944. if ($result) {
  945. $result->context = $context;
  946. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  947. $result->grade = 0;
  948. if ($result->type_iassign == 1) {
  949. $result->automatic_evaluate = 0;
  950. $result->show_answer = 0;
  951. }
  952. elseif ($result->automatic_evaluate == 0)
  953. $result->show_answer = 0;
  954. // $_POST['iassign_list']
  955. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  956. if ($result->iassign_list) {
  957. foreach ($result->iassign_list as $key => $value)
  958. $result->dependency .= $key . ';';
  959. }
  960. else
  961. $result->dependency = 0;
  962. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  963. //TODO Then get it directly from the form data $_POST!
  964. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  965. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  966. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  967. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  968. if ($this->action == 'add') {
  969. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  970. if ($iassign_statement_name) {
  971. $this->return_home_course('error_iassign_name');
  972. die();
  973. }
  974. // Really insert the new iActivity in table '*_iassign_statement'
  975. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  976. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  977. // Trigger module viewed event.
  978. $event = \mod_iassign\event\iassign_created::create(array(
  979. 'objectid' => $iassignid,
  980. 'context' => $context
  981. ));
  982. $event->add_record_snapshot('course', $this->course);
  983. $event->trigger();
  984. $this->return_home_course('iassign_add');
  985. } // if ($this->action == 'add')
  986. elseif ($this->action == 'edit') {
  987. $iassignid = $this->activity->update_iassign($result);
  988. $this->activity->update_calendar($iassignid, $result->oldname);
  989. // Trigger module viewed event.
  990. $event = \mod_iassign\event\iassign_updated::create(array(
  991. 'objectid' => $iassignid,
  992. 'context' => $context
  993. ));
  994. $event->add_record_snapshot('course', $this->course);
  995. $event->trigger();
  996. $this->return_home_course('iassign_update');
  997. } // elseif ($this->action == 'edit')
  998. die();
  999. } // if ($result)
  1000. } // else if ($mform->is_cancelled())
  1001. print $OUTPUT->header();
  1002. $mform->display();
  1003. print $OUTPUT->footer();
  1004. die();
  1005. } // function add_edit_iassign()
  1006. /// Search for dependencies
  1007. function search_dependency ($search_iassing_id, $iassign_statement) {
  1008. global $DB, $OUTPUT;
  1009. $dependency = "";
  1010. if ($iassign_statement)
  1011. foreach ($iassign_statement as $iassign) {
  1012. $inter_dependency = explode(';', $iassign->dependency);
  1013. if (in_array($search_iassing_id, $inter_dependency)) {
  1014. $dependency .= $iassign->id . ";";
  1015. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1016. } // if (in_array($search_iassing_id, $inter_dependency))
  1017. } // foreach ($iassign_statement as $iassign)
  1018. return $dependency;
  1019. }
  1020. /// Search for "sub"dependency
  1021. function search_sub_dependency ($search_iassing_id) {
  1022. global $DB, $OUTPUT;
  1023. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1024. $dependency = "";
  1025. if ($iassign_statement) {
  1026. $inter_dependency = explode(';', $iassign_statement->dependency);
  1027. foreach ($inter_dependency as $tmp) {
  1028. if ($tmp != 0)
  1029. $dependency .= $tmp . ";";
  1030. $dependency .= $this->search_sub_dependency($tmp);
  1031. } // foreach ($inter_dependency as $tmp)
  1032. } // if ($iassign_statement)
  1033. return $dependency;
  1034. }
  1035. // Warning message
  1036. static function warning_message_iassign ($strcode) {
  1037. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1038. }
  1039. /// Update grade of iAssign
  1040. // Called always any iAssign activity is created
  1041. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1042. static function update_grade_iassign ($iassignid) {
  1043. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1044. require_once($CFG->libdir . '/gradelib.php');
  1045. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1046. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1047. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1048. // Each iAssign item is associated with one item on the "gradebook"
  1049. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1050. //$sum_grade = 0;
  1051. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1052. //foreach($grade as $tmp) {
  1053. // $sum_grade += $tmp->grade;
  1054. // }
  1055. //1 Solution 1
  1056. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1057. //1 $sum_grade = 0; //1
  1058. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1059. //2 Solution 2
  1060. $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
  1061. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1062. if (key($array_sum_grade))
  1063. $sum_grade = key($array_sum_grade); //2
  1064. else
  1065. $sum_grade = 0; //2
  1066. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1067. $grades = NULL;
  1068. $params = array('itemname' => $grade_iassign->name);
  1069. $params['iteminstance'] = $iassignid;
  1070. $params['gradetype'] = GRADE_TYPE_VALUE;
  1071. //2016 if ($sum_grade != 0) {
  1072. $params['grademax'] = $sum_grade;
  1073. $params['rawgrademax'] = $sum_grade;
  1074. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1075. $params['grademin'] = 0;
  1076. // @calls /lib/gradelib.php: call to grade_item->insert()
  1077. //TODO: is there any error here in Moodle version 3.0?
  1078. //TODO: Incorrect property 'grademax' found when inserting grade object
  1079. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1080. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1081. }
  1082. /// Update grade of student
  1083. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1084. global $CFG, $DB, $OUTPUT;
  1085. require_once($CFG->libdir . '/gradelib.php');
  1086. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1087. // Review all the student submission for this iAssign activity
  1088. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1089. $total_grade = 0;
  1090. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1091. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1092. if ($iassign_submission)
  1093. $total_grade += $iassign_submission->grade;
  1094. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1095. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1096. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1097. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1098. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1099. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1100. $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
  1101. if (key($array_sum_grade))
  1102. $sum_grade = key($array_sum_grade); //2
  1103. else
  1104. $sum_grade = 0; //2
  1105. $grades['userid'] = $userid;
  1106. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1107. $params = array('itemname' => $grade_iassign->name);
  1108. $params['iteminstance'] = $iassignid;
  1109. $params['gradetype'] = GRADE_TYPE_VALUE;
  1110. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1111. $params['grademax'] = $sum_grade;
  1112. $params['rawgrademax'] = $sum_grade;
  1113. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1114. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1115. }
  1116. /// Display caption of icons
  1117. function view_legend_icons () {
  1118. global $USER, $CFG, $DB, $OUTPUT;
  1119. $id = $this->cm->id;
  1120. if ($this->action == 'print')
  1121. print '<table border=1 width=100%><tr>';
  1122. else
  1123. print '<table width=100%><tr>';
  1124. print '<td >';
  1125. if ($this->action != 'print')
  1126. print $OUTPUT->help_icon('legend', 'iassign');
  1127. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1128. // $imagetext = '');
  1129. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1130. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1131. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1132. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1133. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1134. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1135. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1136. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1137. print '</td>' . "\n";
  1138. if ($this->action != 'print') {
  1139. $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>";
  1140. $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>";
  1141. $link_export = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=export_csv&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('export_ilm') . '&nbsp;' . get_string('export_csv', 'iassign') . "</a>";
  1142. $link_auto_evaluate = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=auto_evaluate&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('correct') . '&nbsp;' . get_string('auto_evaluate_reprocess', 'iassign') . "</a>";
  1143. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1144. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1145. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1146. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1147. } // if ($this->action != 'print')
  1148. print '</tr></table>' . "\n";
  1149. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1150. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1151. $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>";
  1152. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1153. print '</tr></table>' . "\n";
  1154. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1155. else
  1156. print '</td></tr></table>' . "\n";
  1157. } // function view_legend_icons()
  1158. /// Display activity current
  1159. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1160. function view_iassign_current () {
  1161. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1162. $id = $this->cm->id;
  1163. $iassignid = $this->iassign->id;
  1164. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1165. $iassign = $DB->get_record("iassign", array("id" => $iassignid)); // from table '*_iassign': id course name intro introformat activity_group grade timeavailable timedue preventlate test max_experiment
  1166. // Get data of current activity : table '*_iassign_statement' = id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid file grade timemodified timecreated ...
  1167. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1168. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1169. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1170. // 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
  1171. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1172. // log record
  1173. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1174. //Trigger module viewed event.
  1175. $event = \mod_iassign\event\submission_viewed::create(array(
  1176. 'objectid' => $iassign->id,
  1177. 'context' => $this->context,
  1178. 'other' => $info
  1179. ));
  1180. $event->add_record_snapshot('course', $this->course);
  1181. $event->trigger();
  1182. print $OUTPUT->header();
  1183. // Search of iLM data used in the current activity
  1184. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1185. if ($this->action == 'viewsubmission') {
  1186. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1187. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1188. else
  1189. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1190. } else {
  1191. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1192. }
  1193. if ($iassign_submission)
  1194. $this->update_comment($iassign_submission->id);
  1195. $file = $iassign_statement_activity_item->file;
  1196. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1197. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1198. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1199. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1200. $this->bottonPost = 0; // hide submit button
  1201. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1202. $this->view_iassign = false; // disable visualization of activity
  1203. $repeat = "";
  1204. $last_iassign = "";
  1205. $student_answer = "";
  1206. $comment = "";
  1207. // *** Teacher access (view learner's submission)
  1208. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1209. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1210. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1211. // ---> access teacher for test
  1212. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1213. $this->bottonPost = 1;
  1214. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1215. $this->activity->view_dates();
  1216. $USER->iassignEdit = $this->bottonPost;
  1217. $this->activity->show_info_iassign();
  1218. if ($iassign_submission) {
  1219. //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;
  1220. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1221. } else {
  1222. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1223. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1224. }
  1225. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1226. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1227. // Prepare tags to present the iLM
  1228. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1229. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1230. // *** (end) Teacher access (view the activity)
  1231. // *** Teacher access (view learner's submission to the activity)
  1232. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1233. // It is teacher or 'nonediting teacher' that can evaluate
  1234. // ----> area teacher evaluate
  1235. $row = optional_param('row', 0, PARAM_INT);
  1236. $column = optional_param('column', 0, PARAM_INT);
  1237. $link_next = iassign_icons::insert('right_disable');
  1238. $link_previous = iassign_icons::insert('left_disable');
  1239. $link_up = iassign_icons::insert('up_disable');
  1240. $link_down = iassign_icons::insert('down_disable');
  1241. // next_activity
  1242. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1243. $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);
  1244. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1245. }
  1246. // previous_activity
  1247. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1248. $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);
  1249. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1250. }
  1251. // previous_student
  1252. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1253. $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);
  1254. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1255. }
  1256. // next_student
  1257. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1258. $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);
  1259. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1260. }
  1261. if ($iassign_submission) {
  1262. $student_answer = $iassign_submission->answer;
  1263. }
  1264. $last_iassign = get_string('last_iassign', 'iassign');
  1265. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1266. // Messages related to due date (and user role)
  1267. $this->activity->view_dates();
  1268. print $OUTPUT->box_start();
  1269. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1270. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1271. print $OUTPUT->user_picture($user_data);
  1272. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1273. print '</td>' . "\n";
  1274. print '<td width=20% align=right>' . "\n";
  1275. print '<table width=50 cellpadding="0">';
  1276. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1277. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1278. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1279. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1280. print '</table>' . "\n";
  1281. print '</td></tr></table>' . "\n";
  1282. print $OUTPUT->box_end();
  1283. print $OUTPUT->box_start();
  1284. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1285. print '<td width=60% valign="top">' . "\n";
  1286. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1287. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1288. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1289. $resp = get_string('yes');
  1290. else
  1291. $resp = get_string('no');
  1292. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1293. if ($iassign_statement_activity_item->show_answer == 1)
  1294. $resp = get_string('yes');
  1295. else
  1296. $resp = get_string('no');
  1297. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1298. print '</td>';
  1299. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1300. print '<td width=40% valign="top" align="left">';
  1301. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1302. // check status of solution sent by the student
  1303. if ($iassign_submission) {
  1304. switch ($iassign_submission->status) {
  1305. case 3 :
  1306. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1307. break;
  1308. case 2 :
  1309. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1310. break;
  1311. case 1 :
  1312. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1313. break;
  1314. default :
  1315. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1316. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1317. } // switch ($iassign_submission->status)
  1318. }
  1319. else { // if ($iassign_submission)
  1320. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1321. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1322. }
  1323. // update_status
  1324. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1325. $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);
  1326. print " <script type='text/javascript'>
  1327. //<![CDATA[
  1328. function overwriteStatus (newstatus) {
  1329. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1330. document.formEditStatus.return_status.value=newstatus;
  1331. document.formEditStatus.submit();
  1332. }
  1333. else
  1334. document.formEditStatus.return_status.value=-1;
  1335. }
  1336. //]]>
  1337. </script>";
  1338. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1339. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1340. 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";
  1341. print " <input type='hidden' name='return_status'>\n";
  1342. print "</form>\n";
  1343. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1344. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1345. $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);
  1346. print "
  1347. <script type='text/javascript'>
  1348. //<![CDATA[
  1349. function overwriteGrade (newgrade,maxgrade) {
  1350. if (newgrade<0 || newgrade>maxgrade) {
  1351. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1352. document.formEditGrade.return_grade.value=-1;
  1353. document.formEditGrade.submit();
  1354. }
  1355. else {
  1356. document.formEditGrade.return_grade.value=newgrade;
  1357. document.formEditGrade.submit();
  1358. }
  1359. }
  1360. //]]>
  1361. </script>";
  1362. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1363. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1364. print " <input type='text' name='grade' size='6'>";
  1365. print " <input type='hidden' name='return_grade'> ";
  1366. 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";
  1367. print "</form>";
  1368. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1369. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1370. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1371. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1372. if ($teacher)
  1373. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1374. } // if ($iassign_submission->experiment > 0)
  1375. print '</td>';
  1376. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1377. print '</tr></table>';
  1378. print $OUTPUT->box_end();
  1379. $USER->iassignEdit = $this->bottonPost;
  1380. if ($iassign_submission && $allow_resubmission) {
  1381. // Put the iLM to
  1382. print $OUTPUT->box_start();
  1383. print '<p><strong>' . $last_iassign . '</strong></p>';
  1384. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1385. $enderecoPOST = "";
  1386. // Prepare tags to present the iLM
  1387. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1388. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1389. print $OUTPUT->box_end();
  1390. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1391. // ATTENTION: exception used by iGeom (exercise with "script")
  1392. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1393. if (substr($ilm_name, 0, 5)=="igeom") {
  1394. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1395. $loadTeacherActivity = true;
  1396. }
  1397. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1398. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1399. // Prepare tags to present the iLM
  1400. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1401. }
  1402. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1403. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1404. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1405. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1406. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1407. // *** (end) Teacher access (view learner's submission to the activity)
  1408. // *** Student access (view the activity)
  1409. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1410. // It could be the learner (he could send or resend the activity)
  1411. // ---> access student
  1412. $time_now = time();
  1413. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1414. // activity of type example - not submit button for submission
  1415. $this->view_iassign = true;
  1416. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1417. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1418. // activity of type test - iLM automatic evaluator - submit button for submission
  1419. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1420. $this->bottonPost = 1;
  1421. $this->view_iassign = true;
  1422. } else
  1423. $this->view_iassign = false;
  1424. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1425. // activity of type exercise (learner can send his answer, if yet open...)
  1426. $this->view_iassign = true;
  1427. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1428. $this->view_iassign = false;
  1429. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1430. $this->bottonPost = 1; // allow the submit button
  1431. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1432. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1433. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1434. if (!$iassign_submission) {
  1435. $str_iassign_submission_id = '';
  1436. $str_iassign_submission_answer = '';
  1437. }
  1438. else {
  1439. $str_iassign_submission_id = $iassign_submission->id;
  1440. $str_iassign_submission_answer = $iassign_submission->answer;
  1441. }
  1442. if ($this->action != 'repeat') {
  1443. $repeat = "<a href='view.php?action=repeat&id="
  1444. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1445. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1446. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1447. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1448. }
  1449. $this->bottonPost = 1;
  1450. $this->write_solution = 1; // can register his submission
  1451. $student_answer = $str_iassign_submission_answer;
  1452. }
  1453. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1454. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1455. $last_iassign = get_string('last_iassign', 'iassign');
  1456. if ($iassign_submission) {
  1457. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1458. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1459. $student_answer = $iassign_submission->answer;
  1460. } else {
  1461. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1462. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1463. }
  1464. }
  1465. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1466. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1467. $this->bottonPost = 1;
  1468. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1469. } else {
  1470. $last_iassign = get_string('last_iassign', 'iassign');
  1471. if ($iassign_submission) {
  1472. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1473. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1474. $student_answer = $iassign_submission->answer;
  1475. } else {
  1476. // Symbol of "redo activity"
  1477. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1478. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1479. }
  1480. }
  1481. } // elseif ($iassign_statement_activity_item->test == 1)
  1482. elseif ($iassign_statement_activity_item->test == 0)
  1483. $this->view_iassign = false;
  1484. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1485. if ($iassign_submission)
  1486. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1487. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1488. else
  1489. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1490. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1491. $this->view_legend_icons();
  1492. $this->activity->view_dates();
  1493. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1494. print $OUTPUT->box_start();
  1495. print '<table width=100% border=0 valign="top">' . "\n";
  1496. print '<tr><td width=60% valign="top">' . "\n";
  1497. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1498. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1499. $flag_dependency = true;
  1500. if ($iassign_statement_activity_item->type_iassign == 3) {
  1501. if ($iassign_statement_activity_item->dependency == 0) {
  1502. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1503. } else {
  1504. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1505. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1506. foreach ($dependencys as $dependency) {
  1507. if ($dependency) {
  1508. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1509. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1510. if ($dependencysubmissions) {
  1511. if ($dependencysubmissions->status == 3)
  1512. $icon = iassign_icons::insert('correct');
  1513. elseif ($dependencysubmissions->status == 2) {
  1514. $icon = iassign_icons::insert('incorrect');
  1515. $flag_dependency = false;
  1516. } elseif ($dependencysubmissions->status == 1) {
  1517. $icon = iassign_icons::insert('post');
  1518. $flag_dependency = false;
  1519. } elseif ($dependencysubmissions->status == 0) {
  1520. $icon = iassign_icons::insert('not_post');
  1521. $flag_dependency = false;
  1522. }
  1523. } else {
  1524. $icon = iassign_icons::insert('not_post');
  1525. $flag_dependency = false;
  1526. } // if ($dependencysubmissions)
  1527. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1528. } // if ($dependency)
  1529. } // foreach ($dependencys as $dependency)
  1530. } // if ($iassign_statement_activity_item->dependency == 0)
  1531. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1532. if ($flag_dependency == false) {
  1533. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1534. $this->view_iassign = false;
  1535. print '</tr></table>' . "\n";
  1536. }
  1537. else {
  1538. $this->view_iassign = true;
  1539. print '</td>' . "\n";
  1540. } // if ($flag_dependency == false)
  1541. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1542. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1543. // receiver=1 - message to teacher
  1544. // receiver=2 - message to student
  1545. if ($iassign_submission) {
  1546. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1547. if ($verify_message)
  1548. $comment = iassign_icons::insert('comment_unread');
  1549. }
  1550. print '<td width=40% valign="top" align="left">';
  1551. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1552. if ($iassign_statement_activity_item->show_answer == 1) {
  1553. // check status of solution sent by the student
  1554. if ($iassign_submission) {
  1555. switch ($iassign_submission->status) {
  1556. case 3 :
  1557. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1558. break;
  1559. case 2 :
  1560. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1561. break;
  1562. case 1 :
  1563. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1564. break;
  1565. default :
  1566. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1567. $repeat = "";
  1568. $last_iassign = "";
  1569. } // switch ($iassign_submission->status)
  1570. } else {
  1571. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1572. $repeat = "";
  1573. $last_iassign = "";
  1574. }
  1575. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1576. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  1577. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  1578. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  1579. if ($iassign_statement_activity_item->max_experiment == 0)
  1580. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  1581. else {
  1582. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  1583. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  1584. $repeat = "";
  1585. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  1586. $this->bottonPost = 0;
  1587. $this->write_solution = 0;
  1588. }
  1589. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  1590. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  1591. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1592. if ($teacher)
  1593. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  1594. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  1595. } // if ($iassign_statement_activity_item->show_answer==1)
  1596. else {
  1597. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  1598. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1599. $repeat = "";
  1600. $last_iassign = "";
  1601. } elseif ($iassign_submission->status == 1) {
  1602. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1603. }
  1604. }
  1605. print '</td>';
  1606. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1607. print '</tr></table>' . "\n";
  1608. // Presents the iLM
  1609. print '<table width=100% border=0 valign="top">' . "\n";
  1610. print '<td width=80% align="left">';
  1611. 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\".
  1612. print '<td width=20% align="rigth">';
  1613. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  1614. print $repeat; // symbol of "redo activity"
  1615. print '</td></tr></table>' . "\n";
  1616. //2019 print $OUTPUT->box_end(); // closing Box 5 but sometimes it does reach this point - see it at the end of 'if ($this->view_iassign)'
  1617. $output = '';
  1618. if (!$iassign_ilm) {
  1619. $iassign_ilm = new stdClass();
  1620. $iassign_ilm->file_jar = "";
  1621. }
  1622. $output .= $OUTPUT->box_start();
  1623. $USER->iassignEdit = $this->bottonPost;
  1624. // ---
  1625. // Presents the iLM
  1626. // Prepare tags to present the iLM
  1627. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  1628. $student_answer = ""; //?
  1629. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  1630. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  1631. $student_answer = "";
  1632. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  1633. } else {
  1634. // When student is redoing his activity
  1635. // ATTENTION: exception used by iGeom (exercise with "script")
  1636. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  1637. if (substr($ilm_name, 0, 5)=="igeom") {
  1638. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1639. $loadTeacherActivity = true;
  1640. }
  1641. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  1642. }
  1643. if ($iassign_statement_activity_item->type_iassign == 3) {
  1644. $history_comment = '';
  1645. if ($iassign_submission) {
  1646. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1647. }
  1648. if (!empty($history_comment)) {
  1649. $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  1650. " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  1651. $output .= $history_comment;
  1652. $output .= "</table>\n";
  1653. }
  1654. $output .= "</form></center>\n";
  1655. $output .= $OUTPUT->box_end();
  1656. print $output;
  1657. $only_one_send_button = 1; // avoid put comment frame again (bellow)
  1658. } else { // if ($iassign_statement_activity_item->type_iassign == 3)
  1659. $output .= $OUTPUT->box_end();
  1660. print $output;
  1661. }
  1662. } // if ($this->view_iassign)
  1663. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  1664. } // if ($this->view_iassign)
  1665. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1666. else
  1667. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1668. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  1669. print '<table width=100% border=0 valign="top">' . "\n";
  1670. print '<tr><td width=60% valign="top">' . "\n";
  1671. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1672. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1673. print '</tr></table>' . "\n";
  1674. $student_answer = "";
  1675. $enderecoPOST = "";
  1676. // Prepare tags to present the iLM
  1677. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  1678. print $output;
  1679. }
  1680. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  1681. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1682. if ($only_one_send_button==0 && $iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1683. // Put a block with area to sent/answer comments
  1684. $output = '';
  1685. $history_comment = '';
  1686. $row = optional_param('row', 0, PARAM_INT);
  1687. $column = optional_param('column', 0, PARAM_INT);
  1688. if ($iassign_submission) {
  1689. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1690. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1691. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1692. }
  1693. else {
  1694. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1695. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1696. }
  1697. $output .= $OUTPUT->box_start();
  1698. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  1699. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  1700. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  1701. $output .= "</form></center>\n";
  1702. if (!empty($history_comment)) {
  1703. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  1704. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  1705. $output .= $history_comment;
  1706. $output .= "</table>";
  1707. }
  1708. $output .= $OUTPUT->box_end();
  1709. print $output;
  1710. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1711. // final block 'studant'
  1712. print $OUTPUT->footer();
  1713. die();
  1714. } // function view_iassign_current()
  1715. /// Export the data from performance report into CSV file format
  1716. function export_csv () {
  1717. global $USER, $CFG, $DB, $OUTPUT;
  1718. $str = "";
  1719. $fields = "student_id, student_name";
  1720. // Finding all iassign activities for the iassign:
  1721. $id = $this->cm->id;
  1722. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1723. $c = 1;
  1724. foreach ($iassign_list as $iassign) {
  1725. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  1726. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  1727. $c ++;
  1728. }
  1729. // Finding enrolled students:
  1730. $params = array('shortname' => 'student');
  1731. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  1732. $context = context_course::instance($this->course->id);
  1733. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1734. $students = $DB->get_records_sql(
  1735. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1736. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1737. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1738. foreach ($students as $student) {
  1739. $str .= $student->userid . ',';
  1740. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  1741. foreach ($iassign_list as $iassign) {
  1742. $str .= ',' . $iassign->id . ',';
  1743. $str .= '"' . $iassign->name . '",';
  1744. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  1745. $str .= $student_submissions->experiment . ',';
  1746. $str .= $student_submissions->grade . ',';
  1747. switch ($student_submissions->status) {
  1748. case 3:
  1749. $str .= '"correct",';
  1750. break;
  1751. case 2:
  1752. $str .= '"incorrect",';
  1753. break;
  1754. case 1:
  1755. $str .= '"post",';
  1756. break;
  1757. case 0:
  1758. $str .= '"not_post",';
  1759. break;
  1760. }
  1761. $str .= $iassign->iassign_ilmid . ',';
  1762. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  1763. $str .= '"' . $ilm_activity->name . '"';
  1764. }
  1765. $str .= "\n";
  1766. }
  1767. $str = $fields . "\n" . $str;
  1768. header("Content-disposition: attachment; filename=report.csv");
  1769. header("Pragma: no-cache");
  1770. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  1771. header('Content-Length: ' . strlen($str));
  1772. header('Connection: close');
  1773. print $str;
  1774. flush();
  1775. } // function export_csv()
  1776. /// Display report of performance
  1777. function report () {
  1778. global $USER, $CFG, $DB, $OUTPUT;
  1779. $id = $this->cm->id;
  1780. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1781. if ($this->action != 'print') {
  1782. $title = get_string('report', 'iassign');
  1783. print $OUTPUT->header();
  1784. } // if ($this->action != 'print')
  1785. print $OUTPUT->box_start();
  1786. $this->view_legend_icons();
  1787. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  1788. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  1789. print $OUTPUT->box_end();
  1790. if ($this->action == 'print')
  1791. print '<table border=1 width="100%">' . "\n";
  1792. else
  1793. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1794. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  1795. // $num = array();
  1796. $i = 1;
  1797. $num = array();
  1798. foreach ($iassign_list as $iassign) {
  1799. $test_exercise = "";
  1800. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  1801. if (($iassign_submission) && $iassign->type_iassign < 3) {
  1802. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  1803. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  1804. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  1805. $num[$i] = new stdClass();
  1806. $num[$i]->name = $iassign->name;
  1807. $num[$i]->id = $i;
  1808. $num[$i]->iassignid = $iassign->id;
  1809. print ' <tr >' . "\n";
  1810. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  1811. print "<td class=\"cell c0 actvity\">";
  1812. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  1813. print ' </tr>' . "\n";
  1814. $i ++;
  1815. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  1816. } // foreach ($iassign_list as $iassign)
  1817. print "</table>";
  1818. print "<p></p>";
  1819. if ($this->action == 'print')
  1820. print '<table border=1 width="100%">' . "\n";
  1821. else
  1822. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1823. $context = context_course::instance($this->course->id);
  1824. if ($i > 1) {
  1825. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  1826. $params = array('shortname' => 'student');
  1827. $role = $DB->get_record_sql(
  1828. "SELECT s.id, s.shortname FROM {role} s " .
  1829. " WHERE s.shortname = :shortname", $params);
  1830. // $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");
  1831. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1832. $students = $DB->get_records_sql(
  1833. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1834. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1835. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1836. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  1837. for ($j = 1; $j < $i; $j ++) {
  1838. $sum_iassign_correct[$j] = 0;
  1839. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  1840. }
  1841. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  1842. $sum_iassign = $j - 1;
  1843. print '</tr>' . "\n";
  1844. $total = 0;
  1845. $sum_student = 0;
  1846. $comment = iassign_icons::insert('comment_read');
  1847. $sum_comment = 0;
  1848. $sum_correct_iassign = array();
  1849. $sum_correct_student = array();
  1850. $USER->matrix_iassign = array();
  1851. if ($students) {
  1852. $w = 0;
  1853. foreach ($students as $tmp) {
  1854. $users_array[$w] = $tmp;
  1855. $w ++;
  1856. }
  1857. for ($x = 0; $x < $w; $x ++) {
  1858. print '<tr>' . "\n";
  1859. $sum_student ++;
  1860. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  1861. print ' <td >' . $name . '</td>' . "\n";
  1862. $total_student = 0;
  1863. $tentativas = 0;
  1864. for ($j = 1; $j < $i; $j ++) {
  1865. $sum_comment = 0;
  1866. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  1867. print ' <td valign="bottom" align="center">' . "\n";
  1868. if ($student_submissions) {
  1869. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  1870. $tentativas = $student_submissions->experiment;
  1871. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  1872. $params = array('iassign_submissionid' => $student_submissions->id);
  1873. $student_submissions_comment = $DB->get_record_sql(
  1874. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1875. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  1876. if ($student_submissions_comment)
  1877. foreach ($student_submissions_comment as $tmp)
  1878. $sum_comment = $tmp;
  1879. // informations to previous activities
  1880. if ($j - 1 < 1 || $j == $i)
  1881. $iassign_previous = "-1";
  1882. else
  1883. $iassign_previous = $num[$j - 1]->iassignid;
  1884. if ($x - 1 < 0 || $x == $w)
  1885. $user_previous = "-1";
  1886. else
  1887. $user_previous = $users_array[$x - 1]->userid;
  1888. // next
  1889. if ($i - 1 > $j)
  1890. $iassign_next = $num[$j + 1]->iassignid;
  1891. else
  1892. $iassign_next = "-1";
  1893. if ($w - 1 > $x)
  1894. $user_next = $users_array[$x + 1]->userid;
  1895. else
  1896. $user_next = "-1";
  1897. $position = "&row= $x&column=$j";
  1898. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  1899. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1900. $url .= $position;
  1901. // receiver=1 - message to teacher
  1902. // receiver=2 - message to student
  1903. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  1904. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  1905. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  1906. $verify_message = $DB->get_record_sql(
  1907. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1908. "WHERE iassign_submissionid = :iassign_submissionid " .
  1909. " AND return_status= :return_status " .
  1910. " AND receiver= :receiver", $params);
  1911. if ($verify_message)
  1912. foreach ($verify_message as $tmp)
  1913. $sum_verify_message = $tmp;
  1914. if ($sum_verify_message > 0)
  1915. $comment = iassign_icons::insert('comment_unread');
  1916. else
  1917. $comment = iassign_icons::insert('comment_read');
  1918. if ($student_submissions->status == 3) {
  1919. $sum_iassign_correct[$j] ++;
  1920. $total_student ++;
  1921. $feedback = iassign_icons::insert('correct');
  1922. }
  1923. elseif ($student_submissions->status == 2) {
  1924. $feedback = iassign_icons::insert('incorrect');
  1925. }
  1926. elseif ($student_submissions->status == 1) {
  1927. $feedback = iassign_icons::insert('post');
  1928. }
  1929. elseif ($student_submissions->status == 0) {
  1930. $feedback = iassign_icons::insert('not_post');
  1931. }
  1932. if ($this->action != 'print') {
  1933. print '<table><tr>';
  1934. if ($tentativas > 0)
  1935. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  1936. else
  1937. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  1938. print '<td> &nbsp; </td>';
  1939. print '</tr>' . "\n";
  1940. if ($sum_comment > 0 && $sum_verify_message > 0)
  1941. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  1942. else if ($sum_comment > 0)
  1943. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  1944. print '</table>' . "\n";
  1945. }
  1946. if ($this->action == 'print')
  1947. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1948. } // if ($student_submissions)
  1949. else { // if ($student_submissions)
  1950. // informations to browse previous activities
  1951. if ($j - 1 < 1 || $j == $i)
  1952. $iassign_previous = "-1";
  1953. else
  1954. $iassign_previous = $num[$j - 1]->iassignid;
  1955. if ($x - 1 < 0 || $x == $w)
  1956. $user_previous = "-1";
  1957. else
  1958. $user_previous = $users_array[$x - 1]->userid;
  1959. // next
  1960. if ($i - 1 > $j)
  1961. $iassign_next = $num[$j + 1]->iassignid;
  1962. else
  1963. $iassign_next = "-1";
  1964. if ($w - 1 > $x)
  1965. $user_next = $users_array[$x + 1]->userid;
  1966. else
  1967. $user_next = "-1";
  1968. $position = "&row= $x&column=$j";
  1969. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  1970. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1971. $url .= $position;
  1972. $feedback = iassign_icons::insert('not_post');
  1973. if ($this->action == 'print')
  1974. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1975. else {
  1976. print '<table><tr>';
  1977. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  1978. print '<td> &nbsp; </td>';
  1979. print '</tr><tr>' . "\n";
  1980. print '<td> &nbsp;</td>';
  1981. if ($sum_comment > 0)
  1982. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  1983. else
  1984. print '<td> &nbsp;</td>';
  1985. print '</tr></table>';
  1986. }
  1987. } // else if ($student_submissions)
  1988. $USER->matrix_iassign[$x][$j] = new stdClass();
  1989. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  1990. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  1991. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  1992. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  1993. if ($student_submissions)
  1994. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  1995. else
  1996. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  1997. print '</td>' . "\n";
  1998. } // for ($j=1; $j<$i; $j++)
  1999. $total = $total + $total_student;
  2000. $porcentagem = ($total_student / ($j - 1)) * 100;
  2001. if ($tentativas != 0 && $tentativas != null) {
  2002. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2003. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2004. }
  2005. else {
  2006. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2007. }
  2008. print '</tr>' . "\n";
  2009. $sum_correct_student[$sum_student] = new stdClass();
  2010. $sum_correct_student[$sum_student]->name = $name;
  2011. $sum_correct_student[$sum_student]->sum = $total_student;
  2012. } // for ($x = 0; $x < $w; $x ++)
  2013. for ($i = 1; $i < $j; $i ++) {
  2014. if (is_null($sum_iassign_correct[$i]))
  2015. $sum_iassign_correct[$i] = 0;
  2016. $sum_correct_iassign[$i] = new stdClass();
  2017. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2018. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2019. }
  2020. // print '</tr></table>' . "\n";
  2021. }
  2022. } // if ($i>1)
  2023. else {
  2024. print_string('no_activity', 'iassign');
  2025. }
  2026. print "</table>\n";
  2027. if ($this->action != 'print')
  2028. print $OUTPUT->footer();
  2029. die();
  2030. } // function report()
  2031. /// Display graphics of performance
  2032. function stats () {
  2033. global $USER, $CFG, $DB, $OUTPUT;
  2034. $id = $this->cm->id;
  2035. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2036. if ($this->action != 'printstats')
  2037. $title = get_string('graphic', 'iassign');
  2038. $num = array();
  2039. $sum_correct_iassign = array();
  2040. $sum_correct_student = array();
  2041. $sum_student = 0;
  2042. $i = 1;
  2043. foreach ($iassign_list as $iassign) {
  2044. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2045. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2046. $sum_iassign_correct[$i] = 0;
  2047. $num[$i] = new stdClass();
  2048. $num[$i]->name = $iassign->name;
  2049. $num[$i]->id = $i;
  2050. $num[$i]->iassignid = $iassign->id;
  2051. $i ++;
  2052. } // if ($iassign->type_iassign == 3)
  2053. } // foreach ($iassign_list as $iassign)
  2054. $sum_iassign = $i - 1;
  2055. $context = context_course::instance($this->course->id);
  2056. if ($i > 1) {
  2057. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2058. $params = array('shortname' => 'student');
  2059. $role = $DB->get_record_sql(
  2060. "SELECT s.id, s.shortname FROM {role} s " .
  2061. " WHERE s.shortname = :shortname", $params);
  2062. // $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");
  2063. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2064. $students = $DB->get_records_sql(
  2065. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2066. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2067. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2068. $total = 0;
  2069. $sum_student = 0;
  2070. $j = 0;
  2071. $sum_correct_iassign = array();
  2072. $sum_correct_student = array();
  2073. $sum_experiment = array();
  2074. if ($students) {
  2075. foreach ($students as $users) {
  2076. $sum_student ++;
  2077. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2078. // rows
  2079. $total_student = 0;
  2080. for ($j = 1; $j < $i; $j ++) {
  2081. $total_experiment = 0;
  2082. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2083. if ($student_submissions) {
  2084. if ($student_submissions->status == 3) {
  2085. $sum_iassign_correct[$j] ++;
  2086. $total_student ++;
  2087. } // if ($student_submissions->status == 3)
  2088. $total_experiment += $student_submissions->experiment;
  2089. }
  2090. $sum_experiment[$j] = $total_experiment;
  2091. } // for ($j=1; $j<$i; $j++)
  2092. $total = $total + $total_student;
  2093. $sum_correct_student[$sum_student] = new stdClass();
  2094. $sum_correct_student[$sum_student]->name = $name;
  2095. $sum_correct_student[$sum_student]->sum = $total_student;
  2096. } // foreach ($students as $users)
  2097. }
  2098. for ($i = 1; $i < $j; $i ++) {
  2099. if (is_null($sum_iassign_correct[$i]))
  2100. $sum_iassign_correct[$i] = 0;
  2101. $sum_correct_iassign[$i] = new stdClass();
  2102. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2103. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2104. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2105. } // for ($i = 1; $i < $j; $i++)
  2106. } // if ($i > 1)
  2107. if ($this->action != 'printstats') {
  2108. $title = get_string('graphic', 'iassign');
  2109. print $OUTPUT->header();
  2110. $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>";
  2111. $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>";
  2112. print '<table width=100%><tr>';
  2113. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2114. print '<td width=15% align="right">' . $link_report . '</td>';
  2115. print '</td></tr></table>' . "\n";
  2116. print "<br><br>";
  2117. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2118. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2119. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2120. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2121. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2122. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2123. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2124. print '</tr>' . "\n";
  2125. $sum_correct = 0;
  2126. if ($sum_correct_iassign) {
  2127. foreach ($sum_correct_iassign as $iassign) {
  2128. if (is_null($iassign->experiment))
  2129. $iassign->experiment = 0;
  2130. $bar = "";
  2131. $sum = $iassign->sum;
  2132. $percent = ($sum / $sum_student) * 100;
  2133. $text = number_format($percent, 1) . '%';
  2134. $sum_correct += $sum;
  2135. if ($sum > 0) {
  2136. for ($i = 1; $i < $percent * 2; $i ++)
  2137. $bar .= iassign_icons::insert('hbar_blue');
  2138. $bar .= iassign_icons::insert('hbar_blue_r');
  2139. } // if ($sum > 0)
  2140. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2141. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2142. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2143. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2144. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2145. print '</tr>' . "\n";
  2146. } // foreach ($sum_correct_iassign as $iassign)
  2147. }
  2148. print "</table>";
  2149. print "<br><br>";
  2150. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2151. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2152. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2153. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2154. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2155. print '</tr>' . "\n";
  2156. $sum_correct = 0;
  2157. foreach ($sum_correct_student as $student) {
  2158. $bar = "";
  2159. $sum = $student->sum;
  2160. $percent = ($sum / $sum_iassign) * 100;
  2161. $text = number_format($percent, 1) . '%';
  2162. $sum_correct += $sum;
  2163. if ($sum > 0) {
  2164. for ($i = 1; $i < $percent * 2; $i ++)
  2165. $bar .= iassign_icons::insert('hbar_blue');
  2166. $bar .= iassign_icons::insert('hbar_blue_r');
  2167. } // if ($sum > 0)
  2168. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2169. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2170. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2171. print '</tr>' . "\n";
  2172. } // foreach ($sum_correct_student as $student)
  2173. print "</table>\n";
  2174. print "<br><br>\n";
  2175. $var = 0;
  2176. $cv = 0;
  2177. $dv = 0;
  2178. $avg = 0;
  2179. if ($sum_correct_student) {
  2180. $avg = $sum_correct / $sum_student;
  2181. if ($avg > 0) {
  2182. foreach ($sum_correct_student as $student)
  2183. $var += pow($student->sum - $avg, 2);
  2184. $var = $var / $sum_student;
  2185. $dv = sqrt($var);
  2186. $cv = ($dv / $avg) * 100;
  2187. }
  2188. }
  2189. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2190. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2191. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2192. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2193. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2194. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2195. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2196. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2197. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2198. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2199. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2200. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2201. print "</table>\n";
  2202. print $OUTPUT->footer();
  2203. } else {
  2204. print "<STYLE TYPE='text/css'>
  2205. <!--
  2206. .boldtable {
  2207. font-family:sans-serif;
  2208. font-size:10pt;
  2209. }
  2210. -->
  2211. </STYLE>\n";
  2212. print '<table border=1 width=100%>' . "\n";
  2213. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2214. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2215. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2216. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2217. print '</tr>' . "\n";
  2218. $sum_correct = 0;
  2219. foreach ($sum_correct_iassign as $iassign) {
  2220. $bar = "";
  2221. $sum = $iassign->sum;
  2222. $percent = ($sum / $sum_student) * 100;
  2223. $text = number_format($percent, 1) . '%';
  2224. $sum_correct += $sum;
  2225. if ($sum > 0) {
  2226. for ($i = 1; $i < $percent * 2; $i ++)
  2227. $bar .= iassign_icons::insert('hbar_blue');
  2228. $bar .= iassign_icons::insert('hbar_blue_r');
  2229. } // if ($sum > 0)
  2230. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2231. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2232. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2233. print '</tr>' . "\n";
  2234. } // foreach ($sum_correct_iassign as $iassign)
  2235. print "</table>";
  2236. print "<br><br>";
  2237. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2238. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2239. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2240. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2241. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2242. print '</tr>' . "\n";
  2243. $sum_correct = 0;
  2244. foreach ($sum_correct_student as $student) {
  2245. $bar = "";
  2246. $sum = $student->sum;
  2247. $percent = ($sum / $sum_iassign) * 100;
  2248. $text = number_format($percent, 1) . '%';
  2249. $sum_correct += $sum;
  2250. if ($sum > 0) {
  2251. for ($i = 1; $i < $percent * 2; $i ++)
  2252. $bar .= iassign_icons::insert('hbar_blue');
  2253. $bar .= iassign_icons::insert('hbar_blue_r');
  2254. } // if ($sum > 0)
  2255. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2256. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2257. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2258. print '</tr>' . "\n";
  2259. } // foreach ($sum_correct_student as $student)
  2260. print "</table>\n";
  2261. print "<br/><br/>\n";
  2262. $var = 0;
  2263. $cv = 0;
  2264. $dv = 0;
  2265. $avg = 0;
  2266. if ($sum_correct_student) {
  2267. $avg = $sum_correct / $sum_student;
  2268. if ($avg > 0) {
  2269. foreach ($sum_correct_student as $student)
  2270. $var += pow($student->sum - $avg, 2);
  2271. $var = $var / $sum_student;
  2272. $dv = sqrt($var);
  2273. $cv = ($dv / $avg) * 100;
  2274. }
  2275. }
  2276. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2277. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2278. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2279. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2280. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2281. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2282. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2283. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2284. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2285. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2286. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2287. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2288. print "</table>\n";
  2289. } // if ($this->action != 'printstats')
  2290. die();
  2291. }
  2292. /// Display graphics of performance for students
  2293. function stats_students () {
  2294. global $USER, $CFG, $DB, $OUTPUT;
  2295. $id = $this->cm->id;
  2296. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2297. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2298. $title = get_string('results', 'iassign');
  2299. $sum_correct = 0;
  2300. $sum_incorrect = 0;
  2301. $sum_post = 0;
  2302. $sum_nopost = 0;
  2303. $sum_iassign = count($iassign_statement_list);
  2304. $bar_nopost = "";
  2305. $bar_correct = "";
  2306. $bar_incorrect = "";
  2307. $bar_post = "";
  2308. $text_nopost = "";
  2309. $text_correct = "";
  2310. $text_incorrect = "";
  2311. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2312. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2313. if ($iassign_submission) {
  2314. if ($iassign_submission->status == 3)
  2315. $sum_correct ++;
  2316. elseif ($iassign_submission->status == 2)
  2317. $sum_incorrect ++;
  2318. elseif ($iassign_submission->status == 1)
  2319. $sum_post ++;
  2320. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2321. $sum_nopost ++;
  2322. } // if ($iassign_submission)
  2323. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2324. if ($sum_iassign > 0) {
  2325. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2326. $text_correct = number_format($percent_correct, 1) . '%';
  2327. }
  2328. if ($sum_correct > 0) {
  2329. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2330. $bar_correct .= iassign_icons::insert('hbar_green');
  2331. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2332. } // if ($sum_correct > 0)
  2333. if ($sum_iassign > 0) {
  2334. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2335. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2336. }
  2337. if ($sum_incorrect > 0) {
  2338. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2339. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2340. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2341. } // if ($sum_incorrect > 0)
  2342. if ($sum_iassign > 0) {
  2343. $percent_post = ($sum_post / $sum_iassign) * 100;
  2344. $text_post = number_format($percent_post, 1) . '%';
  2345. }
  2346. if ($sum_post > 0) {
  2347. for ($i = 1; $i < $percent_post * 2; $i ++)
  2348. $bar_post .= iassign_icons::insert('hbar_blue');
  2349. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2350. } // if ($sum_post > 0)
  2351. if ($sum_iassign > 0) {
  2352. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2353. $text_nopost = number_format($percent_nopost, 1) . '%';
  2354. }
  2355. if ($sum_nopost > 0) {
  2356. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2357. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2358. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2359. } // if ($sum_nopost > 0)
  2360. print $OUTPUT->header();
  2361. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2362. print '<table width=100%><tr>';
  2363. print '<td align="right">' . $link_return . '</td>' . "\n";
  2364. print '</td></tr></table>' . "\n";
  2365. print "<br/><br/>\n";
  2366. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2367. print '<tr><th colspan=3 class="header c1">' . "\n";
  2368. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2369. // $imagetext = '');
  2370. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2371. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2372. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2373. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2374. print '</tr>' . "\n";
  2375. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2376. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2377. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2378. print '</tr>' . "\n";
  2379. if ($sum_post) {
  2380. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2381. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2382. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2383. print '</tr>' . "\n";
  2384. } // if ($sum_post)
  2385. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2386. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2387. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2388. print '</tr>' . "\n";
  2389. print "</table>";
  2390. print "<br><br>";
  2391. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2392. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2393. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2394. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2395. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2396. $sum_grade = 0;
  2397. $sum_grade_student = 0;
  2398. $avg = 0;
  2399. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2400. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2401. if (!$iassign_submission) {
  2402. $iassign_submission = new stdClass();
  2403. $iassign_submission->grade = 0;
  2404. }
  2405. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2406. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2407. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2408. print '</tr>' . "\n";
  2409. $sum_grade += $iassign_statement_activity_item->grade;
  2410. $sum_grade_student += $iassign_submission->grade;
  2411. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2412. if ($sum_grade > 0)
  2413. $avg = $sum_grade_student / $sum_grade * 100;
  2414. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2415. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2416. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2417. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2418. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2419. print "</table>";
  2420. print $OUTPUT->footer();
  2421. die();
  2422. } // function stats_students()
  2423. /// Display page of iAssign's activity
  2424. function view_iassigns () {
  2425. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2426. $id = $this->cm->id;
  2427. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2428. $notice = optional_param('notice', '', PARAM_TEXT);
  2429. if (strpos($notice, 'error'))
  2430. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2431. else if ($notice != '')
  2432. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2433. print $OUTPUT->box_start();
  2434. print '<table width=100% border=0><tr>' . "\n";
  2435. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2436. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2437. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2438. $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>";
  2439. $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>";
  2440. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2441. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2442. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2443. // Has capability to see "report": teacher or up
  2444. print '<td width=10% align="left">' . "\n";
  2445. print $link_help;
  2446. print '</td>' . "\n";
  2447. print '<td width=10% align="left">' . "\n";
  2448. print $link_report;
  2449. print '</td>' . "\n";
  2450. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2451. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2452. print '<td width=15% align="left">' . "\n";
  2453. print $link_add;
  2454. print "</td>\n";
  2455. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2456. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2457. if ($iassign_list) {
  2458. print '<td align="right">' . "\n";
  2459. // $USER->iassignEdit == 0 view 'Turn editing off'
  2460. // $USER->iassignEdit == 1 view 'Turn editing on'
  2461. if (!isset($USER->iassignEdit))
  2462. $USER->iassignEdit = 0;
  2463. if ($USER->iassignEdit == 0) {
  2464. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2465. $botton = 1;
  2466. } // if ($USER->iassignEdit == 0)
  2467. elseif ($USER->iassignEdit == 1) {
  2468. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2469. $botton = 0;
  2470. } // elseif ($USER->iassignEdit == 1)
  2471. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2472. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2473. print " <input type=submit value='$bottonEdit_message'/>\n";
  2474. print "</form>\n";
  2475. print "</td>\n";
  2476. } // if ($iassign_list)
  2477. }
  2478. print '</tr></table>' . "\n";
  2479. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2480. $this->view_legend_icons();
  2481. print $OUTPUT->box_end();
  2482. $iassign_array_exercise = array();
  2483. $i_exercise = 0;
  2484. $iassign_array_test = array();
  2485. $i_test = 0;
  2486. $iassign_array_example = array();
  2487. $i_example = 0;
  2488. $iassign_array_general = array();
  2489. $i_general = 0;
  2490. if ($iassign_list) {
  2491. if ($this->iassign->activity_group == 0) {
  2492. foreach ($iassign_list as $iassign) {
  2493. $iassign_array_general[$i_general] = $iassign;
  2494. $i_general ++;
  2495. }
  2496. } // if ($this->iassign->activity_group == 0)
  2497. else {
  2498. foreach ($iassign_list as $iassign) {
  2499. if ($iassign->type_iassign == 3) {
  2500. $iassign_array_exercise[$i_exercise] = $iassign;
  2501. $i_exercise ++;
  2502. } // if ($iassign->type_iassign == 3)
  2503. if ($iassign->type_iassign == 2) {
  2504. $iassign_array_test[$i_test] = $iassign;
  2505. $i_test ++;
  2506. } // if ($iassign->type_iassign == 2)
  2507. if ($iassign->type_iassign == 1) {
  2508. $iassign_array_example[$i_example] = $iassign;
  2509. $i_example ++;
  2510. } // if ($iassign->type_iassign == 1)
  2511. }
  2512. }
  2513. if ($iassign_array_exercise) {
  2514. $title = get_string('exercise', 'iassign');
  2515. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2516. }
  2517. if ($iassign_array_test) {
  2518. $title = get_string('test', 'iassign');
  2519. $this->show_iassign($title, $iassign_array_test, $i_test);
  2520. }
  2521. if ($iassign_array_example) {
  2522. $title = get_string('example', 'iassign');
  2523. $this->show_iassign($title, $iassign_array_example, $i_example);
  2524. }
  2525. if ($iassign_array_general) {
  2526. $title = "";
  2527. $this->show_iassign($title, $iassign_array_general, $i_general);
  2528. }
  2529. } else { // if ($iassign_list)
  2530. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2531. }
  2532. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2533. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2534. print $OUTPUT->box_start();
  2535. print '<table width=100% border=0><tr>' . "\n";
  2536. print '<td width=10% align="left">' . "\n";
  2537. print $link_report;
  2538. print '</td>' . "\n";
  2539. print '</tr></table>' . "\n";
  2540. print $OUTPUT->box_end();
  2541. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2542. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2543. print $OUTPUT->box_start();
  2544. print '<table width=100% border=0><tr>' . "\n";
  2545. print '<td align="left">' . "\n";
  2546. print $link_add;
  2547. print '</td>' . "\n";
  2548. print '</tr></table>' . "\n";
  2549. print $OUTPUT->box_end();
  2550. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2551. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2552. } // function view_iassigns()
  2553. /// Display all iAssigns
  2554. function show_iassign ($title, $iassign_array, $i) {
  2555. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  2556. $id = $this->cm->id;
  2557. print $OUTPUT->box_start();
  2558. print " <script type='text/javascript'>
  2559. //<![CDATA[
  2560. function validate_move () {
  2561. var radios = document.getElementsByName('iassign_destiny');
  2562. var formValid = false;
  2563. //alert('aqui validate_move()');
  2564. var i = 0;
  2565. while (!formValid && i < radios.length) {
  2566. if (radios[i].checked) formValid = true;
  2567. i++;
  2568. }
  2569. if (!formValid) {
  2570. document.getElementById('move_dest').classList.add('alert-danger');
  2571. }
  2572. return formValid;
  2573. }
  2574. var modal;
  2575. function load_move(id_ias) {
  2576. document.form_move_activity.iassign_current.value = id_ias;
  2577. modal.style.display = 'block';
  2578. var radios = document.getElementsByName('iassign_destiny');
  2579. var i = 0;
  2580. while (i < radios.length) {
  2581. radios[i].checked = false;
  2582. i++;
  2583. }
  2584. document.getElementById('move_dest').classList.remove('alert-danger');
  2585. }
  2586. function load_modal_elements() {
  2587. modal = document.getElementById('myModal');
  2588. var span = document.getElementById('close_modal');
  2589. span.onclick = function() {
  2590. modal.style.display = 'none';
  2591. }
  2592. window.onclick = function(event) {
  2593. if (event.target == modal) {
  2594. modal.style.display = 'none';
  2595. }
  2596. }
  2597. }
  2598. window.onload = load_modal_elements;
  2599. //]]>
  2600. </script>\n";
  2601. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  2602. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  2603. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  2604. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  2605. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  2606. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  2607. <input type='hidden' name='iassign_current' value='' />";
  2608. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  2609. $section = $course_sections[0];
  2610. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  2611. for ($k = 0; $k < count($ids_sections); $k++) {
  2612. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  2613. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  2614. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  2615. if ($c_cm) {
  2616. if ($ccm->instance == $c_cm->instance) {
  2617. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2618. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2619. }
  2620. else {
  2621. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2622. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2623. }
  2624. }
  2625. }
  2626. $radio_buttons .= "</ul>";
  2627. }
  2628. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  2629. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  2630. </form>
  2631. </div></div> </div></div>\n";
  2632. print " <style>.modal {
  2633. display: none;
  2634. position: fixed;
  2635. z-index: 1;
  2636. left: 0;
  2637. top: 0;
  2638. width: 100%;
  2639. height: 100%;
  2640. overflow: scroll;
  2641. background-color: rgb(0,0,0);
  2642. background-color: rgba(0,0,0,0.4);
  2643. }
  2644. .modal-content {
  2645. background-color: #fefefe;
  2646. margin: 15% auto;
  2647. padding: 10px 10px;
  2648. border: 1px solid #888;
  2649. width: 50%;
  2650. }
  2651. #close_modal {
  2652. color: #aaa;
  2653. float: right;
  2654. font-size: 28px;
  2655. font-weight: bold;
  2656. margin-top: -15px;
  2657. margin-right: -3px;
  2658. }
  2659. #close_modal:hover,
  2660. #close_modal:focus {
  2661. color: black;
  2662. text-decoration: none;
  2663. cursor: pointer;
  2664. }
  2665. #modal_title {
  2666. min-height: 3rem;
  2667. color: initial;
  2668. background: initial;
  2669. font-size: 1.5rem;
  2670. line-height: 1.5;
  2671. padding: 15px;
  2672. border-bottom: 1px solid #e5e5e5;
  2673. }
  2674. .input_move {
  2675. width: 90%;
  2676. padding: 2px;
  2677. }
  2678. .input_move:hover {
  2679. background: #eff0ef;
  2680. }
  2681. </style>";
  2682. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2683. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  2684. for ($j = 0; $j < $i; $j ++) {
  2685. $iassign_current = $iassign_array[$j]->id;
  2686. // receiver=1 - message to teacher
  2687. // receiver=2 - message to student
  2688. $sum_comment = 0;
  2689. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  2690. foreach ($iassign_submissions as $iassign_submission) {
  2691. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  2692. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2693. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2694. if ($verify_message)
  2695. foreach ($verify_message as $tmp)
  2696. $sum_comment += $tmp;
  2697. } // foreach ($iassign_submissions as $iassign_submission)
  2698. if ($sum_comment == 0)
  2699. $comment_unread = "";
  2700. else {
  2701. $comment_unread_message = get_string('comment_unread', 'iassign');
  2702. if ($sum_comment == 1)
  2703. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2704. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  2705. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  2706. }
  2707. if ($j == $i - 1)
  2708. $iassign_down = $iassign_array[$j]->id;
  2709. else
  2710. $iassign_down = $iassign_array[$j + 1]->id;
  2711. if ($j > 0)
  2712. $iassign_up = $iassign_array[$j - 1]->id;
  2713. else
  2714. $iassign_up = $iassign_array[$j]->id;
  2715. if ($iassign_array[$j]->visible == 0)
  2716. $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>";
  2717. else
  2718. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2719. $links .= $comment_unread;
  2720. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  2721. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  2722. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  2723. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  2724. if ($j==0) // first activity
  2725. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2726. else
  2727. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2728. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  2729. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  2730. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  2731. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  2732. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  2733. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  2734. if (count($iassign_array) > 1) {
  2735. if ($j == 0)
  2736. $links .= $link_down;
  2737. elseif ($j == $i - 1)
  2738. $links .= $link_up;
  2739. else
  2740. $links .= $link_up . $link_down;
  2741. } // if (count($iassign_array) > 1)
  2742. $links .= $link_edit . $link_delete;
  2743. if ($iassign_array[$j]->visible == 0)
  2744. $links .= $link_visible_show;
  2745. else
  2746. $links .= $link_visible_hide;
  2747. $links .= $link_duplicate_activity . $link_move_activity;
  2748. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2749. print '<p>' . $links . '</p>' . "\n";
  2750. }
  2751. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2752. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  2753. print '<table width=100% ><tr>' . "\n";
  2754. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2755. print '</tr></table>' . "\n";
  2756. for ($j = 0; $j < $i; $j ++) {
  2757. $icon_status = "";
  2758. $icon_comment = "";
  2759. if ($iassign_array[$j]->visible == 1) {
  2760. $iassign_current = $iassign_array[$j]->id;
  2761. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  2762. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2763. $icon_status = "";
  2764. $icon_comment = "";
  2765. if ($iassign_submission) {
  2766. // receiver=1 - message to teacher
  2767. // receiver=2 - message to student
  2768. // $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");
  2769. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  2770. $verify_message = $DB->get_record_sql(
  2771. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2772. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2773. if ($verify_message)
  2774. foreach ($verify_message as $tmp)
  2775. $sum_comment = $tmp;
  2776. if ($sum_comment > 0) {
  2777. $comment_unread_message = get_string('comment_unread', 'iassign');
  2778. if ($sum_comment == 1)
  2779. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2780. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  2781. }
  2782. // $icon_comment = iassign_icons::insert('comment_unread');
  2783. if ($iassign_array[$j]->type_iassign == 3) {
  2784. if ($iassign_array[$j]->show_answer == 1) {
  2785. if ($iassign_submission->status == 3)
  2786. $icon_status = iassign_icons::insert('correct');
  2787. elseif ($iassign_submission->status == 2)
  2788. $icon_status = iassign_icons::insert('incorrect');
  2789. elseif ($iassign_submission->status == 1)
  2790. $icon_status = iassign_icons::insert('post');
  2791. elseif ($iassign_submission->status == 0)
  2792. $icon_status = iassign_icons::insert('not_post');
  2793. } // if ($iassign_array[$j]->show_answer==1)
  2794. else {
  2795. if ($iassign_submission->status == 0)
  2796. $icon_status = iassign_icons::insert('not_post');
  2797. else
  2798. $icon_status = iassign_icons::insert('post');
  2799. }
  2800. } // if ($iassign_array[$j]->type_iassign == 3)
  2801. } // if ($iassign_submission)
  2802. elseif ($iassign_array[$j]->type_iassign == 3) {
  2803. $icon_status = iassign_icons::insert('not_post');
  2804. } // if ($iassign_array[$j]->type_iassign == 3)
  2805. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  2806. } // if ($iassign_array[$j]->visible == 1)
  2807. } // for ($j = 0; $j < $i; $j++)
  2808. } else if (isguestuser()) {
  2809. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2810. print '<table width=100% ><tr>' . "\n";
  2811. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2812. print '</tr></table>' . "\n";
  2813. for ($j = 0; $j < $i; $j ++) {
  2814. $icon_status = "";
  2815. $icon_comment = "";
  2816. if ($iassign_array[$j]->visible == 1) {
  2817. $iassign_current = $iassign_array[$j]->id;
  2818. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2819. print '<p>' . $links . '</p>' . "\n";
  2820. } // if ($iassign_array[$j]->visible == 1)
  2821. }
  2822. }
  2823. print $OUTPUT->box_end();
  2824. } // function show_iassign($title, $iassign_array, $i)
  2825. /// Show message of return
  2826. function return_home_course ($message) {
  2827. //D global $DB, $OUTPUT;
  2828. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2829. //D echo $OUTPUT->box_start();
  2830. //D echo '<table width=100% border=0 valign="top">' . "\n";
  2831. //D echo '<tr><td align="left"><strong>' . "\n";
  2832. //D print_string($message, 'iassign');
  2833. //D echo '</strong></td>' . "\n";
  2834. //D echo '<td width=20% align="right">' . "\n";
  2835. //D echo $link_return;
  2836. //D echo '</td></tr></table>' . "\n";
  2837. //D echo $OUTPUT->box_end();
  2838. //D // echo $OUTPUT->footer();
  2839. redirect(new moodle_url($this->return . '&notice=' . $message));
  2840. exit;
  2841. }
  2842. /// Search comment of activity
  2843. function search_comment_submission ($iassign_submissionid) {
  2844. global $USER, $DB, $OUTPUT, $COURSE;
  2845. // $context = context_course::instance($COURSE->id);
  2846. $colorEdit1 = "#a7bede"; // "#dce7ec"
  2847. $colorEdit2 = "#b7ceee";
  2848. $has_capability = 0;
  2849. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  2850. $text = "";
  2851. if ($comments) {
  2852. $even = 1;
  2853. foreach ($comments as $tmp) {
  2854. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  2855. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  2856. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2857. // $text .= $tmp->comment . "</td></tr>";
  2858. //} else {
  2859. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2860. if ($even) {
  2861. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2862. $even = 0;
  2863. } else {
  2864. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2865. $even = 1;
  2866. }
  2867. $text .= $tmp->comment . "</td></tr>\n";
  2868. } // foreach ($comments as $tmp)
  2869. }
  2870. return $text;
  2871. }
  2872. /// Update comment of activity
  2873. function update_comment ($iassign_submissionid) {
  2874. global $USER, $DB, $OUTPUT;
  2875. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  2876. $receiver = 1; // student message to teacher
  2877. else
  2878. $receiver = 2; // teacher message to student
  2879. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  2880. if ($verify_message) {
  2881. foreach ($verify_message as $message) {
  2882. if ($message->receiver == $receiver) {
  2883. $newentry = new stdClass();
  2884. $newentry->id = $message->id;
  2885. $newentry->return_status = 1;
  2886. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  2887. print_error('error_update', 'iassign');
  2888. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  2889. } // if ($message->receiver == $receiver)
  2890. // Trigger module viewed event.
  2891. $event = \mod_iassign\event\submission_comment_updated::create(array(
  2892. 'objectid' => $this->iassign->id,
  2893. 'context' => $this->context
  2894. ));
  2895. $event->add_record_snapshot('course', $this->course);
  2896. $event->trigger();
  2897. } // foreach ($verify_message as $message)
  2898. }
  2899. }
  2900. /// Record comment of activity
  2901. function write_comment_submission () {
  2902. global $USER, $CFG, $DB;
  2903. $id = $this->cm->id;
  2904. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  2905. $row = optional_param('row', 0, PARAM_INT);
  2906. $column = optional_param('column', 0, PARAM_INT);
  2907. $sum_comment = 0;
  2908. $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);
  2909. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  2910. $str1 = trim($submission_comment);
  2911. $str2 = trim(get_string('box_comment_message', 'iassign'));
  2912. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  2913. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  2914. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  2915. $receiver = 1; // student message to teacher
  2916. $this->action = 'view';
  2917. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  2918. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  2919. } else {
  2920. $receiver = 2; // teacher message to student
  2921. $this->action = 'viewsubmission';
  2922. //D $tousers = array(); //MOOC 2016
  2923. //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
  2924. }
  2925. //MOOC 2016: foi p/ 15 linhas acima:
  2926. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  2927. if (!$iassign_submission) {
  2928. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  2929. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  2930. $this->iassign_submission_current = $id_submission;
  2931. } else {
  2932. $id_submission = $iassign_submission->id;
  2933. } // if (!$iassign_submission)
  2934. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  2935. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  2936. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  2937. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  2938. $comments = $DB->get_record_sql(
  2939. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2940. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  2941. if ($comments)
  2942. foreach ($comments as $tmp)
  2943. $sum_comment = $tmp;
  2944. if ($sum_comment == 0) {
  2945. $newentry = new stdClass();
  2946. $newentry->iassign_submissionid = $id_submission;
  2947. $newentry->comment_authorid = $USER->id;
  2948. $newentry->timecreated = time();
  2949. $newentry->comment = $submission_comment;
  2950. $newentry->receiver = $receiver;
  2951. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  2952. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  2953. //T $eventdata = new stdClass();
  2954. //T $eventdata->component = 'mod_iassign'; //your component name
  2955. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  2956. //T $eventdata->userfrom = $USER;
  2957. //T $eventdata->userto = $touser;
  2958. //T $eventdata->subject = "Teste de Subject";
  2959. //T $eventdata->fullmessage = "Teste de Mensagem...";
  2960. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  2961. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  2962. //T $eventdata->smallmessage = "Teste de Mensagem";
  2963. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  2964. //T // alteracao tulio faria
  2965. //T //message_send($eventdata);
  2966. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  2967. // Trigger module viewed event.
  2968. $event = \mod_iassign\event\submission_comment_created::create(array(
  2969. 'objectid' => $this->iassign->id,
  2970. 'context' => $this->context
  2971. ));
  2972. $event->add_record_snapshot('course', $this->course);
  2973. $event->trigger();
  2974. }
  2975. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  2976. // if ($this->action=='viewsubmission') {
  2977. // echo $OUTPUT->header();
  2978. // $this->return_last('confirm_add_comment', $link_return);
  2979. // die;
  2980. // }
  2981. return true;
  2982. } // function write_comment_submission()
  2983. /// Writes a new submission
  2984. // The first student answer is under 'function get_answer()'
  2985. function new_submission ($iassignid, $id_user, $receiver) {
  2986. global $USER, $DB, $OUTPUT;
  2987. $newentry = new stdClass();
  2988. $newentry->iassign_statementid = $iassignid;
  2989. $newentry->userid = $id_user;
  2990. $newentry->timecreated = time();
  2991. $newentry->timemodified = time();
  2992. $newentry->answer = 0; // student only submit message
  2993. if ($receiver == 2) // teacher message to student (write id teacher)
  2994. $newentry->teacher = $USER->id;
  2995. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  2996. return_home_course('error_insert_submissions');
  2997. else {
  2998. // Trigger module view event
  2999. $event = \mod_iassign\event\submission_created::create(array(
  3000. 'objectid' => $this->iassign->id,
  3001. 'context' => $this->context
  3002. ));
  3003. $event->add_record_snapshot('course', $this->course);
  3004. $event->trigger();
  3005. }
  3006. return $newentry->id;
  3007. }
  3008. /// Return to a specific address of page
  3009. function return_last ($message, $link_return) {
  3010. global $DB, $OUTPUT;
  3011. print $OUTPUT->box_start();
  3012. print '<table width=100% border=0 valign="top">' . "\n";
  3013. print '<tr><td align="left"><strong>' . "\n";
  3014. print_string($message, 'iassign');
  3015. print '</strong></td>' . "\n";
  3016. print '<td width=20% align="right">' . "\n";
  3017. print $link_return;
  3018. print '</td></tr></table>' . "\n";
  3019. print $OUTPUT->box_end();
  3020. print $OUTPUT->footer();
  3021. die();
  3022. } // function return_last($message, $link_return)
  3023. } // class iassign
  3024. /// Class for manage activities
  3025. class activity {
  3026. var $activity;
  3027. /// Constructor of class.
  3028. // @param int $id Id of activity
  3029. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3030. //D public function activity($id) { self::__construct($id); }
  3031. function __construct ($id) {
  3032. global $DB;
  3033. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3034. if (empty($this->activity))
  3035. $this->activity = null;
  3036. }
  3037. /// Get an activity
  3038. // @return NULL
  3039. function get_activity () {
  3040. if ($this->activity != null)
  3041. return $this->activity;
  3042. else
  3043. return null;
  3044. }
  3045. /// Delete interactive activities
  3046. function delete ($return) {
  3047. global $USER, $CFG, $DB, $OUTPUT;
  3048. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3049. $output = $OUTPUT->header();
  3050. $output .= $OUTPUT->box_start();
  3051. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3052. if ($iassign_submission_currents) {
  3053. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3054. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3055. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3056. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3057. $output .= $OUTPUT->box_end();
  3058. $output .= $OUTPUT->footer();
  3059. print $output;
  3060. die();
  3061. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3062. } // if ($iassign_submission_currents)
  3063. else
  3064. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3065. $output .= '<table width=50% border=0>';
  3066. $output .= '<tr valign="top"><td>';
  3067. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3068. $output .= '</td><td>';
  3069. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3070. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3071. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3072. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3073. $output .= "</form>\n";
  3074. $output .= '</td><td>';
  3075. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3076. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3077. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3078. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3079. $output .= "</form>\n";
  3080. $output .= '</td></tr></table>' . "\n";
  3081. $output .= $OUTPUT->box_end();
  3082. $output .= $OUTPUT->footer();
  3083. print $output;
  3084. } // function delete($return)
  3085. /// Function for confirm the delete of activity
  3086. // @param String $return Url of return
  3087. // @param Object $iassign Object content an activity
  3088. function deleteyes ($return, $iassign) {
  3089. global $USER, $CFG, $DB, $OUTPUT;
  3090. $msg = '';
  3091. if (!empty($this->activity->id)) {
  3092. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3093. if ($iassign_submission_currents) {
  3094. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3095. foreach ($iassign_submission_currents as $iassign_submission)
  3096. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3097. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3098. } // if ($iassign_submission_currents)
  3099. }
  3100. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3101. $this->delete_calendar($this->activity->id);
  3102. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3103. iassign::update_grade_iassign($this->activity->iassignid);
  3104. if ($delete_iassign_current) {
  3105. $iassign->return_home_course('confirm_delete_iassign');
  3106. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3107. } else {
  3108. $iassign->return_home_course('error_confirm_delete_iassign');
  3109. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3110. }
  3111. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3112. }
  3113. }
  3114. /// Changes position of activities (between those inside a group of interactive activities)
  3115. // @param $move_action = must be "up" or "down"
  3116. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3117. function move_iassign ($move_action, $target, $return) {
  3118. global $DB, $OUTPUT;
  3119. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3120. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3121. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3122. if ($move_action=="firstdown") {
  3123. $final_position_source = 2;
  3124. $final_position_target = 1;
  3125. }
  3126. else
  3127. if ($move_action=="down") {
  3128. $final_position_target = $this->activity->position;
  3129. $final_position_source = $final_position_target + 1;
  3130. }
  3131. else
  3132. if ($move_action=="up") {
  3133. $final_position_target = $this->activity->position;
  3134. $final_position_source = $final_position_target - 1;
  3135. }
  3136. else { // error:
  3137. print_error('error_update_move_iassign', 'iassign');
  3138. exit;
  3139. }
  3140. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3141. $newentry->id = $this->activity->id; // ID of the "source activity"
  3142. $newentry->position = $final_position_source;
  3143. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3144. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3145. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3146. print_error('error_update_move_iassign', 'iassign');
  3147. }
  3148. else { // first update performed successfully
  3149. $newentry->id = $iassign_target->id;
  3150. $newentry->position = $final_position_target;
  3151. if (!$DB->update_record('iassign_statement', $newentry))
  3152. print_error('error_update_move_iassign', 'iassign');
  3153. }
  3154. redirect($return);
  3155. }
  3156. /// Enable or disable the display of interactive activities
  3157. function visible_iassign ($return) {
  3158. global $DB;
  3159. $newentry = new stdClass();
  3160. $newentry->id = $this->activity->id;
  3161. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3162. if (!$DB->update_record('iassign_statement', $newentry))
  3163. print_error('error_update_visible_iassign', 'iassign');
  3164. redirect($return);
  3165. }
  3166. /// Add news interactive activities (register in table 'iassign_statement')
  3167. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3168. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3169. function new_iassign ($param) {
  3170. global $DB;
  3171. $newentry = new stdClass();
  3172. $newentry->iassignid = $param->iassignid;
  3173. $newentry->name = $param->name;
  3174. $newentry->type_iassign = $param->type_iassign;
  3175. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3176. $proposition = $param->proposition;
  3177. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3178. else $proposition_text = $proposition;
  3179. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3180. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3181. //TODO Then get it directly from the form data $_POST!
  3182. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3183. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3184. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3185. $newentry->author_name = $param->author_name;
  3186. $newentry->author_modified_name = $param->author_modified_name;
  3187. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3188. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3189. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3190. $newentry->grade = $param->grade;
  3191. $newentry->timemodified = time();
  3192. $newentry->timecreated = time();
  3193. if ($param->type_iassign == 1) {
  3194. $newentry->timedue = 0;
  3195. $newentry->timeavailable = 0;
  3196. } // if ($param->type_iassign == 1)
  3197. else {
  3198. $newentry->timedue = $param->timedue;
  3199. $newentry->timeavailable = $param->timeavailable;
  3200. }
  3201. $newentry->preventlate = $param->preventlate;
  3202. $newentry->test = $param->test;
  3203. $newentry->special_param1 = $param->special_param1;
  3204. $newentry->visible = $param->visible;
  3205. $newentry->position = $param->position;
  3206. $newentry->max_experiment = $param->max_experiment;
  3207. $newentry->dependency = $param->dependency;
  3208. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3209. $newentry->show_answer = $param->show_answer;
  3210. $id = $DB->insert_record("iassign_statement", $newentry);
  3211. if ($id) {
  3212. $component = 'mod_iassign';
  3213. $filearea = 'exercise';
  3214. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3215. $file = $fs->get_file_by_id($param->file);
  3216. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3217. // File already inserted in other context!
  3218. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3219. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3220. $updateentry = new stdClass();
  3221. $updateentry->id = $id;
  3222. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3223. $updateentry->file = $newfile->get_itemid();
  3224. if (!$DB->update_record("iassign_statement", $updateentry))
  3225. print_error('error_add', 'iassign');
  3226. if ($param->type_iassign == 3)
  3227. iassign::update_grade_iassign($param->iassignid);
  3228. //TODO iLM_HTML5 :: //MOOC2014
  3229. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3230. //D if ($iassign_ilm_configs) {
  3231. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3232. //D if ($iassign_ilm_config->param_type != 'static') {
  3233. //D $newentry = new stdClass();
  3234. //D $newentry->iassign_statementid = $id;
  3235. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3236. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3237. //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});
  3238. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3239. //D print_error('error_add_param', 'iassign');
  3240. //D }
  3241. //D }
  3242. //D }
  3243. // log event --------------------------------------------------------------------------------------
  3244. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3245. // log event --------------------------------------------------------------------------------------
  3246. return $id;
  3247. }
  3248. else
  3249. print_error('error_add', 'iassign');
  3250. } // function new_iassign($param)
  3251. /// Add the calendar entries for this iassign
  3252. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3253. // @return bool
  3254. static function add_calendar ($iassignid) {
  3255. global $DB, $CFG;
  3256. require_once($CFG->dirroot . '/calendar/lib.php');
  3257. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3258. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3259. $event = new stdClass();
  3260. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3261. $event->description = $iassign_statement_activity_item->name;
  3262. $event->courseid = $iassign->course;
  3263. $event->groupid = 0;
  3264. $event->userid = 0;
  3265. $event->modulename = 'iassign';
  3266. $event->instance = $iassign->id;
  3267. $event->eventtype = 'due';
  3268. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3269. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3270. calendar_event::create($event);
  3271. }
  3272. /// Update the calendar entries for this iassign
  3273. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3274. // @return bool
  3275. function update_calendar ($iassignid, $olddescription) {
  3276. global $DB, $CFG;
  3277. require_once($CFG->dirroot . '/calendar/lib.php');
  3278. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3279. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3280. $event = new stdClass();
  3281. $event->id = 0;
  3282. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3283. if ($events) {
  3284. foreach ($events as $value) {
  3285. if ($value->description == $olddescription) {
  3286. $event->id = $value->id;
  3287. }
  3288. }
  3289. }
  3290. if ($event->id != 0) {
  3291. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3292. $event->description = $iassign_statement_activity_item->name;
  3293. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3294. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3295. $calendarevent = calendar_event::load($event->id);
  3296. $calendarevent->update($event);
  3297. } else
  3298. $this->add_calendar($iassignid);
  3299. }
  3300. /// Update the calendar entries for this iassign
  3301. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3302. // @return bool
  3303. function delete_calendar ($iassignid) {
  3304. global $DB, $CFG;
  3305. require_once($CFG->dirroot . '/calendar/lib.php');
  3306. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3307. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3308. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3309. if ($events) {
  3310. foreach ($events as $value) {
  3311. if ($value->description == $iassign_statement_activity_item->name) {
  3312. $DB->delete_records('event', array('id' => $value->id));
  3313. }
  3314. }
  3315. }
  3316. }
  3317. /// Update interactive activities
  3318. function update_iassign ($param) {
  3319. global $DB;
  3320. $component = 'mod_iassign';
  3321. $filearea = 'exercise';
  3322. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3323. $file = $fs->get_file_by_id($param->file);
  3324. $fileold = $fs->get_file_by_id($param->fileold);
  3325. if ($param->file != $param->fileold) {
  3326. if ($fileold) {
  3327. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3328. foreach ($fileoldarea as $value) {
  3329. $value->delete();
  3330. }
  3331. }
  3332. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3333. $itemid = $file->get_itemid() + $param->iassign_id;
  3334. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3335. $param->file = $newfile->get_itemid();
  3336. } else
  3337. $param->file = $file->get_itemid();
  3338. } else {
  3339. $param->file = $file->get_itemid();
  3340. }
  3341. $newentry = new stdClass();
  3342. $newentry->id = $param->iassign_id;
  3343. $newentry->name = $param->name;
  3344. $newentry->type_iassign = $param->type_iassign;
  3345. //2019 $newentry->proposition = $param->proposition;
  3346. $proposition = $param->proposition;
  3347. if (is_array($proposition))
  3348. $proposition_text = $proposition['text'];
  3349. else
  3350. $proposition_text = $proposition;
  3351. $newentry->proposition = $proposition_text;
  3352. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3353. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3354. $newentry->grade = $param->grade;
  3355. $newentry->author_modified_name = $param->author_modified_name;
  3356. $newentry->timemodified = time();
  3357. if ($param->type_iassign == 1) {
  3358. $newentry->timedue = 0;
  3359. $newentry->timeavailable = 0;
  3360. } // if ($param->type_iassign == 1)
  3361. else {
  3362. $newentry->timedue = $param->timedue;
  3363. $newentry->timeavailable = $param->timeavailable;
  3364. }
  3365. $newentry->preventlate = $param->preventlate;
  3366. $newentry->test = $param->test;
  3367. $newentry->special_param1 = $param->special_param1;
  3368. $newentry->visible = $param->visible;
  3369. $newentry->max_experiment = $param->max_experiment;
  3370. $newentry->dependency = $param->dependency;
  3371. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3372. $newentry->show_answer = $param->show_answer;
  3373. if (!$DB->update_record("iassign_statement", $newentry))
  3374. print_error('error_update', 'iassign');
  3375. if ($param->type_iassign == 3) {
  3376. iassign::update_grade_iassign($param->iassignid);
  3377. }
  3378. //$id = $newentry->id; // MOOC 2016 --- inicio
  3379. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3380. //if ($iassign_activity_item_configs) {
  3381. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3382. // $newentry = new stdClass();
  3383. // $newentry->id = $iassign_activity_item_config->id;
  3384. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3385. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3386. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3387. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3388. // print_error('error_edit_param', 'iassign');
  3389. // }
  3390. // } // MOOC 2016 --- final
  3391. // log event --------------------------------------------------------------------------------------
  3392. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3393. // log event --------------------------------------------------------------------------------------
  3394. return $newentry->id;
  3395. // if ($param->type_iassign==3)
  3396. // $this->update_grade_iassign($param->iassignid);
  3397. } // function update_iassign($param)
  3398. /// Show information of activity
  3399. function show_info_iassign () {
  3400. global $DB, $OUTPUT;
  3401. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3402. if ($this->activity->type_iassign == 3) {
  3403. if ($this->activity->dependency == 0) {
  3404. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3405. } else {
  3406. $dependencys = explode(';', $this->activity->dependency);
  3407. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3408. foreach ($dependencys as $dependency) {
  3409. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3410. if ($dependencyiassign)
  3411. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3412. } // foreach ($dependencys as $dependency)
  3413. } // if ($iassign_statement_activity_item->dependency == 0)
  3414. if ($this->activity->max_experiment == 0)
  3415. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3416. else
  3417. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3418. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3419. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3420. print $OUTPUT->box($output);
  3421. } // function show_info_iassign()
  3422. /// Shows date of opening and closing activities
  3423. function view_dates () {
  3424. global $USER, $CFG, $DB, $OUTPUT;
  3425. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3426. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3427. $status_iassign = "";
  3428. $status_iassign1 = "";
  3429. $status_iassign2 = "";
  3430. if ($this->activity->type_iassign == 1) // activity of type example
  3431. $type_iassign = get_string('example_iassign', 'iassign');
  3432. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3433. $type_iassign = get_string('test_iassign', 'iassign');
  3434. if ($this->activity->timeavailable > time()) {
  3435. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3436. } elseif ($this->activity->timedue < time()) {
  3437. $status_iassign = get_string('last_timedue', 'iassign');
  3438. }
  3439. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3440. $type_iassign = get_string('exercise_iassign', 'iassign');
  3441. if ($this->activity->timeavailable > time()) {
  3442. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3443. } elseif ($this->activity->timedue < time()) { // after delivery
  3444. $status_iassign = get_string('last_timedue', 'iassign');
  3445. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3446. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3447. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3448. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3449. if ($this->activity->test == 1) // allowed to test after of deadline
  3450. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3451. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3452. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3453. } // elseif ($iassign_statement_activity_item->test == 0)
  3454. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3455. } // elseif ($iassign_statement_activity_item->timedue < time())
  3456. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3457. $output = '<table width=100% >' . "\n";
  3458. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3459. $output .= '<tr>' . "\n";
  3460. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3461. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3462. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3463. // leo $output .= '<td width=80%>' . $type_iassign;
  3464. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3465. // $output .= '</td>' . "\n";
  3466. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3467. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3468. $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>";
  3469. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3470. } else {
  3471. $link_next = "";
  3472. $link_previous = "";
  3473. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3474. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3475. // previous_activity
  3476. if ($iassign_previous) {
  3477. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3478. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3479. } // next_activity
  3480. if ($iassign_next) {
  3481. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3482. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3483. }
  3484. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3485. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3486. $output .= '</tr></table>' . "\n";
  3487. $output .= '<table width=100% >' . "\n";
  3488. if ($this->activity->type_iassign > 1) {
  3489. if ($this->activity->timeavailable)
  3490. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3491. if ($this->activity->timedue)
  3492. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3493. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3494. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3495. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3496. $output .= '</table>' . "\n";
  3497. print $OUTPUT->box($output);
  3498. } // function view_dates()
  3499. } // class activity
  3500. /// Class to manage Interactive Learning Module (iLM)
  3501. class ilm {
  3502. var $ilm;
  3503. /// Constructor of class
  3504. // @param int $id Id of iLM
  3505. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3506. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3507. function __construct ($id) {
  3508. global $DB;
  3509. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3510. if (empty($this->ilm))
  3511. $this->ilm = null;
  3512. }
  3513. /// Shows activity in iLM
  3514. // @calledby view_iassign_current()
  3515. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3516. global $USER, $CFG, $DB;
  3517. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3518. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3519. $typec = strtolower($iassign_ilm->type);
  3520. require_once 'ilm_handlers/' . $typec . '.php';
  3521. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3522. return $retorno;
  3523. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3524. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3525. // @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);
  3526. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3527. // @param Object $file File in use in activity
  3528. // @return int Return the id of log
  3529. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3530. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3531. $newentry = new stdClass();
  3532. $newentry->iassign_statementid = $iassign_activity_itemid;
  3533. $newentry->userid = $USER->id;
  3534. $newentry->file = $content_or_id_from_ilm_security;
  3535. $newentry->timecreated = time();
  3536. $newentry->view = 1;
  3537. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3538. if (!$id_iLM_security) {
  3539. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3540. } // from (!$DB->insert_record("iassign_security", $newentry))
  3541. return $id_iLM_security;
  3542. }
  3543. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3544. // @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);
  3545. // @param int $userid
  3546. // @param int $iassign_activity_itemid Id of iassign statement
  3547. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3548. global $DB;
  3549. // 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")
  3550. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3551. }
  3552. } // class ilm
  3553. /// Class to manage settings of iLM.
  3554. class ilm_settings {
  3555. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  3556. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3557. // @param int $ilm_id Id of iLM
  3558. // @param array $options An array with options for create dynamic tag html APPLET
  3559. // @return string Return with a tag html APPLET created
  3560. static function build_ilm_tags ($ilm_id, $options = array()) {
  3561. global $DB;
  3562. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3563. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3564. $typec = strtolower($iassign_ilm->type);
  3565. require_once 'ilm_handlers/' . $typec . '.php';
  3566. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3567. return $retorno;
  3568. } // static function build_ilm_tags($ilm_id, $options = array())
  3569. /// Function for get modified date of iLM file
  3570. // @param string $file_jar String with Ids of iLM files
  3571. // @return string Return with the filenames and modified date
  3572. static function applet_filetime ($file_jar) {
  3573. $filetime = "";
  3574. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3575. $files_jar = explode(",", $file_jar);
  3576. foreach ($files_jar as $one_file) {
  3577. $file = $fs->get_file_by_id($one_file);
  3578. if ($file)
  3579. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3580. }
  3581. return $filetime;
  3582. }
  3583. /// Function for verify an default applet
  3584. // @param String $file_jar String containing an list de ids of applet files
  3585. // @return boolean Return true or fale if applet is default
  3586. static function applet_default ($file_jar) {
  3587. $is_default = true;
  3588. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3589. $files_jar = explode(",", $file_jar);
  3590. foreach ($files_jar as $one_file) {
  3591. $file = $fs->get_file_by_id($one_file);
  3592. if ($file)
  3593. $is_default &= ($file->get_itemid() == 0);
  3594. }
  3595. return $is_default;
  3596. }
  3597. /// Function for get form variables for add, edit, or copy iLM
  3598. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  3599. // @see settings_form.php
  3600. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  3601. // @param int $ilm_id Id of iLM
  3602. // @param string $action String with the action
  3603. // @return object Return an object with forms variables
  3604. static function add_edit_copy_ilm ($ilm_id, $action) {
  3605. global $USER, $DB, $CFG;
  3606. require_once('settings_form.php'); // put the form
  3607. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3608. $param = new stdClass();
  3609. $param->action = $action;
  3610. $param->ilm_id = $ilm_id;
  3611. $CFG->action_ilm = $action;
  3612. $CFG->ilm_id = $ilm_id;
  3613. if ($action == 'add') {
  3614. $param->title = get_string('add_ilm', 'iassign');
  3615. $param->name = "";
  3616. $param->version = "";
  3617. $param->url = "";
  3618. $param->description = "";
  3619. $param->extension = "";
  3620. $param->author = $USER->id;
  3621. $param->file_jar = "";
  3622. $param->file_jar_static = "";
  3623. $param->file_class = "";
  3624. $param->width = 800;
  3625. $param->height = 600;
  3626. $param->enable = 0; // 0 - hide / 1 - show
  3627. $param->timecreated = time();
  3628. $param->timemodified = time();
  3629. $param->evaluate = 0;
  3630. $param->parent = 0;
  3631. }
  3632. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  3633. if ($iassign_ilm) {
  3634. $description = json_decode($iassign_ilm->description);
  3635. $param->title = get_string('edit_ilm', 'iassign');
  3636. $param->id = $iassign_ilm->id;
  3637. $param->name_ilm = $iassign_ilm->name;
  3638. $param->name = $iassign_ilm->name;
  3639. $param->version = $iassign_ilm->version;
  3640. $param->ilm_type = $iassign_ilm->type;
  3641. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3642. $param->url = $iassign_ilm->url;
  3643. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  3644. if (!isset($description->{current_language()})) {
  3645. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  3646. else
  3647. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  3648. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  3649. }
  3650. else
  3651. $param->description = $description->{current_language()};
  3652. $param->description_lang = $iassign_ilm->description;
  3653. $param->extension = $iassign_ilm->extension;
  3654. $param->author = $iassign_ilm->author;
  3655. $param->file_jar = $iassign_ilm->file_jar;
  3656. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  3657. $param->file_class = $iassign_ilm->file_class;
  3658. $param->width = $iassign_ilm->width;
  3659. $param->height = $iassign_ilm->height;
  3660. $param->enable = $iassign_ilm->enable;
  3661. $param->timecreated = $iassign_ilm->timecreated;
  3662. $param->timemodified = time();
  3663. $param->evaluate = $iassign_ilm->evaluate;
  3664. $param->parent = $iassign_ilm->parent;
  3665. }
  3666. }
  3667. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  3668. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  3669. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3670. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  3671. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  3672. // echo "Sem dados<br/>"; exit;
  3673. return;
  3674. }
  3675. $description = json_decode($iassign_ilm->description);
  3676. if ($iassign_ilm) {
  3677. if ($iassign_ilm->parent == 0)
  3678. $iassign_ilm->parent = $ilm_id;
  3679. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  3680. $param->title = get_string('new_version_ilm', 'iassign');
  3681. $param->name_ilm = $iassign_ilm->name;
  3682. $param->name = $iassign_ilm->name;
  3683. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  3684. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  3685. $param->version = $iassign_ilm->version; // do not erase field 'version'
  3686. $param->ilm_type = $iassign_ilm->type;
  3687. $param->url = $iassign_ilm->url;
  3688. $param->description = $description->{current_language()};
  3689. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  3690. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3691. $param->extension = $iassign_ilm->extension;
  3692. $param->author = $USER->id;
  3693. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  3694. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  3695. $param->file_jar_static = '';
  3696. $param->file_class = $iassign_ilm->file_class;
  3697. $param->width = $iassign_ilm->width;
  3698. $param->height = $iassign_ilm->height;
  3699. $param->enable = 0;
  3700. $param->timecreated = time();
  3701. $param->timemodified = time();
  3702. $param->evaluate = $iassign_ilm->evaluate;
  3703. $param->parent = $iassign_ilm->parent;
  3704. }
  3705. }
  3706. elseif ($action == 'copy') {
  3707. $description = json_decode($iassign_ilm->description);
  3708. if ($iassign_ilm) {
  3709. if ($iassign_ilm->parent == 0)
  3710. $iassign_ilm->parent = $ilm_id;
  3711. $param->title = get_string('copy_ilm', 'iassign');
  3712. $param->id = $iassign_ilm->id;
  3713. $param->name_ilm = $iassign_ilm->name;
  3714. $param->name = $iassign_ilm->name;
  3715. $param->version = "";
  3716. $param->ilm_type = $iassign_ilm->type;
  3717. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3718. $param->url = $iassign_ilm->url;
  3719. $param->description = $description->{current_language()};
  3720. $param->description_lang = $iassign_ilm->description;
  3721. $param->extension = $iassign_ilm->extension;
  3722. $param->author = $USER->id;
  3723. $param->file_jar = '';
  3724. $param->file_jar_static = '';
  3725. $param->file_class = $iassign_ilm->file_class;
  3726. $param->width = $iassign_ilm->width;
  3727. $param->height = $iassign_ilm->height;
  3728. $param->enable = 0;
  3729. $param->timecreated = time();
  3730. $param->timemodified = time();
  3731. $param->evaluate = $iassign_ilm->evaluate;
  3732. $param->parent = $iassign_ilm->parent;
  3733. }
  3734. }
  3735. return $param;
  3736. } // static function add_edit_copy_ilm($ilm_id, $action)
  3737. /// Function for save iLM file in moodledata
  3738. // @param int $itemid Itemid of file save in draft (upload file)
  3739. // @param int $ilm_id Id of iLM
  3740. // @return string Return an string with ids of iLM files
  3741. static function new_file_ilm ($itemid, $iassign_ilm) {
  3742. global $CFG, $USER, $DB;
  3743. $return = null;
  3744. $file_jar = array();
  3745. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3746. $contextuser = context_user::instance($USER->id);
  3747. $contextsystem = context_system::instance();
  3748. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  3749. if ($files_ilm) {
  3750. foreach ($files_ilm as $value) {
  3751. // CHECK IF file is HTML type
  3752. if ($iassign_ilm->type == 1) {
  3753. // Check if the file extension is ZIP
  3754. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  3755. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  3756. if ((strtolower($ext) == 'zip')) {
  3757. // Coping...:
  3758. $destination = 'ilm_debug/' . $value->get_filename();
  3759. $value->copy_content_to($destination);
  3760. // Extracting content...:
  3761. $zip = new ZipArchive();
  3762. $extracted = './ilm';
  3763. $dir = "";
  3764. if ($zip->open($destination) === TRUE) {
  3765. $dir = './ilm/' . trim($zip->getNameIndex(0));
  3766. if (is_dir($dir)) {
  3767. $i = 1;
  3768. $previous = str_replace("/", "", $zip->getNameIndex(0));
  3769. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  3770. $i ++;
  3771. }
  3772. $name = $previous . "_" . $i;
  3773. $dir = './ilm/' . $name . "/";
  3774. $j = 0;
  3775. while ($item_name = $zip->getNameIndex($j)) {
  3776. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  3777. $j++;
  3778. }
  3779. $zip->close();
  3780. }
  3781. $zip->open($destination);
  3782. $zip->extractTo($extracted);
  3783. $zip->close();
  3784. // After the extraction, remove it from DEBUG
  3785. unlink($destination);
  3786. } else { // Error trying to open destination...
  3787. // After the extraction error, also remove it from DEBUG
  3788. unlink($destination);
  3789. print_error('error_add_ilm_zip', 'iassign');
  3790. }
  3791. return $dir;
  3792. }
  3793. } // if ($iassign_ilm->type == 1)
  3794. if ($value->get_filename() != '.') {
  3795. $file_ilm = array(
  3796. 'userid' => $USER->id,
  3797. 'contextid' => $contextsystem->id,
  3798. 'component' => 'mod_iassign',
  3799. 'filearea' => 'ilm',
  3800. 'itemid' => rand(1, 999999999),
  3801. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  3802. 'filename' => $value->get_filename());
  3803. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  3804. array_push($file_jar, $file_ilm->get_id());
  3805. }
  3806. }
  3807. if (!empty($file_jar)) {
  3808. $return = implode(",", $file_jar);
  3809. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  3810. foreach ($old_file_jar as $value) {
  3811. $file = $fs->get_file_by_id($value);
  3812. if ($file)
  3813. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  3814. }
  3815. }
  3816. }
  3817. else // if ($files_ilm)
  3818. $return = $iassign_ilm->file_jar;
  3819. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  3820. return $return;
  3821. } // static function new_file_ilm($itemid, $iassign_ilm)
  3822. /// Function for save in database an new iLM
  3823. // @param object $param An object with iLM params
  3824. static function new_ilm ($itemid) {
  3825. global $CFG, $USER, $OUTPUT;
  3826. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3827. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3828. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3829. }
  3830. $pathtemp = $CFG->dataroot . '/temp/';
  3831. $contextuser = context_user::instance($USER->id);
  3832. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3833. $zip = new zip_packer();
  3834. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3835. foreach ($files as $file) {
  3836. if (!$file->is_directory())
  3837. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3838. }
  3839. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3840. // Verifica se o pacote possui o XML
  3841. if (!$application_xml) {
  3842. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3843. return;
  3844. } else {
  3845. $missing = "";
  3846. if (!isset($application_xml->name)) {
  3847. $missing .= "name";
  3848. }
  3849. if (!isset($application_xml->version)) {
  3850. $missing .= ", version";
  3851. }
  3852. if (!isset($application_xml->type)) {
  3853. $missing .= ", type";
  3854. }
  3855. if (!isset($application_xml->extension)) {
  3856. $missing .= ", extension";
  3857. }
  3858. if (!isset($application_xml->file_jar)) {
  3859. $missing .= ", file_jar";
  3860. }
  3861. if (!isset($application_xml->file_class)) {
  3862. $missing .= ", file_class";
  3863. }
  3864. if (!isset($application_xml->width)) {
  3865. $missing .= ", width";
  3866. }
  3867. if (!isset($application_xml->height)) {
  3868. $missing .= ", height";
  3869. }
  3870. if (!isset($application_xml->evaluate)) {
  3871. $missing .= ", evaluate";
  3872. }
  3873. if (strlen($missing) > 2) {
  3874. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3875. return;
  3876. }
  3877. }
  3878. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3879. $typec = strtolower($application_xml->type);
  3880. require_once 'ilm_handlers/' . $typec . '.php';
  3881. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3882. return $retorno;
  3883. } // static function new_ilm($itemid)
  3884. /// Function for save in database an iLM edit
  3885. // @param object $param An object with iLM params
  3886. static function edit_ilm ($param, $itemid) {
  3887. // Descobrir o tipo de iLM:
  3888. global $DB, $USER, $CFG;
  3889. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  3890. $pathtemp = $CFG->dataroot . '/temp/';
  3891. $contextuser = context_user::instance($USER->id);
  3892. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3893. $zip = new zip_packer();
  3894. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3895. $files_extract = null;
  3896. foreach ($files as $file) {
  3897. if (!$file->is_directory())
  3898. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3899. }
  3900. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  3901. $typec = strtolower($iassign_t->type);
  3902. require_once 'ilm_handlers/' . $typec . '.php';
  3903. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  3904. }
  3905. /// Function for register the new iLM (in database and in the directory)
  3906. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  3907. // @param object $param An object with iLM params
  3908. static function copy_new_version_ilm ($param) {
  3909. global $DB, $CFG, $USER;
  3910. $itemid = $param->file;
  3911. $pathtemp = $CFG->dataroot . '/temp/';
  3912. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3913. //D echo "pathtemp=$pathtemp<br/>";
  3914. $contextuser = context_user::instance($USER->id);
  3915. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3916. $zip = new zip_packer();
  3917. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3918. $files_extract = null;
  3919. foreach ($files as $file) {
  3920. if (!$file->is_directory())
  3921. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3922. }
  3923. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3924. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  3925. $typec = strtolower($iassign_t->type);
  3926. require_once 'ilm_handlers/' . $typec . '.php';
  3927. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  3928. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  3929. } // static function copy_new_version_ilm($param)
  3930. //VER::
  3931. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  3932. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  3933. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  3934. /// Function for change visibility of iLM
  3935. // @param int $ilm_id Id of iLM
  3936. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  3937. static function visible_ilm ($ilm_id, $status) {
  3938. global $DB;
  3939. if ($status == 0)
  3940. $visible = 1;
  3941. else
  3942. $visible = 0;
  3943. $newentry = new stdClass();
  3944. $newentry->id = $ilm_id;
  3945. $newentry->enable = $visible;
  3946. if (!$DB->update_record("iassign_ilm", $newentry))
  3947. error(get_string('error_edit_ilm', 'iassign'));
  3948. }
  3949. /// Function for confirm change default iLM
  3950. // @param int $ilm_id Id of iLM
  3951. // @param int $ilm_parent Id of parent iLM
  3952. // @return string Return with an string for create default page confirmation
  3953. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  3954. global $OUTPUT, $DB;
  3955. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3956. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3957. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3958. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  3959. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  3960. return $return;
  3961. }
  3962. /// Function for change the default iLM
  3963. // @see settings_ilm.php
  3964. // @param int $ilm_id Id of iLM
  3965. // @return int Return Id of default iLM
  3966. static function default_ilm ($ilm_id) {
  3967. global $DB;
  3968. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  3969. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  3970. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  3971. $iassign_ilm_default->id = $iassign_ilm->id;
  3972. $iassign_ilm_default->parent = 0;
  3973. $iassign_ilm->parent = $iassign_ilm_default->id;
  3974. $iassign_ilm->id = 0;
  3975. $iassign_ilm_default->enable = 1;
  3976. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  3977. print_error('error_edit_ilm', 'iassign');
  3978. }
  3979. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  3980. if (!$inserted) {
  3981. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  3982. print_error($msg_error);
  3983. //xx print_error('error_add_ilm', 'iassign');
  3984. }
  3985. return $iassign_ilm_default->id;
  3986. } // static function default_ilm ($ilm_id)
  3987. /// Function for confirm delete iLM
  3988. // @param int $ilm_id Id of iLM
  3989. // @param int $ilm_parent Id of parent iLM
  3990. // @return string Return with an string for create delete page confirmation
  3991. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  3992. global $OUTPUT, $DB;
  3993. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3994. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3995. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3996. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  3997. }
  3998. /// Function for delete directory where the iLM is allocated.
  3999. // @param string $dirPath
  4000. // @throws InvalidArgumentException
  4001. public static function delete_dir ($dirPath) {
  4002. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4003. $dirPath .= '/';
  4004. }
  4005. $files = glob($dirPath . '*', GLOB_MARK);
  4006. foreach ($files as $file) {
  4007. if (is_dir($file)) {
  4008. ilm_settings::delete_dir($file);
  4009. } else {
  4010. unlink($file);
  4011. }
  4012. }
  4013. rmdir($dirPath);
  4014. }
  4015. /// Function for delete iLM
  4016. // @param int $ilm_id Id of iLM
  4017. // @return int Return Id of parent iLM
  4018. static function delete_ilm ($ilm_id) {
  4019. global $DB;
  4020. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4021. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4022. $typec = strtolower($iassign_ilm->type);
  4023. require_once 'ilm_handlers/' . $typec . '.php';
  4024. $retorno = $typec::delete_ilm($ilm_id);
  4025. return $retorno;
  4026. }
  4027. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4028. // @param int $ilm_id Id of iLM
  4029. static function export_ilm ($ilm_id) {
  4030. global $DB;
  4031. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4032. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4033. $typec = strtolower($iassign_ilm->type);
  4034. require_once 'ilm_handlers/' . $typec . '.php';
  4035. $typec::export_ilm($ilm_id);
  4036. } // static function export_ilm($ilm_id)
  4037. //TODO iLM_HTML5 :: //MOOC 2016
  4038. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4039. // @param int $ilm_id Id of iLM
  4040. static function export_update_ilm ($ilm_id) {
  4041. global $DB, $CFG;
  4042. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4043. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4044. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4045. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4046. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4047. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4048. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4049. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4050. $upgrade_descriptor .= '</upgrade>' . "\n";
  4051. file_put_contents($xml_filename, $upgrade_descriptor);
  4052. header("Pragma: public");
  4053. header("Expires: 0");
  4054. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4055. header("Cache-Control: private", false);
  4056. header('Content-Type: application/xml; charset=utf-8');
  4057. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4058. header("Content-Length: " . @filesize($xml_filename));
  4059. set_time_limit(0);
  4060. @readfile("$xml_filename") || die("File not found.");
  4061. unlink($xml_filename);
  4062. exit;
  4063. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4064. /// Function for save iLM from XML descriptor
  4065. // @param array $application_xml Data of XML descriptor
  4066. // @param array $files_extract Filenames of extract files
  4067. // @return array Return an array content id of JAR files
  4068. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4069. global $CFG, $USER;
  4070. // Tratamento diferenciado se for do tipo HTML5:
  4071. $source = "";
  4072. $diretorio = "";
  4073. if (strtolower($application_xml->type) == 'html5') {
  4074. $i = 0;
  4075. foreach ($files_extract as $key => $value) {
  4076. $file = $CFG->dataroot . '/temp/' . $key;
  4077. // Verifica se já existe a pasta no diretório dos iLM:
  4078. if ($i == 0) {
  4079. $source = $file;
  4080. if (file_exists("ilm/" . basename($file))) {
  4081. $j = 1;
  4082. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4083. $j ++;
  4084. }
  4085. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4086. // mkdir($diretorio, 0777, true);
  4087. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4088. }
  4089. else {
  4090. $diretorio = 'ilm/' . basename($file);
  4091. // mkdir($diretorio, 0777, true);
  4092. mkdir($diretorio, 0755, true);
  4093. }
  4094. break;
  4095. }
  4096. $i ++;
  4097. }
  4098. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4099. if ($item->isDir()) {
  4100. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4101. }
  4102. else {
  4103. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4104. }
  4105. }
  4106. ilm_settings::delete_dir($source);
  4107. return "./" . $diretorio;
  4108. }
  4109. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4110. $file_jar = array();
  4111. $files_ilm = explode(",", $application_xml->file_jar);
  4112. $contextsystem = context_system::instance();
  4113. foreach ($files_ilm as $value) {
  4114. $file_ilm = array(
  4115. 'userid' => $USER->id,
  4116. 'contextid' => $contextsystem->id,
  4117. 'component' => 'mod_iassign',
  4118. 'filearea' => 'ilm',
  4119. 'itemid' => rand(1, 999999999),
  4120. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4121. 'filename' => $value);
  4122. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4123. array_push($file_jar, $file_ilm->get_id());
  4124. }
  4125. foreach ($files_extract as $key => $value) {
  4126. $file = $CFG->dataroot . '/temp/' . $key;
  4127. if (file_exists($file))
  4128. unlink($file);
  4129. }
  4130. return $file_jar;
  4131. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4132. /// Function for import the iLM from an package
  4133. // @param int $itemid Itemid of zip file
  4134. static function import_ilm ($itemid) {
  4135. global $CFG, $USER, $OUTPUT;
  4136. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4137. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4138. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4139. }
  4140. $pathtemp = $CFG->dataroot . '/temp/';
  4141. $contextuser = context_user::instance($USER->id);
  4142. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4143. $zip = new zip_packer();
  4144. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4145. foreach ($files as $file) {
  4146. if (!$file->is_directory())
  4147. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4148. }
  4149. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4150. // Verifica se o pacote possui o XML
  4151. if (!$application_xml) {
  4152. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4153. return;
  4154. } else {
  4155. $missing = "";
  4156. if (!isset($application_xml->name)) {
  4157. $missing .= "name";
  4158. }
  4159. if (!isset($application_xml->version)) {
  4160. $missing .= ", version";
  4161. }
  4162. if (!isset($application_xml->type)) {
  4163. $missing .= ", type";
  4164. }
  4165. if (!isset($application_xml->extension)) {
  4166. $missing .= ", extension";
  4167. }
  4168. if (!isset($application_xml->file_jar)) {
  4169. $missing .= ", file_jar";
  4170. }
  4171. if (!isset($application_xml->file_class)) {
  4172. $missing .= ", file_class";
  4173. }
  4174. if (!isset($application_xml->width)) {
  4175. $missing .= ", width";
  4176. }
  4177. if (!isset($application_xml->height)) {
  4178. $missing .= ", height";
  4179. }
  4180. if (!isset($application_xml->evaluate)) {
  4181. $missing .= ", evaluate";
  4182. }
  4183. if (strlen($missing) > 2) {
  4184. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4185. return;
  4186. }
  4187. }
  4188. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4189. $typec = strtolower($application_xml->type);
  4190. require_once 'ilm_handlers/' . $typec . '.php';
  4191. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4192. } // static function import_ilm($itemid)
  4193. /// Function for list iLM defaults
  4194. // @return string Return an string with a table of iLM
  4195. static function list_ilm () {
  4196. global $DB, $OUTPUT;
  4197. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4198. $str = '';
  4199. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4200. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4201. if ($iassign_ilm) {
  4202. foreach ($iassign_ilm as $ilm) {
  4203. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4204. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4205. $str .= '<tr><td>';
  4206. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4207. $str .= '<tr>';
  4208. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4209. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4210. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4211. $str .= '</tr>';
  4212. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4213. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4214. $str .= '</table>';
  4215. $str .= '</td></tr>';
  4216. }
  4217. }
  4218. $str .= '</table>';
  4219. return $str;
  4220. }
  4221. /// Function for download and install an upgrade of an iLM
  4222. // @param int $ilm_id Id of iLM
  4223. static function upgrade_ilm ($ilm_id) {
  4224. global $DB, $CFG, $USER;
  4225. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4226. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4227. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4228. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4229. if (!$result)
  4230. print_error('error_upgrade_ilm', 'iassign');
  4231. else {
  4232. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4233. $extension = explode(".", $zip_filename);
  4234. if ($extension[count($extension) - 1] != 'ipz') {
  4235. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4236. die;
  4237. }
  4238. $zip = new zip_packer();
  4239. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4240. $contextuser = context_user::instance($USER->id);
  4241. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4242. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4243. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4244. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4245. if (file_exists($zip_filename))
  4246. unlink($zip_filename);
  4247. if (empty($file_jar)) {
  4248. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4249. print_error($msg_error);
  4250. //xx print_error('error_add_ilm', 'iassign');
  4251. }
  4252. else {
  4253. $newentry = new stdClass();
  4254. $newentry->name = (String) $application_xml->name;
  4255. $newentry->version = (String) $application_xml->version;
  4256. $newentry->url = (String) $application_xml->url;
  4257. $newentry->description = $description_str;
  4258. $newentry->extension = strtolower((String) $application_xml->extension);
  4259. $newentry->file_jar = implode(",", $file_jar);
  4260. $newentry->file_class = (String) $application_xml->file_class;
  4261. $newentry->width = (String) $application_xml->width;
  4262. $newentry->height = (String) $application_xml->height;
  4263. $newentry->enable = 0;
  4264. $newentry->timemodified = time();
  4265. $newentry->author = $USER->id;
  4266. $newentry->timecreated = time();
  4267. $newentry->evaluate = (String) $application_xml->evaluate;
  4268. $newentry->parent = $ilm_id;
  4269. }
  4270. }
  4271. return $iassign_ilm->id;
  4272. } // static function upgrade_ilm($ilm_id)
  4273. //MOOC2014 -- inicio
  4274. //TODO: REVIEW
  4275. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4276. // static function move_iassign($ilm_id)
  4277. //MOOC2014 -- final
  4278. /// Function for list iLM versions with all informations
  4279. // @return string Return an string with a table of iLM
  4280. static function view_ilm ($ilmid, $from) {
  4281. global $DB;
  4282. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4283. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4284. $typec = strtolower($iassign_ilm->type);
  4285. require_once 'ilm_handlers/' . $typec . '.php';
  4286. $retorno = $typec::view_ilm($ilmid, $from);
  4287. return $retorno;
  4288. }
  4289. /// Function for get form variables for add, edit, or copy iLM params
  4290. // @param int $ilm_param_id Id of iLM param
  4291. // @param string $action String with the action
  4292. // @return object Return an object with forms variables
  4293. static function add_edit_copy_param ($ilm_param_id, $action) {
  4294. global $DB;
  4295. require_once('params_form.php');
  4296. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4297. $param = new stdClass();
  4298. $param->action = $action;
  4299. $param->ilm_param_id = $ilm_param_id;
  4300. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4301. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4302. $type = $iassign_ilm_config->param_type;
  4303. if ($action == 'add') {
  4304. $param->title = get_string('add_ilm', 'iassign');
  4305. $param->iassign_ilmid = $ilm_param_id;
  4306. $param->param_name = "";
  4307. $param->param_value = "";
  4308. $param->description = "";
  4309. $param->visible = 1;
  4310. }
  4311. elseif ($action == 'edit') {
  4312. if ($iassign_ilm_config) {
  4313. $param->title = get_string('edit_ilm', 'iassign');
  4314. $param->id = $iassign_ilm_config->id;
  4315. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4316. $param->param_type = $type; //MOOC2014
  4317. $param->param_name = $iassign_ilm_config->param_name;
  4318. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4319. $param->param_value = $iassign_ilm_config->param_value;
  4320. else //MOOC2014
  4321. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4322. $param->param_value = $iassign_ilm_config->param_value;
  4323. $param->description = $iassign_ilm_config->description;
  4324. $param->visible = $iassign_ilm_config->visible;
  4325. }
  4326. }
  4327. elseif ($action == 'copy') {
  4328. if ($iassign_ilm_config) {
  4329. $param->title = get_string('copy_ilm', 'iassign');
  4330. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4331. $param->param_type = $type; //MOOC2014
  4332. $param->param_name = $iassign_ilm_config->param_name;
  4333. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4334. $param->param_value = $iassign_ilm_config->param_value;
  4335. else //MOOC2014
  4336. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4337. $param->description = $iassign_ilm_config->description;
  4338. $param->visible = $iassign_ilm_config->visible;
  4339. }
  4340. }
  4341. return $param;
  4342. } // static function add_edit_copy_param($ilm_param_id, $action)
  4343. /// Function for change visibility of iLM param
  4344. // @param int $ilm_param_id Id of iLM param
  4345. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4346. static function visible_param ($ilm_param_id, $status) {
  4347. global $DB, $CFG;
  4348. if ($status == 0)
  4349. $visible = 1;
  4350. else
  4351. $visible = 0;
  4352. $newentry = new stdClass();
  4353. $newentry->id = $ilm_param_id;
  4354. $newentry->visible = $visible;
  4355. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4356. error(get_string('error_edit_param', 'iassign'));
  4357. }
  4358. /// Function for save in database an new iLM param
  4359. // @param object $param An object with iLM params
  4360. static function add_param ($param) {
  4361. global $DB;
  4362. $newentry = new stdClass();
  4363. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4364. //MOOC2014 $newentry->param_name = $param->param_name;
  4365. $newentry->param_type = $param->param_type; //MOOC2014
  4366. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4367. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4368. $newentry->param_value = $param->param_value;
  4369. else //MOOC2014
  4370. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4371. $newentry->description = $param->description;
  4372. $newentry->visible = $param->visible;
  4373. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4374. if (!$newentry->id) {
  4375. print_error('error_add_param', 'iassign');
  4376. }
  4377. }
  4378. /// Function for save in database a iLM param edit
  4379. // @param object $param An object with iLM params
  4380. static function edit_param ($param) {
  4381. global $DB;
  4382. $updentry = new stdClass();
  4383. $updentry->id = $param->id;
  4384. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4385. $updentry->param_type = $param->param_type; //MOOC2014
  4386. // $updentry->param_name = $param->param_name;
  4387. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4388. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4389. $updentry->param_value = $param->param_value;
  4390. else //MOOC2014
  4391. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4392. $updentry->description = $param->description;
  4393. $updentry->visible = $param->visible;
  4394. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4395. error(get_string('error_edit_param', 'iassign'));
  4396. }
  4397. }
  4398. /// Function for save in database a iLM param copy
  4399. // @param object $param An object with iLM params
  4400. static function copy_param ($param) {
  4401. global $DB;
  4402. $newentry = new stdClass();
  4403. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4404. //$newentry->param_name = $param->param_name;
  4405. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4406. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4407. $newentry->param_value = $param->param_value;
  4408. else //MOOC2014
  4409. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4410. $newentry->description = $param->description;
  4411. $newentry->visible = $param->visible;
  4412. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4413. if (!$newentry->id) {
  4414. print_error('error_add_param', 'iassign');
  4415. }
  4416. }
  4417. /// Function for delete iLM param of database
  4418. // @param int $param_id Id of iLM param
  4419. static function delete_param ($param_id) {
  4420. global $DB;
  4421. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4422. print_error('error_delete_param', 'iassign');
  4423. }
  4424. }
  4425. } // class ilm_settings
  4426. /// Class for manage iLM files (editor).
  4427. class ilm_manager {
  4428. var $id; // course id
  4429. var $url;
  4430. var $from;
  4431. /// Constructor for the base ilm_manager class
  4432. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4433. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4434. function __construct ($id, $url, $from) {
  4435. $this->id = $id; // course id
  4436. $this->url = $url;
  4437. $this->from = $from;
  4438. }
  4439. /// Function to get iAssign content file in Moodle data (exercise)
  4440. // @calledby x function preview_ilm($iassign_ilm) :
  4441. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4442. function get_file_ilm () {
  4443. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4444. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4445. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4446. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4447. $md_file = $fs->get_file_by_id($fileid);
  4448. $ilm_content_file = $md_file->get_content();
  4449. return $ilm_content_file;
  4450. }
  4451. /// Function for creating a new file from the iLM online editor
  4452. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4453. function ilm_editor_new () {
  4454. global $CFG, $DB, $OUTPUT, $PAGE;
  4455. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4456. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4457. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4458. $context = context_course::instance($this->id);
  4459. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4460. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4461. if (!$iassign) {
  4462. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4463. die();
  4464. }
  4465. $temp = explode(",", $iassign->extension);
  4466. $extension = $temp[0]; // default extension for this iLM
  4467. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4468. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4469. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4470. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4471. if ($stringArchiveContent != NULL) {
  4472. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4473. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4474. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4475. $filename = optional_param('filename', NULL, PARAM_RAW);
  4476. //Leo $filename = iassign_utils::format_filename($filename); //
  4477. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4478. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4479. //2019/02 $arrayfilename = explode(".", $filename);
  4480. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4481. //2019/02 $count_dots = count($arrayfilename);
  4482. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4483. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4484. //2019/02 if ($last_name != $extension)
  4485. //2019/02 $filename = $filename . '.' . $extension;
  4486. //2019/02 }
  4487. //2019/02 else { // no extension...
  4488. //2019/02 $filename = $filename . '.' . $extension;
  4489. //2019/02 }
  4490. // Store the name of recent created file
  4491. $_SESSION['file_name'] = $filename;
  4492. //$this->write_file_iassign($string, $filename);
  4493. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4494. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4495. die();
  4496. }
  4497. else { // if ($stringArchiveContent != NULL)
  4498. // iLM On-line editor
  4499. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4500. $str_get_iLM = "window.frames.iLM";
  4501. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4502. }
  4503. else { // otherwise it is JAR named 'iLM'
  4504. $str_get_iLM = "document.iLM";
  4505. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4506. }
  4507. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4508. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4509. $files_array = '';
  4510. foreach ($files as $value) {
  4511. if ($value->get_filename() != ".")
  4512. $files_array .= "'" . $value->get_filename() . "',";
  4513. }
  4514. $files_array .= "''";
  4515. $file = null;
  4516. $ia_content = "";
  4517. $filename = "";
  4518. $error_files_exists = get_string('error_file_exists', 'iassign');
  4519. $output = "<script type='text/javascript'>
  4520. //<![CDATA[
  4521. //D alert('locallib.php: ilm_editor_new');
  4522. function submit_iLM_Answer () {
  4523. var docFormOnLineEditor = document.formEnvio;
  4524. var resposta_exerc = new Array(3);
  4525. var valor_resposta = new Array(3);
  4526. var sessao = new Array(3);
  4527. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4528. resposta_exerc[0] = doc_iLM.getAnswer();
  4529. valor_resposta[0] = doc_iLM.getEvaluation();
  4530. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4531. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4532. var files = new Array(" . $files_array . ");
  4533. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4534. if (docFormOnLineEditor.filename.value=='') {
  4535. // ERROR: the file name is empty
  4536. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4537. return false;
  4538. }
  4539. // }
  4540. for (i=0; i<files.length; i++) {
  4541. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4542. alert('" . $error_files_exists . "');
  4543. return false;
  4544. }
  4545. }
  4546. docFormOnLineEditor.submit();
  4547. return true;
  4548. }
  4549. //]]>
  4550. </script>\n";
  4551. $output .= "
  4552. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4553. $output .= $OUTPUT->box_start();
  4554. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4555. $output .= "
  4556. <table width='100%' cellpadding='20'>
  4557. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4558. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4559. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4560. </tr>
  4561. </table>\n";
  4562. $output .= $OUTPUT->box_end();
  4563. $output .= "<center>\n";
  4564. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4565. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4566. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4567. $output .= $output_ilm;
  4568. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4569. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4570. </center>
  4571. </form>\n";
  4572. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4573. $PAGE->navbar->add($title);
  4574. $PAGE->set_title($title);
  4575. $PAGE->set_heading($title); // insert title above the navigation bar
  4576. print $OUTPUT->header();
  4577. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4578. print $output;
  4579. print $OUTPUT->footer();
  4580. }
  4581. die();
  4582. } // function ilm_editor_new()
  4583. /// Function for editing an file in online editor
  4584. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  4585. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  4586. global $CFG, $DB, $OUTPUT, $PAGE;
  4587. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4588. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4589. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4590. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4591. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4592. // If iLM is not registered, error!
  4593. if (!$iassign) {
  4594. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  4595. die;
  4596. }
  4597. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  4598. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  4599. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  4600. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  4601. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4602. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4603. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  4604. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  4605. if ($stringArchiveContent != NULL) {
  4606. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  4607. die();
  4608. } else { // if ($stringArchiveContent != NULL)
  4609. $end_file = '';
  4610. if ($content_file) {
  4611. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  4612. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  4613. }
  4614. $temp = explode(",", $iassign->extension);
  4615. $extension = $temp[0]; // default extension for this iLM
  4616. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  4617. $str_get_iLM = "window.frames.iLM";
  4618. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4619. } else { // otherwise it is JAR named 'iLM'
  4620. $str_get_iLM = "document.iLM";
  4621. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4622. }
  4623. $output = "<script type='text/javascript'>
  4624. //<![CDATA[
  4625. function submit_iLM_Answer () {
  4626. var docFormEditor = document.formEnvio;
  4627. var activityAnswer; // to get activity answer (text)
  4628. var activityValue; // to get activity answer value (float)
  4629. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4630. //activityAnswer = doc_iLM.getAnswer();
  4631. //activityValue = doc_iLM.getEvaluation();
  4632. activityAnswer = " . $str_get_iLM . ".getAnswer();
  4633. activityValue = " . $str_get_iLM . ".getEvaluation();
  4634. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  4635. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  4636. docFormEditor.submit();
  4637. return true;
  4638. }
  4639. //]]>
  4640. </script>\n";
  4641. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4642. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  4643. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4644. // return true;
  4645. // }
  4646. $output .= "
  4647. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4648. $output .= $OUTPUT->box_start();
  4649. $output .= "
  4650. <table width='100%' cellpadding='20'>
  4651. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  4652. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  4653. <input type='hidden' name='filename' value='$filename'/></td>
  4654. <td>
  4655. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4656. </tr>
  4657. </table>\n";
  4658. $output .= $OUTPUT->box_end();
  4659. $output .= " <center>\n";
  4660. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  4661. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  4662. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  4663. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  4664. </center>
  4665. </form>\n";
  4666. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4667. $PAGE->navbar->add($title);
  4668. $PAGE->set_title($title);
  4669. $PAGE->set_heading($title); // insert title above the navigation bar
  4670. print $OUTPUT->header();
  4671. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4672. print $output;
  4673. print $OUTPUT->footer();
  4674. } // else if ($stringArchiveContent != NULL)
  4675. die();
  4676. } // function ilm_editor_update()
  4677. /// Function for write iAssign file in Moodle data (exercise)
  4678. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  4679. // @param string $stringArchiveContent Content of iassign file
  4680. // @param string $filename Filename of iassign file
  4681. function write_file_iassign ($stringArchiveContent, $filename) {
  4682. global $USER;
  4683. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4684. $context = context_course::instance($this->id);
  4685. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4686. $dirid = $this->get_dir_ilm('dirid');
  4687. $dir = $fs->get_file_by_id($dirid);
  4688. $fileinfo = array('contextid' => $context->id, // ID of course
  4689. 'component' => 'mod_iassign', // usually = table name
  4690. 'filearea' => 'activity', // usually = table name
  4691. 'itemid' => 0, // usually = ID of row in table
  4692. 'filepath' => $dir->get_filepath(), // any path beginning and ending whith '/'
  4693. 'userid' => $USER->id,
  4694. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4695. 'filename' => $filename); // any filename
  4696. // Create file containing text. '$stringArchiveContent'
  4697. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4698. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  4699. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  4700. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  4701. // 'Activité interactive enregistrée avec succès sous le nom:';
  4702. // 'Atividade interativa gravada com sucesso sob o nome:'
  4703. $output = "
  4704. <script type='text/javascript'>
  4705. //<![CDATA[
  4706. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  4707. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4708. //]]>
  4709. </script>";
  4710. print $output;
  4711. die();
  4712. }
  4713. /// Function for write iAssign file in Moodle data (exercise)
  4714. // @param string $stringArchiveContent Content of iassign file
  4715. // @param string $filename Filename of iassign file
  4716. // @param int $itemid Itemid of iassign file
  4717. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  4718. global $OUTPUT, $USER;
  4719. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4720. $context = context_course::instance($this->id);
  4721. $dirid = $this->get_dir_ilm('dirid');
  4722. if ($stringArchiveContent != (-1)) {
  4723. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4724. $file = $fs->get_file_by_id($fileid);
  4725. if (!$file) {
  4726. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  4727. die;
  4728. }
  4729. $fileinfo = array('contextid' => $context->id, // ID of context
  4730. 'component' => 'mod_iassign', // usually = table name
  4731. 'filearea' => 'activity', // usually = table name
  4732. 'itemid' => 0, // usually = ID of row in table
  4733. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  4734. 'userid' => $USER->id,
  4735. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4736. 'license' => 'allrightsreserved', // allrightsreserved
  4737. 'timecreated' => $file->get_timecreated(),
  4738. 'filename' => $file->get_filename()); // any filename
  4739. $file->delete();
  4740. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4741. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  4742. }
  4743. $output = "<script type='text/javascript'>
  4744. //<![CDATA[
  4745. alert('" . get_string('sucess_update', 'iassign') . "');\n
  4746. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4747. //]]>
  4748. </script>";
  4749. print $output;
  4750. die();
  4751. }
  4752. /// Function for create an tag for iAssign filter
  4753. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  4754. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4755. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  4756. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4757. // @param int $fileid Id of file
  4758. // @return string Return an string with an tag of iassign filter
  4759. function tag_ilm ($fileid) {
  4760. global $DB;
  4761. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4762. $width = '600';
  4763. $height = '400';
  4764. $file = $fs->get_file_by_id($fileid);
  4765. $filetype = explode(".", $file->get_filename());
  4766. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  4767. foreach ($iassign_ilm as $value) {
  4768. $extensions = explode(",", $value->extension);
  4769. if (in_array($filetype[1], $extensions)) {
  4770. $width = $value->width;
  4771. $height = $value->height;
  4772. }
  4773. }
  4774. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  4775. }
  4776. /// Function for delete iAssign file in Moodle data (exercise)
  4777. function delete_file_ilm () {
  4778. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4779. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4780. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  4781. $file = $fs->get_file_by_id($fileid);
  4782. if ($file)
  4783. $file->delete();
  4784. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4785. die();
  4786. }
  4787. /// Function for delete selected iAssign file in Moodle data (exercise)
  4788. function delete_selected_ilm () {
  4789. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4790. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4791. $context = context_course::instance($this->id);
  4792. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4793. $dirid = $this->get_dir_ilm('dirid');
  4794. foreach ($files_id as $file_id) {
  4795. $file = $fs->get_file_by_id($file_id);
  4796. if ($file) {
  4797. if (!$file->is_directory())
  4798. $file->delete();
  4799. else {
  4800. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4801. foreach ($files_delete as $value)
  4802. $value->delete();
  4803. $file->delete();
  4804. }
  4805. }
  4806. }
  4807. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4808. die();
  4809. }
  4810. /// Function for duplicate iAssign file from "online" edition
  4811. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  4812. function duplicate_file_ilm () {
  4813. global $USER, $COURSE;
  4814. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4815. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4816. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4817. $filename = optional_param('filename', NULL, PARAM_RAW);
  4818. $file = $fs->get_file_by_id($fileid);
  4819. $context = context_course::instance($this->id);
  4820. $fileinfo = array(
  4821. 'contextid' => $context->id, // ID of context
  4822. 'component' => 'mod_iassign', // usually = table name
  4823. 'filearea' => 'activity', // usually = table name
  4824. 'itemid' => 0, // usually = ID of row in table
  4825. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  4826. 'userid' => $USER->id,
  4827. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4828. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  4829. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  4830. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  4831. die();
  4832. }
  4833. /// Function for rename iAssign file
  4834. function rename_file_ilm () {
  4835. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4836. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4837. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4838. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4839. $file = $fs->get_file_by_id($fileid);
  4840. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  4841. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  4842. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4843. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  4844. die();
  4845. }
  4846. /// Function for get iassign file for iassign form
  4847. function add_ilm () {
  4848. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4849. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4850. $output = "
  4851. <script type='text/javascript'>
  4852. //<![CDATA[
  4853. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  4854. iassign_file_link.innerHTML = '$filename';
  4855. window.opener.document.forms['mform1'].file.value='$fileid';
  4856. window.opener.document.forms['mform1'].filename.value='$filename';
  4857. window.close();
  4858. //]]>
  4859. </script>";
  4860. print $output;
  4861. die();
  4862. }
  4863. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  4864. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  4865. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  4866. function preview_ilm ($courseid, $iassign_ilm) {
  4867. global $OUTPUT, $CFG, $USER;
  4868. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4869. $title = get_string('modulename', 'iassign'); // iAssign
  4870. print $OUTPUT->header();
  4871. print $OUTPUT->box_start();
  4872. $javascript = "
  4873. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  4874. <script type='text/javascript'>
  4875. //<![CDATA[
  4876. function submit_close () {
  4877. window.opener.location.reload();
  4878. window.close();
  4879. }
  4880. //]]>
  4881. </script>\n";
  4882. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  4883. // to the complete "applet" tag
  4884. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  4885. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  4886. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  4887. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  4888. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  4889. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  4890. if ($ilm_name != "ivprog") {
  4891. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  4892. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  4893. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  4894. } else {
  4895. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  4896. $content_or_id_from_ilm_security = $this->get_file_ilm();
  4897. $timecreated = time();
  4898. $token = md5($timecreated);
  4899. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  4900. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  4901. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  4902. $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)
  4903. }
  4904. $html = "
  4905. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4906. <table border='1'>
  4907. <tr><td>
  4908. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  4909. <!-- iLM calls : end -->
  4910. </td></tr>
  4911. </table>
  4912. <table>
  4913. <tr>
  4914. <td align='center'>
  4915. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  4916. </td></tr>
  4917. </table>
  4918. </form>\n";
  4919. print $javascript . $html;
  4920. print $OUTPUT->box_end();
  4921. //NAO echo format_string($html); // Moodle 3.X
  4922. die();
  4923. } // function preview_ilm($courseid, $iassign_ilm)
  4924. //r_ function preview_ilm ($iassign_ilm)
  4925. //r_ /// Function for preview iassign file from iassign filter.
  4926. //r_ function preview_ilm() {
  4927. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4928. //r_ $tag_filter = $this->tag_ilm($fileid);
  4929. //r_ $javascript = "<script type='text/javascript'>
  4930. //r_ //<![CDATA[
  4931. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  4932. //r_ //]]>
  4933. //r_ </script>";
  4934. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4935. //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>
  4936. //r_ </table></form></body></html>";
  4937. //r_ echo $javascript . format_text($html);
  4938. //r_ die;
  4939. //r_ }
  4940. /// Function for export an package (zip) of iassign files
  4941. function export_files_ilm () {
  4942. global $CFG;
  4943. $context = context_course::instance($this->id);
  4944. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4945. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  4946. $zip = new zip_archive();
  4947. $zip->open($zip_filename);
  4948. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4949. foreach ($files_id as $file_id) {
  4950. $file = $fs->get_file_by_id($file_id);
  4951. if (!$file->is_directory())
  4952. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  4953. else {
  4954. $zip->add_directory($file->get_filepath());
  4955. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4956. foreach ($files_zip as $value) {
  4957. if (!$value->is_directory())
  4958. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  4959. else
  4960. $zip->add_directory($value->get_filepath());
  4961. }
  4962. }
  4963. }
  4964. $zip->close();
  4965. header("Pragma: public");
  4966. header("Expires: 0");
  4967. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4968. header("Cache-Control: private", false);
  4969. header("Content-Type: application/zip");
  4970. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  4971. header("Content-Transfer-Encoding: binary");
  4972. header("Content-Length: " . @filesize($zip_filename));
  4973. set_time_limit(0);
  4974. @readfile("$zip_filename") || die("File not found.");
  4975. unlink($zip_filename);
  4976. exit;
  4977. }
  4978. /// Function of execute a command in button editor tinymce
  4979. // @param int $fileid Id of file
  4980. function tinymce_ilm ($fileid) {
  4981. $tag_filter = $this->tag_ilm($fileid);
  4982. $output = "<script type='text/javascript'>
  4983. //<![CDATA[
  4984. var tag_filter = '$tag_filter';
  4985. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  4986. // all right, insert it
  4987. } else {
  4988. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  4989. }
  4990. // window.close();
  4991. //]]>
  4992. </script>\n";
  4993. print $output;
  4994. die();
  4995. }
  4996. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  4997. /// Function to add content to the Editor Window
  4998. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  4999. // @param int $fileid Id of file
  5000. function editor_ilm ($fileid, $editor) {
  5001. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5002. $output1 = "<script type='text/javascript'>
  5003. //<![CDATA[
  5004. var tag_filter = '$tag_filter';\n";
  5005. if ($editor == 'atto') {
  5006. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5007. } elseif ($editor == 'tinyMCE') {
  5008. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5009. } else
  5010. $output2 = "";
  5011. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5012. window.close();
  5013. //]]>
  5014. </script>\n";
  5015. //D var_dump($output);
  5016. print $output1 . $output2 . $output3;
  5017. die();
  5018. }
  5019. /// Function to add content to the Atto Editor Window
  5020. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5021. // @param int $fileid Id of file
  5022. function atto_ilm ($fileid) {
  5023. global $CFG, $DB;
  5024. $tag_filter = $this->tag_ilm($fileid);
  5025. $output = "<script type='text/javascript'>
  5026. //<![CDATA[
  5027. var tag_filter = '$tag_filter';
  5028. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5029. // all right, insert iLM tag to this editor
  5030. } else {
  5031. // error trying to insert
  5032. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5033. }
  5034. //window.close();
  5035. //]]>
  5036. </script>\n";
  5037. print $output;
  5038. die();
  5039. }
  5040. /// Function for get path and infos of dirs: dirid, dir_base, dir_parent, dir_home
  5041. // @param string $key Key for return information
  5042. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5043. function get_dir_ilm ($key) {
  5044. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5045. $context = context_course::instance($this->id);
  5046. $dirid = optional_param('dirid', 0, PARAM_INT);
  5047. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5048. if ($dirid == 0) {
  5049. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5050. $dirid = $dir->get_id();
  5051. } else {
  5052. $dir = $fs->get_file_by_id($dirid);
  5053. $dir_base = $dir->get_filepath();
  5054. }
  5055. $dir_parent = $dir->get_parent_directory();
  5056. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5057. return $data[$key];
  5058. }
  5059. /// Function for create an new dir
  5060. function new_dir_ilm () {
  5061. global $USER;
  5062. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5063. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5064. $dir_base = $this->get_dir_ilm('dir_base');
  5065. $context = context_course::instance($this->id);
  5066. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5067. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5068. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5069. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5070. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5071. }
  5072. /// Function for delete an dir
  5073. function delete_dir_ilm () { //
  5074. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5075. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5076. $context = context_course::instance($this->id);
  5077. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5078. $dir_parent = $this->get_dir_ilm('dir_parent');
  5079. if ($dir) {
  5080. if ($dir->is_directory()) {
  5081. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5082. foreach ($files_delete as $value)
  5083. $value->delete();
  5084. $dir->delete();
  5085. }
  5086. }
  5087. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5088. die();
  5089. }
  5090. /// Function for rename an dir
  5091. function rename_dir_ilm () {
  5092. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5093. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5094. $context = context_course::instance($this->id);
  5095. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5096. $dir_parent = $this->get_dir_ilm('dir_parent');
  5097. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5098. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5099. if ($dir->is_directory()) {
  5100. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5101. foreach ($files_rename_path as $value)
  5102. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5103. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5104. }
  5105. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5106. die();
  5107. }
  5108. /// Function for move an dir and your content for other dir
  5109. function selected_move_ilm () {
  5110. global $PAGE, $OUTPUT, $CFG;
  5111. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5112. $context = context_course::instance($this->id);
  5113. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5114. $dirid = $this->get_dir_ilm('dirid');
  5115. $dir_base = $this->get_dir_ilm('dir_base');
  5116. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5117. $code_javascript_ilm = "
  5118. <script type='text/javascript'>
  5119. //<![CDATA[
  5120. function getRadiobutton () {
  5121. var radioButtons = document.getElementsByTagName('input');
  5122. var param = '';
  5123. for (var counter=0; counter < radioButtons.length; counter++) {
  5124. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5125. param = radioButtons[counter].value;
  5126. }
  5127. return param;
  5128. }
  5129. function move_selected_ilm () {
  5130. var msgAnswer;
  5131. if (getRadiobutton() != '') {
  5132. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5133. if (msgAnswer)
  5134. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5135. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5136. }
  5137. else
  5138. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5139. }
  5140. function cancel_selected_ilm () {
  5141. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5142. }
  5143. //]]>
  5144. </script>\n";
  5145. $title = get_string('move_files', 'iassign');
  5146. $PAGE->set_title($title);
  5147. $PAGE->set_pagelayout('base');
  5148. print $OUTPUT->header();
  5149. print $OUTPUT->heading($title);
  5150. $dir_paths = array();
  5151. print $OUTPUT->box_start();
  5152. print "<center>";
  5153. foreach ($files_id as $file_id) {
  5154. $file = $fs->get_file_by_id($file_id);
  5155. if ($file) {
  5156. if (!$file->is_directory())
  5157. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5158. else {
  5159. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5160. array_push($dir_paths, $file->get_filepath());
  5161. }
  5162. }
  5163. }
  5164. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5165. if ($dir_base != '/') {
  5166. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5167. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5168. }
  5169. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5170. foreach ($files_tree as $file) {
  5171. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5172. $is_parent = false;
  5173. foreach ($dir_paths as $dir) {
  5174. $path = explode("/", $dir);
  5175. array_pop($path);
  5176. $path[count($path) - 1] = '';
  5177. $path = implode("/", $path);
  5178. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5179. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5180. }
  5181. if ($is_parent == false) {
  5182. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5183. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5184. }
  5185. }
  5186. }
  5187. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5188. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5189. print "</center>";
  5190. print $OUTPUT->box_end();
  5191. print $OUTPUT->footer();
  5192. print $code_javascript_ilm;
  5193. die;
  5194. }
  5195. /// Function for move files for an dir
  5196. function move_files_ilm () {
  5197. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5198. $context = context_course::instance($this->id);
  5199. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5200. $dirid = $this->get_dir_ilm('dirid');
  5201. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5202. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5203. foreach ($files_id as $file_id) {
  5204. $file = $fs->get_file_by_id($file_id);
  5205. if ($file) {
  5206. if ($file->is_directory()) {
  5207. $pathname = explode("/", $file->get_filepath());
  5208. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5209. foreach ($files_move_path as $value) {
  5210. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5211. $value->rename($path_move, $value->get_filename());
  5212. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5213. }
  5214. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5215. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5216. $file->rename($path_move, $file->get_filename());
  5217. } else {
  5218. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5219. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5220. }
  5221. }
  5222. }
  5223. //die;
  5224. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5225. die();
  5226. } // function move_files_ilm()
  5227. /// Function for recover files in use on all activities of a course
  5228. function recover_files_ilm () {
  5229. global $DB, $USER;
  5230. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5231. $courseid = optional_param('id', NULL, PARAM_INT);
  5232. $dirid = $this->get_dir_ilm('dirid');
  5233. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5234. $contextfile = context_course::instance($this->id);
  5235. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5236. foreach ($iassigns as $iassign) {
  5237. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5238. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5239. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5240. $context = context_module::instance($cm->id);
  5241. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5242. if ($files) {
  5243. foreach ($files as $value) {
  5244. $extension = explode(".", $value->get_filename());
  5245. if (!$value->is_directory()) {
  5246. $fileinfo = array('contextid' => $contextfile->id,
  5247. 'component' => 'mod_iassign',
  5248. 'filearea' => 'activity',
  5249. 'itemid' => 0,
  5250. 'filepath' => $this->get_dir_ilm('dir_base'),
  5251. 'userid' => $USER->id,
  5252. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5253. 'license' => 'allrightsreserved',
  5254. 'timecreated' => time(),
  5255. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5256. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5257. }
  5258. }
  5259. } // if ($files)
  5260. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5261. } // foreach ($iassigns as $iassign)
  5262. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5263. die();
  5264. } // function recover_files_ilm()
  5265. /// Auxiliary function the get all files in a given context
  5266. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5267. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5268. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5269. function get_files_in_context (&$allfiles, $contextid, $extension, $userid) {
  5270. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5271. // (NAO s_iassign_statement.file = s_files.id)
  5272. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5273. $dir_base = $this->get_dir_ilm('dir_base');
  5274. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5275. $countf = 0;
  5276. $array_files_id = array(); // all files from this context
  5277. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5278. //$filename = $item_fc->get_filename();
  5279. //$filepath = $item_fc->get_filepath();
  5280. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5281. //$fileuserid = $item_fc->get_userid(); // get user.id of the author
  5282. // $array_files_aux[] = $item_fc;
  5283. $itemid = $item_fc->get_id();
  5284. if (!in_array($itemid, $array_files_id)) {
  5285. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5286. $allfiles[] = $item_fc;
  5287. $array_files_id[] = $itemid;
  5288. $countf++;
  5289. }
  5290. }
  5291. return $countf;
  5292. }
  5293. /// List iassign files from course directory
  5294. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5295. function view_files_ilm ($iassign_ilm_class, $extension) {
  5296. global $CFG, $DB, $USER, $OUTPUT;
  5297. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5298. $context = context_course::instance($this->id); // $this->id = ID of the current course
  5299. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5300. $dirid = $this->get_dir_ilm('dirid');
  5301. $dir_base = $this->get_dir_ilm('dir_base');
  5302. // Get all files in module iAssign
  5303. // -- start
  5304. $array_all_files = array(); // all files from all context.id (in data decreasing order)
  5305. $array_contextid_files = array(); // context.id in data decreasing order
  5306. $array_contextid_files_aux = array(); // all context.id in data creasing order
  5307. // Get all files from table '*_files': id ; contenthash ; pathnamehash ; contextid ; component ;... filename ; userid ...
  5308. // $DB is 'mysqli_native_moodle_database' object
  5309. if (!has_capability("moodle/site:config", $context, $USER->id, true)) // *_capabilities="moodle/site:config" : greatest one
  5310. $array_query = array('component' => 'mod_iassign');
  5311. else
  5312. $array_query = array('component' => 'mod_iassign', 'userid' => $USER->id);
  5313. $files_iassign = $DB->get_records('files', $array_query); // extensions for all iLM...
  5314. $count_all_files = 0;
  5315. $count_files_with_ext = 0;
  5316. $count_thisauthor_contextid = 0;
  5317. $count_otherauthors_contextid = 0;
  5318. foreach ($files_iassign as $item_files_iassign) {
  5319. $extensionF = explode(".", $item_files_iassign->filename); // $item_files_iassign->get_filename()
  5320. $lastitem = sizeof($extensionF);
  5321. if ($lastitem>0) $lastitem--;
  5322. else // error: it must have extension (after ".")
  5323. continue;
  5324. $str_extension = $extensionF[$lastitem];
  5325. $count_files_with_ext++;
  5326. if ($extension == $str_extension) {
  5327. $contextid = $item_files_iassign->contextid;
  5328. if (!in_array($contextid, $array_contextid_files_aux)) { // not yet in array of context with this extension
  5329. $total_in_context = $this->get_files_in_context($array_all_files, $contextid, $extension, $USER->id); // $array_all_files by reference
  5330. $count_all_files += $total_in_context;
  5331. }
  5332. }
  5333. }
  5334. //TODO Deste modo vem: se ADMIN => todos os arquivos de extensao compativel; senao todos os arquivos do usuario
  5335. //TODO Implementar: se NAO ADMIN => pegar TODOS os arquivos do curso
  5336. //TODO Tabela pegar todos '*_files.contextid' tais que '*_files.component=="mod_iassign"'
  5337. $array_files_course = array();
  5338. for ($ii=$count_all_files-1; $ii>0; $ii--) {
  5339. //$contextid = $array_contextid_files[$ii];
  5340. //$files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5341. //$array_files_course[] = $files_course;
  5342. $files_course = $array_all_files[$ii];
  5343. $files_array = '';
  5344. $files_array .= "''";
  5345. $error_files_exists = get_string('error_file_exists', 'iassign');
  5346. $dirs_array = '';
  5347. foreach ($files_course as $one_file) {
  5348. if (!$one_file->is_directory())
  5349. $files_array .= "'" . $one_file->get_filename() . "',";
  5350. else { //if ($one_file->is_directory())
  5351. $pathname = explode("/", substr($one_file->get_filepath(), 0, strlen($one_file->get_filepath()) - 1));
  5352. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5353. }
  5354. } // foreach ($files_course as $one_file)
  5355. } // for ($ii=0; $ii<$num_contexts; $ii++)
  5356. print "#" . $count_all_files . "<br/>";
  5357. // -- end
  5358. $dirs_array .= "''";
  5359. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5360. //TODO Rever o 'preview' pois soh poder deixar ver uma vez
  5361. $code_javascript_ilm = "
  5362. <script type='text/javascript'>
  5363. //<![CDATA[
  5364. function preview_ilm (fileid, ilmid) { //JavaScript function
  5365. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5366. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5367. }
  5368. function update_ilm (ilmid, fileid) { //JavaScript function
  5369. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5370. }
  5371. function delete_ilm (ilmid, fileid) { //JavaScript function
  5372. var msgAnswer;
  5373. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5374. if (msgAnswer) {
  5375. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5376. }
  5377. }
  5378. function delete_selected_ilm () { //JavaScript function
  5379. var msgAnswer;
  5380. var param = getCheckbox();
  5381. if (param.join() != '') {
  5382. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5383. if (msgAnswer)
  5384. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5385. }
  5386. else
  5387. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5388. }
  5389. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5390. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5391. }
  5392. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5393. var filenamecopy;
  5394. var i;
  5395. var files = new Array($files_array);
  5396. do {
  5397. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5398. } while (filenamecopy == '');
  5399. if (filenamecopy == null)
  5400. return false;\n
  5401. else {
  5402. for (i=0;i<files.length;i++) {
  5403. if (files[i]==filenamecopy) {
  5404. alert('$error_files_exists');
  5405. return false;\n
  5406. }
  5407. }\n" .
  5408. // @see: function 'duplicate_file_ilm()' above
  5409. "
  5410. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5411. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5412. } // else
  5413. }
  5414. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5415. var filenamecopy;
  5416. var i;
  5417. var files = new Array($files_array);
  5418. do {
  5419. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5420. } while (filenamecopy == '');
  5421. if (filenamecopy == null)
  5422. return false;
  5423. else {
  5424. for (i=0;i<files.length;i++) {
  5425. if (files[i]==filenamecopy) {
  5426. alert('$error_files_exists');
  5427. return false;
  5428. }
  5429. }
  5430. 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;
  5431. }
  5432. }
  5433. function export_files_ilm () { //JavaScript function
  5434. var param = getCheckbox();
  5435. if (param.join() != '')
  5436. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5437. else
  5438. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5439. }
  5440. function select_all_ilm () { //JavaScript function
  5441. var checkBoxes = document.getElementsByTagName('input');
  5442. var selectAll = document.getElementById('select_all');
  5443. for (var counter=0; counter < checkBoxes.length; counter++) {
  5444. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5445. checkBoxes[counter].checked = selectAll.checked;
  5446. }
  5447. }
  5448. function getCheckbox () { //JavaScript function
  5449. var checkBoxes = document.getElementsByTagName('input');
  5450. var param = new Array();
  5451. for (var counter=0; counter < checkBoxes.length; counter++) {
  5452. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5453. param.push(checkBoxes[counter].value);
  5454. }
  5455. return param;
  5456. }
  5457. function new_dir_ilm () { //JavaScript function
  5458. var dirname = '';
  5459. var i;
  5460. var dirs = new Array($dirs_array);
  5461. do {
  5462. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5463. } while (dirname == '');
  5464. if (dirname == null)
  5465. return false;\n
  5466. else {
  5467. for (i=0;i<dirs.length;i++) {
  5468. if (dirs[i]==dirname) {
  5469. alert('$error_dir_exists');
  5470. return false;\n
  5471. }
  5472. }
  5473. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5474. }
  5475. }
  5476. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5477. var msgAnswer;
  5478. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5479. if (msgAnswer) {
  5480. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5481. }
  5482. }
  5483. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5484. var dirnamecopy;
  5485. var i;
  5486. var dirs = new Array($dirs_array);
  5487. do {
  5488. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5489. } while (dirnamecopy == '');
  5490. if (dirnamecopy == null)
  5491. return false;\n
  5492. else {
  5493. for (i=0;i<dirs.length;i++) {
  5494. if (dirs[i]==dirnamecopy) {
  5495. alert('$error_dir_exists');
  5496. return false;\n
  5497. }
  5498. }
  5499. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5500. }
  5501. }
  5502. function move_selected_ilm (ilmid) { //JavaScript function
  5503. var param = getCheckbox();
  5504. if (param.join() != '')
  5505. 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();
  5506. else
  5507. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5508. }
  5509. function recover_files_ilm () { //JavaScript function
  5510. var msgAnswer;
  5511. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5512. if (msgAnswer) {
  5513. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5514. }
  5515. }
  5516. window.onload = function() { //JavaScript function
  5517. var xPosition = 0;
  5518. var yPosition = 0;
  5519. element=document.getElementById('new_file');
  5520. while(element) {
  5521. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5522. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5523. element = element.offsetParent;
  5524. }
  5525. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5526. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5527. location.hash = '#new_file';
  5528. };
  5529. //]]>
  5530. </script>\n"; // end of $code_javascript_ilm
  5531. $output = "";
  5532. $select_all = "";
  5533. $count_files = 0;
  5534. $extensions_allow = array();
  5535. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  5536. foreach ($iassign_ilm as $item_iassign_ilm)
  5537. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  5538. //Estava foreach ($files_course as $one_file)
  5539. for ($ii=$count_all_files-1; $ii>0; $ii--) { // function view_files_ilm ($iassign_ilm_class, $extension)
  5540. //$contextid = $array_contextid_files[$ii]; // Notice: Undefined offset: 2257 in /var/www/html/saw/mod/iassign/locallib.php on line 6333
  5541. //$files_course = $array_files_course[$ii];
  5542. $one_file = $array_all_files[$ii];
  5543. $filename = $one_file->get_filename();
  5544. $filepath = $one_file->get_filepath();
  5545. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  5546. $pathname = $pathname[count($pathname) - 1];
  5547. $fileid = $one_file->get_id();
  5548. $tmp = explode(".", $filename);
  5549. if (is_array($tmp)) { // define file type
  5550. if (sizeof($tmp)>1)
  5551. $filetype = $tmp[1];
  5552. else
  5553. $filetype = $extension;
  5554. }
  5555. else
  5556. $filetype = $extension;
  5557. $author = $one_file->get_author();
  5558. $timemodified = date("d/m/Y H:i:s", $one_file->get_timemodified());
  5559. $timecreated = date("d/m/Y H:i:s", $one_file->get_timecreated());
  5560. $extensions = explode(",", $extension);
  5561. if (in_array(strtolower($filetype), $extensions) || $one_file->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  5562. $count_files ++;
  5563. // buscar fileid nas tabelas do iassign
  5564. $list_filein_use = "";
  5565. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5566. if ($iassign_statement_activity_list) {
  5567. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5568. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  5569. }
  5570. }
  5571. $array_iassign_ilm = $DB->get_records("iassign_ilm", array('extension' => $filetype, 'parent' => '0', 'enable' => '1'));
  5572. foreach ($array_iassign_ilm as $iassign_ilm) { // get files from all iLM equivalent
  5573. if (!$iassign_ilm) {
  5574. $iassign_ilm = new stdClass();
  5575. $iassign_ilm->id = $ilmid;
  5576. }
  5577. // Do not use $var inside "..." - problem with some "unusual" operational system
  5578. $url = $CFG->wwwroot . "/pluginfile.php/" . $one_file->get_contextid() . "/mod_iassign/activity";
  5579. $fileurl = $url . '/' . $one_file->get_itemid() . $filepath . $filename;
  5580. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  5581. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  5582. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5583. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5584. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5585. $check_select = "";
  5586. $link_rename = "";
  5587. $link_delete = "";
  5588. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5589. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5590. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5591. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  5592. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5593. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5594. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5595. if ($one_file->get_userid() == $USER->id) {
  5596. if ($iassign_statement_activity_list) {
  5597. $check_select = "";
  5598. $link_edit = iassign_icons::insert('edit_iassign_disable');
  5599. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  5600. $link_rename = "";
  5601. }
  5602. else {
  5603. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  5604. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  5605. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  5606. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  5607. }
  5608. } // if ($one_file->get_userid() == $USER->id)
  5609. if (!in_array($filetype, $extensions_allow)) {
  5610. $link_edit = "";
  5611. $link_add_ilm_iassign = "";
  5612. $link_add_ilm_tinymce = "";
  5613. $link_add_ilm_atto = "";
  5614. $link_filter = "";
  5615. }
  5616. if ($one_file->is_directory()) {
  5617. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  5618. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  5619. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  5620. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  5621. <td><center>$author</center></td>
  5622. <td><center>$timecreated</center></td>
  5623. <td><center>$timemodified</center></td></tr>\n";
  5624. }
  5625. else if ($this->from == 'iassign') {
  5626. $new_id = "";
  5627. $new_class = "";
  5628. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  5629. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  5630. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  5631. }
  5632. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  5633. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5634. <td><center>$author</center></td>
  5635. <td><center>$timecreated</center></td>
  5636. <td><center>$timemodified</center></td></tr>\n";
  5637. }
  5638. else if ($this->from == 'block') {
  5639. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  5640. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5641. <td><center>$author</center></td>
  5642. <td><center>$timecreated</center></td>
  5643. <td><center>$timemodified</center></td></tr>\n";
  5644. }
  5645. else if ($this->from == 'tinymce') {
  5646. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  5647. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5648. <td><center>$author</center></td>
  5649. <td><center>$timecreated</center></td>
  5650. <td><center>$timemodified</center></td></tr>\n";
  5651. }
  5652. else if ($this->from == 'atto') {
  5653. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  5654. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5655. <td><center>$author</center></td>
  5656. <td><center>$timecreated</center></td>
  5657. <td><center>$timemodified</center></td></tr>\n";
  5658. }
  5659. } // foreach ($array_iassign_ilm as $iassign_ilm)
  5660. } // if (in_array(strtolower($filetype), $extensions) || $one_file->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto')
  5661. } // for ($ii=$count_all_files-1; $ii>0; $ii--) // for ($ii=0; $ii<$num_contexts; $ii++)
  5662. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  5663. $dir_base = "";
  5664. $header = "";
  5665. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  5666. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  5667. foreach ($basename as $value) {
  5668. $dir_base .= $value . "/";
  5669. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  5670. if ($dir_id) {
  5671. if ($value == "") {
  5672. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5673. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  5674. } else {
  5675. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5676. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  5677. }
  5678. }
  5679. } // foreach ($basename as $value)
  5680. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  5681. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  5682. $html .= "
  5683. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  5684. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  5685. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  5686. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  5687. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  5688. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  5689. </table>\n";
  5690. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  5691. $html .= "<table width='100%'><tr>\n";
  5692. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  5693. if ($count_files != 0) {
  5694. $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";
  5695. $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";
  5696. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  5697. }
  5698. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  5699. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  5700. $html .= "</form>\n";
  5701. print $code_javascript_ilm;
  5702. print $html;
  5703. } // function view_files_ilm($extension)
  5704. } // class ilm_manager
  5705. /// Class to insert of icons
  5706. class iassign_icons {
  5707. static function insert ($icon) {
  5708. global $CFG;
  5709. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  5710. return $string;
  5711. }
  5712. }
  5713. /// Class with util functions for plugin manage
  5714. class iassign_utils {
  5715. /// Function to return the filename extension
  5716. // @param string The $filename as an string
  5717. // @return string Return an string (last group after '.')
  5718. static function filename_extension ($filename) {
  5719. if ($filename == null || $filename == '') {
  5720. return null;
  5721. }
  5722. $itens = explode('.', $filename);
  5723. $num = count($itens);
  5724. if ($num < 2) {
  5725. return null;
  5726. }
  5727. return $itens[$num - 1];
  5728. }
  5729. /// Use the PHP class/package ZipArchive to create a Zip file
  5730. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  5731. // Warning: ZipArchive::close(): Failure to create temporary file: No such file or directory in /var/www/html/.../lib/filestorage/zip_archive.php on line 224
  5732. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  5733. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  5734. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  5735. $zip = new zip_archive(); //2
  5736. $res = $zip->open($full_path_zip_filename);
  5737. $total_vet = count($vet_student_filename);
  5738. for ($ii=0; $ii<$total_vet; $ii++) {
  5739. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  5740. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  5741. }
  5742. $ret = $zip->close();
  5743. iassign_utils::download_file($full_path_zip_filename);
  5744. $filenameZip = $zip->filename;
  5745. return array($ret, $zip);
  5746. }
  5747. static function download_file ($zip_filename) {
  5748. header("Pragma: public");
  5749. header("Expires: 0");
  5750. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5751. header("Cache-Control: private", false);
  5752. header("Content-Type: application/zip");
  5753. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5754. header("Content-Transfer-Encoding: binary");
  5755. header("Content-Length: " . @filesize($zip_filename));
  5756. set_time_limit(0);
  5757. @readfile("$zip_filename") || die("File not found.");
  5758. unlink($zip_filename);
  5759. }
  5760. /// Function for format filename remove special caracters
  5761. // @param string $text String for clean
  5762. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  5763. // @return string Return an string in clean format
  5764. static function format_filename ($text) {
  5765. if ($text != '.') {
  5766. //D $text = htmlspecialchars(urldecode($text));
  5767. //D echo "locallib.php: format_filename: $text<br/>";
  5768. if (is_object($text)) // with iAssign did not filtered text from JSON format
  5769. $text = json_decode($text)->{current_language()};
  5770. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  5771. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  5772. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  5773. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  5774. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  5775. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  5776. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  5777. // E.g. text = "exerc_midpoint.course.geo"
  5778. // 0123456789012345678901234
  5779. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  5780. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  5781. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  5782. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  5783. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  5784. //$ext = strrpos($text, ".");
  5785. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  5786. //$text = str_replace($array1, $array2, $text);
  5787. }
  5788. return $text;
  5789. }
  5790. /// Function to filter characters to the file name to iLM content
  5791. // @param string $text String for clean
  5792. // @param string $ext String ot the extension of the iLM
  5793. // @return string Return an string in clean format
  5794. static function filter_filename_extension ($filename, $ext) {
  5795. if ($filename != '.') {
  5796. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  5797. $arrTo = array("_","","","","","","","","","","","","");
  5798. $filename = str_replace($arrFrom, $arrTo, $filename);
  5799. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  5800. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  5801. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  5802. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  5803. $index_lastposition = strlen($filenameF);
  5804. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  5805. $text = str_replace(".", "_", $text); // erase all other "."
  5806. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  5807. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  5808. }
  5809. else
  5810. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  5811. return $filenameF;
  5812. }
  5813. /// Function for format pathname remove special caracters
  5814. // @param string $text String for clean
  5815. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5816. // @return string Return an string in clean format
  5817. static function format_pathname ($text, $is_lowercase = true) {
  5818. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5819. $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", "-", "_", "", "", "");
  5820. $text = str_replace($array1, $array2, $text);
  5821. if ($is_lowercase)
  5822. $text = strtolower($text);
  5823. return $text;
  5824. }
  5825. /// Function for format file name from iLM original name
  5826. // @param string $text String to build the file neam
  5827. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5828. // @return string Return an string in clean format
  5829. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  5830. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5831. $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", "-", "_", "", "", "");
  5832. $index_firstposition_blank = strpos($ilm_name, " ");
  5833. if ($index_firstposition_blank) { // truncate the name!
  5834. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  5835. }
  5836. $index_firstposition_dots = strpos($ilm_name, ":");
  5837. if ($index_firstposition_dots) { // truncate the name!
  5838. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  5839. }
  5840. $namefiltered = str_replace($array1, $array2, $ilm_name);
  5841. if ($is_lowercase)
  5842. $namefiltered = strtolower($namefiltered);
  5843. return $namefiltered;
  5844. }
  5845. /// Function for insert version in the filename
  5846. // @param string $filename Name of file
  5847. // @return string Return the filename with version
  5848. static function version_filename ($filename) {
  5849. $array_filename = explode('.', $filename);
  5850. if (count($array_filename) > 1)
  5851. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  5852. else
  5853. $filename = $array_filename[0] . '-' . date("Ymd-His");
  5854. return $filename;
  5855. }
  5856. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  5857. static function remove_code_message ($string) {
  5858. $array = explode("&lt;ia_uc&gt;", $string);
  5859. return $array[0];
  5860. }
  5861. }
  5862. // class iassign_utils
  5863. /// Class with language functions for plugin manage
  5864. class iassign_language {
  5865. /// Function for return text in language or get default language (en)
  5866. // @param string $lang Code of language
  5867. // @param string $description JSON text content all languages
  5868. // @return string Return an string in the language selected
  5869. static function get_description_lang ($lang, $descriptions) {
  5870. $description_lang = "";
  5871. $description = json_decode($descriptions);
  5872. if ($description == null) {
  5873. $description_lang = $descriptions;
  5874. }
  5875. else {
  5876. if (isset($description->{$lang}))
  5877. $description_lang = $description->{$lang};
  5878. else
  5879. if (isset($description->en)) //MOOC2014
  5880. $description_lang = $description->en;
  5881. else //MOOC2014
  5882. $description_lang = "en"; //MOOC2014
  5883. }
  5884. return $description_lang;
  5885. }
  5886. /// Function for return all language supported by iLM
  5887. // @param string $descriptions JSON text content all languages
  5888. // @return string Return as string with all languages
  5889. static function get_all_lang ($descriptions) {
  5890. $langs = "";
  5891. $description = json_decode($descriptions);
  5892. if ($description) {
  5893. foreach ($description as $key => $value) {
  5894. $langs .= $key . " ; ";
  5895. }
  5896. $langs = substr($langs, 0, strlen($langs) - 3);
  5897. }
  5898. return $langs;
  5899. }
  5900. /// Function for convert json in xml //MOOC2014
  5901. // @param string $json JSON text
  5902. // @return string Return as string with xml tags
  5903. static function json_to_xml ($json) {
  5904. $xml = "";
  5905. $json = json_decode($json);
  5906. foreach ($json as $key => $value) {
  5907. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  5908. }
  5909. return $xml;
  5910. }
  5911. }
  5912. // class iassign_language
  5913. /// Class with log functions for plugin manage.
  5914. class iassign_log {
  5915. /// Function for insert log event
  5916. // @param string $action Code action of event
  5917. // @param string $information Text for describe action of event
  5918. // @param int $cmid Id of context module
  5919. // @param int $ilmid Id of iLM
  5920. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  5921. global $COURSE, $CFG, $USER, $DB;
  5922. $newentry = new stdClass();
  5923. $newentry->time = time();
  5924. $newentry->userid = $USER->id;
  5925. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  5926. $newentry->course = $COURSE->id;
  5927. $newentry->cmid = $cmid;
  5928. $newentry->ilmid = $ilmid;
  5929. $newentry->action = $action;
  5930. $newentry->info = $information;
  5931. $newentry->language = current_language();
  5932. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  5933. if (ini_get("browscap") && function_exists('get_browse')) {
  5934. $browser = get_browse(null, true);
  5935. $newentry->javascript = $browser['javascript'];
  5936. $newentry->java = $browser['javaapplets'];
  5937. }
  5938. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  5939. print_error('error_add_log', 'iassign');
  5940. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  5941. } // class iassign_log