1
0

locallib.php 386 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.4 2020/05/28
  7. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  8. *
  9. * - v 4.9.3 2020/01/16
  10. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  11. *
  12. * - v 4.9.2 2019/03/13
  13. * + Several fixes to allow iLM under HTML stack
  14. *
  15. * - v 4.9.1 2017/11/02
  16. * + 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")
  17. * + 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)'
  18. *
  19. * - v 4.9 2017/03/13
  20. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  21. *
  22. * - v 4.8 2016/05/12
  23. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  24. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  25. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  26. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  27. * replaced by
  28. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  29. * - v 4.7 2016/02/17
  30. * + 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(...)')
  31. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  32. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  33. * + 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)
  34. * + 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'
  35. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  36. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  37. *
  38. * --------------- (code bellow was used at our MOOC 2014)
  39. * - v 4.6 2014/02/25
  40. * + Fix bugs in filter function for open applets.
  41. * - v 4.5 2014/02/24
  42. * + Fix bugs in params.
  43. * + Insert new param type.
  44. * - v 4.4 2014/01/24
  45. * + Allow select type of params.
  46. * + Insert the use of applet params specific for activities.
  47. * - v 4.3 2014/01/23
  48. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  49. * - v 4.2 2016/02/13
  50. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  51. * --------------- (above code used at our MOOC 2014)
  52. *
  53. * - v 4.1 2013/12/13
  54. * + Insert log in iAssign actions.
  55. * + 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).
  56. * + Insert class for Log actions in system.
  57. * - v 4.0 2013/10/31
  58. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  59. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  60. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  61. * - v 3.9 2013/10/25
  62. * + Insert support of upgrade iLM.
  63. * + Insert support for more than one extension in iLM.
  64. * + Fix bugs in verion control.
  65. * - v 3.8 2013/09/19
  66. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  67. * - v 3.7 2013/09/12
  68. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  69. * + 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).
  70. * - v 3.6 2013/09/05
  71. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  72. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  73. * + Change tag APPLET in function ilm_settings::view_ilm.
  74. * - v 3.5 2013/08/26
  75. * + Fix bug in download package iassign without answers (iassign::report).
  76. * - v 3.4 2013/08/23
  77. * + Fix bug in export package iassign.
  78. * - v 3.3 2013/08/22
  79. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  80. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  81. * - v 3.2 2013/08/21
  82. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  83. * + Change functions for import files for ilm_manager.php.
  84. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  85. * - v 3.1 2013/08/15
  86. * + Change return file selected (ilm_manager::add_ilm).
  87. * + 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).
  88. * - v 3.0 2013/08/02
  89. * + 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).
  90. * - v 2.9 2013/08/01
  91. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  92. * - v 2.8 2013/07/25
  93. * + Insert the activity name in header of view (activity::view_dates).
  94. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  95. * - v 2.7 2013/07/24
  96. * + Create link previous and next for student view in one activity (activity::view_dates).
  97. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  98. * - v 2.6 2013/07/23
  99. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  100. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  101. * - v 2.5 2013/07/12
  102. * + 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).
  103. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  104. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  105. *
  106. * @author Patricia Alves Rodrigues
  107. * @author Leônidas O. Brandão
  108. * @contributor Igor Moreira Félix (2018-)
  109. * @contributor Márcio de Lima Passos (2014)
  110. * @version v 4.9.2 2019/03/13
  111. * @version v 4.8 2016/05/12
  112. * @package mod_iassign_lib
  113. * @since 2010/09/27
  114. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  115. *
  116. * <b>License</b>
  117. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  118. */
  119. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  120. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  121. //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"'
  122. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  123. /**
  124. * Standard base class for all iAssign
  125. */
  126. class iassign {
  127. var $cm;
  128. var $course;
  129. var $iassign;
  130. var $striassign;
  131. var $striassigns;
  132. var $context;
  133. var $activity;
  134. var $iassign_up;
  135. var $iassign_down;
  136. var $action;
  137. var $iassign_submission_current;
  138. var $userid_iassign;
  139. var $bottonPost;
  140. var $write_solution;
  141. var $view_iassign;
  142. // 3.1 update PHP 7.0 compatibility for all moodle versions
  143. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  144. /// Constructor for the base iassign class
  145. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  146. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  147. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  148. function __construct ($iassign, $cm, $course) {
  149. global $COURSE, $CFG, $USER, $DB;
  150. $botton = optional_param('botton', NULL, PARAM_TEXT);
  151. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  152. if (!is_null($botton))
  153. $USER->iassignEdit = $botton;
  154. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  155. // 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'
  156. $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"
  157. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  158. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  159. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  160. $this->action = optional_param('action', NULL, PARAM_TEXT);
  161. $this->cm = $cm;
  162. $this->context = context_module::instance($this->cm->id);
  163. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  164. $this->userid_iassign = $USER->id;
  165. if ($course) {
  166. $this->course = $course;
  167. }
  168. else if ($this->cm->course == $COURSE->id) {
  169. $this->course = $COURSE;
  170. }
  171. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  172. print_error('invalidid', 'iassign');
  173. }
  174. $this->coursecontext = context_course::instance($this->course->id);
  175. if ($iassign) {
  176. $this->iassign = $iassign;
  177. }
  178. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  179. print_error('invalidid', 'iassign');
  180. }
  181. $USER->context = context_module::instance($this->cm->id);
  182. $USER->cm = $this->cm->id;
  183. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  184. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  185. $this->context = context_module::instance($this->cm->id);
  186. $this->striassign = get_string('modulename', 'iassign');
  187. $this->striassigns = get_string('modulenameplural', 'iassign');
  188. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  189. $this->bottonPost = 0;
  190. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  191. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  192. $this->view();
  193. } // function __construct($iassign, $cm, $course)
  194. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  195. // This method provides the page to view each iLM with any interactive activity
  196. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  197. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  198. global $USER, $DB, $OUTPUT;
  199. // $iassign_statementid = $this->iassign->iassign_statementid;
  200. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  201. $iassign_statementid = $this->activity->get_activity()->id;
  202. else
  203. $iassign_statementid = "";
  204. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  205. // If this user has no capability to View 'iassign': stop here
  206. require_capability('mod/iassign:view', $this->context);
  207. // Trigger module view event
  208. $event = \mod_iassign\event\course_module_viewed::create(array(
  209. 'objectid' => $this->iassign->id,
  210. 'context' => $this->context
  211. ));
  212. $event->add_record_snapshot('course', $this->course);
  213. $event->trigger();
  214. if ($this->action) { // when student do/redo activity or teacher see student solution
  215. $this->action(); // calls '$this->view_iLM();'
  216. }
  217. else {
  218. print $OUTPUT->header();
  219. $this->view_iassigns(); // show the iLM with the content
  220. print $OUTPUT->footer();
  221. }
  222. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  223. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //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" }
  226. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //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" }
  229. //D else echo "Apagou!<br/>";
  230. die();
  231. } // function view()
  232. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  233. function action () {
  234. global $USER;
  235. // action:
  236. // up - move up activity (mover atividade para cima)
  237. // down - move down activity (mover atividade para baixo)
  238. // visible - view/hide activity (exibir/ocultar atividade)
  239. // delete - delete activity (excluir atividade)
  240. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  241. // deleteno - does not erase activity (não apaga atividade)
  242. // add - add activity (adicionar atividade)
  243. // edit - edit activity (modificar atividade)
  244. $action_iassign = array(
  245. 'newcomment' => '$this->add_comment();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();');
  253. $action_iassign_limit = array(
  254. 'view' => '$this->view_iassign_current();',
  255. //'newcomment' => '$this->get_answer();',
  256. 'viewsubmission' => '$this->view_iassign_current();',
  257. 'edit_status' => '$this->edit_status();',
  258. 'edit_grade' => '$this->edit_grade();',
  259. 'export_csv' => '$this->export_csv();',
  260. 'report' => '$this->report();',
  261. 'print' => '$this->report();',
  262. 'stats' => '$this->stats();',
  263. 'printstats' => '$this->stats();');
  264. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  265. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  266. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  267. 'visible' => '$this->activity->visible_iassign($this->return);',
  268. 'delete' => '$this->activity->delete($this->return);',
  269. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  270. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  271. 'add' => '$this->add_edit_iassign();',
  272. 'edit' => '$this->add_edit_iassign();',
  273. 'get_answer' => '$this->get_answer();',
  274. 'duplicate_activity' => '$this->duplicate_activity();',
  275. 'move_activity' => '$this->move_activity();',
  276. 'auto_evaluate' => '$this->auto_evaluate();',
  277. 'all_submissions' => '$this->all_submissions();',
  278. 'delete_submissions' => '$this->delete_submissions();',
  279. 'download_submissions' => '$this->download_submissions();',
  280. 'open_individual_submission' => '$this->open_individual_submission();',
  281. 'get_individual_submission' => '$this->get_individual_submission();',
  282. 'get_student_submission' => '$this->get_student_submission();',
  283. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  284. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  285. );
  286. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  287. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  288. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  289. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  290. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  291. }
  292. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  293. eval($action_iassign_limit[$this->action]);
  294. }
  295. else { // Student reaches this point
  296. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  297. // Arrive here with: "get_answer"; "view"
  298. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  299. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  300. }
  301. } // function action()
  302. /// This method prints the student submission to a specific exercise
  303. function get_student_submission () {
  304. global $DB;
  305. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  306. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  307. if (!$student || !$exercise) exit;
  308. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  309. if ($iassign_submission)
  310. print($iassign_submission->answer);
  311. die();
  312. }
  313. /// This method prints the teacher exercise
  314. function get_teacher_exercise () {
  315. global $DB, $COURSE;
  316. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  317. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  318. $fs = get_file_storage(); // Get reference to all files in Moodle data
  319. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  320. foreach ($files as $file) {
  321. if ($file->get_filename() != ".") {
  322. print($file->get_content());
  323. }
  324. }
  325. die();
  326. }
  327. /// This method receives the data from auto_eval event
  328. /// @see auto_evaluate()
  329. function post_auto_eval_result () {
  330. global $COURSE, $CFG, $USER, $DB;
  331. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  332. exit;
  333. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  334. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  335. $student = optional_param('student', -1, PARAM_INT);
  336. $grade = optional_param('grade', 0, PARAM_FLOAT);
  337. // 1: Recuperar a nota atual:
  338. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  339. // 2: Atualizar a tabela:
  340. $update_entry = new stdClass();
  341. $update_entry->id = $actual->id;
  342. $update_entry->previous_grade = $actual->grade;
  343. $update_entry->grade = $grade;
  344. // Update the iassign_submission
  345. $DB->update_record("iassign_submission", $update_entry);
  346. }
  347. /// Function to help download all_submissions files
  348. function download_submissions_help ($list) {
  349. global $DB, $CFG, $OUTPUT;
  350. // Get list of iLMs
  351. $ilm_list = $DB->get_records("iassign_ilm");
  352. // Get list of enrolled students:
  353. $params_temp = array('shortname' => 'student');
  354. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  355. $context = context_course::instance($this->course->id);
  356. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  357. $students_list = $DB->get_records_sql(
  358. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  359. $json_obj = new stdclass();
  360. $json_obj->submissions = [];
  361. $csvfields = [];
  362. $csvfields[] = 'submissionid';
  363. $csvfields[] = 'file';
  364. $csvfields[] = 'filesize';
  365. $csvfields[] = 'timestamp';
  366. $csvfields[] = 'humandate';
  367. $csvfields[] = 'grade';
  368. $csvfields[] = 'userid';
  369. $csvfields[] = 'exerciseid';
  370. $json_obj->submissions[] = $csvfields;
  371. $exercise_dir = [];
  372. $exercises_list = [];
  373. foreach ($list as $item) {
  374. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  375. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  376. $exercises_list[] = $temp;
  377. $exercise_dir[] = $temp->id;
  378. }
  379. }
  380. $student_dir = [];
  381. $students_list = [];
  382. foreach ($list as $item) {
  383. if (!in_array($item->userid, $student_dir)) {
  384. $temp = $DB->get_record("user", array("id" => $item->userid));
  385. $students_list[] = $temp;
  386. $student_dir[] = $temp->id;
  387. }
  388. }
  389. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  390. //TODO: tem que criar moodledata/temp/iassign_files
  391. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  392. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  393. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  394. $zip = new zip_archive(); // create ZIP
  395. $zip->open($zip_filename);
  396. foreach ($exercises_list as $exercise) {
  397. $dir_ex = iassign_utils::format_filename($exercise->name);
  398. $zip->add_directory($dir_ex);
  399. $extension_ilm = '';
  400. foreach ($ilm_list as $ilm) {
  401. if ($exercise->iassign_ilmid == $ilm->id) {
  402. $extension_ilm = $ilm->extension;
  403. break;
  404. }
  405. }
  406. foreach ($students_list as $student) {
  407. $individual_dir =
  408. $dir_ex . DIRECTORY_SEPARATOR .
  409. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  410. $zip->add_directory($individual_dir);
  411. $i = 1;
  412. foreach($list as $item) {
  413. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  414. $date = new DateTime();
  415. $date->setTimestamp($item->timecreated);
  416. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  417. $zip->add_file_from_string($new_file, $item->answer);
  418. $temp_json = [];
  419. $temp_json[] = intval($item->id);
  420. $temp_json[] = $new_file;
  421. $temp_json[] = strlen($new_file);
  422. $temp_json[] = intval($item->timecreated);
  423. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  424. $temp_json[] = doubleval($item->grade);
  425. $temp_json[] = intval($item->userid);
  426. $temp_json[] = intval($exercise->id);
  427. $json_obj->submissions[] = $temp_json;
  428. }
  429. }
  430. }
  431. }
  432. $csv_str = "";
  433. foreach($json_obj->submissions as $sub) {
  434. $csv_str .= $this->csvstr($sub) . "\n";
  435. }
  436. $zip->add_file_from_string('index.csv', $csv_str);
  437. $zip->close();
  438. iassign_utils::download_file($zip_filename);
  439. exit;
  440. }
  441. function csvstr(array $fields) : string {
  442. $f = fopen('php://memory', 'r+');
  443. if (fputcsv($f, $fields) === false) {
  444. return false;
  445. }
  446. rewind($f);
  447. $csv_line = stream_get_contents($f);
  448. return rtrim($csv_line);
  449. }
  450. /// Download submissions from table iassign_allsubmissions
  451. function download_submissions () {
  452. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  453. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  454. exit;
  455. $type = optional_param('type', NULL, PARAM_TEXT);
  456. $item = optional_param('item', NULL, PARAM_TEXT);
  457. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  458. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  459. $sub_list = [];
  460. if ($type == 'individual') {
  461. $sub_list[] = $DB->get_record(
  462. 'iassign_allsubmissions', array('id' => $item));
  463. } elseif ($type == 'student') {
  464. $sub_list = $DB->get_records(
  465. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  466. } elseif ($type == 'exercise') {
  467. $sub_list = $DB->get_records(
  468. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  469. } elseif ($type == 'block') {
  470. $exercises_in_block = $DB->get_records(
  471. 'iassign_statement', array('iassignid' => $iassign_id));
  472. foreach ($exercises_in_block as $exercise) {
  473. $temp = $DB->get_records(
  474. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  475. $sub_list = array_merge($sub_list, $temp);
  476. }
  477. }
  478. $this->download_submissions_help($sub_list);
  479. }
  480. /// Delete submissions in table iassign_allsubmissions
  481. function delete_submissions () {
  482. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  483. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  484. exit;
  485. $type = optional_param('type', NULL, PARAM_TEXT);
  486. $item = optional_param('item', NULL, PARAM_TEXT);
  487. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  488. if ($type == 'individual') {
  489. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  490. } elseif ($type == 'student') {
  491. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  492. } elseif ($type == 'exercise') {
  493. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  494. }
  495. }
  496. function get_individual_submission () {
  497. global $DB, $USER;
  498. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  499. exit;
  500. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  501. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  502. print $submission->answer;
  503. }
  504. /// Open individual submission
  505. function open_individual_submission () {
  506. global $DB, $USER, $CFG;
  507. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  508. exit;
  509. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  510. $id = $this->cm->id;
  511. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  512. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  513. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  514. $all_submissions = $DB->get_records('iassign_allsubmissions',
  515. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  516. $previous = null;
  517. $next = null;
  518. $i = 0;
  519. $found = false;
  520. foreach($all_submissions as $individual) {
  521. if (!$found && $individual->id != $submissionid) {
  522. $previous = $individual;
  523. }
  524. if ($found) {
  525. $next = $individual;
  526. break;
  527. }
  528. if ($individual->id === $submissionid) {
  529. $found = true;
  530. }
  531. $i ++;
  532. }
  533. print '<center style="padding-top: 2rem;">';
  534. if ($previous) {
  535. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  536. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  537. } else {
  538. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  539. }
  540. print ' (' . $i . '/' . count($all_submissions) . ')';
  541. if ($next) {
  542. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  543. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  544. } else {
  545. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  546. }
  547. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  548. print
  549. //array("type" => "editor_new", "notSEND" => "true")
  550. ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  551. print '</center>';
  552. }
  553. /// Manage all submissions in exercises to table iassign_allsubmissions
  554. function all_submissions () {
  555. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  556. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  557. exit;
  558. print $OUTPUT->header();
  559. $id = $this->cm->id;
  560. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  561. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  562. print '
  563. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  564. <div class="modal-dialog modal-dialog-centered" role="document">
  565. <div class="modal-content">
  566. <div class="modal-header">
  567. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  568. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  569. <span aria-hidden="true">&times;</span>
  570. </button>
  571. </div>
  572. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  573. <div class="modal-footer">
  574. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  575. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  576. </div>
  577. </div>
  578. </div>
  579. </div>'; // "
  580. print '
  581. <script>
  582. var sub_type;
  583. var sub_item;
  584. var sub_el;
  585. var sub_exercise;
  586. function delete_submission (type, item, el, exercise = 0) {
  587. sub_type = type;
  588. sub_item = item;
  589. sub_exercise = exercise;
  590. sub_el = el.closest("tr");
  591. if (!sub_el) sub_el = el.closest("a");
  592. $("#modalConfirm").modal();
  593. }
  594. function confirm_delete () {
  595. var url = "'.$enderecoPOST.'&action=delete_submissions";
  596. var xhttp = new XMLHttpRequest();
  597. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  598. xhttp.send();
  599. $("#modalConfirm").modal("hide");
  600. if ($(sub_el).attr("href"))
  601. $($(sub_el).attr("href")).remove();
  602. if (sub_el) sub_el.remove();
  603. }
  604. function download_submission(type, item, exercise = 0, iassign = 0) {
  605. var url = "'.$enderecoPOST.'&action=download_submissions";
  606. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  607. document.location = url;
  608. }
  609. function open_submission(item) {
  610. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  611. var poupup = window.open(url, "popup", "width=900,height=900");
  612. }
  613. </script>' . chr(13); // '
  614. // Get list of exercises in the instance:
  615. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  616. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  617. print '<h2 class="m-b-2">' . get_string('all_submissions_manager', 'iassign') . '';
  618. print '<i onclick="download_submission(\'block\', 0, 0, '.$iassignid.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.5rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> </h2>';
  619. // Get list of enrolled students:
  620. $params_temp = array('shortname' => 'student');
  621. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  622. $context = context_course::instance($this->course->id);
  623. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  624. $students_list = $DB->get_records_sql(
  625. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  626. print '<div>';
  627. foreach ($exercises_list as $exercise) {
  628. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  629. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  630. print '
  631. <a href="#item-'.$exercise->id.'" class="list-group-item list-group-item-action h4" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> '
  632. . $exercise->name
  633. . ' - ' . $iassign_ilm->name
  634. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  635. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  636. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  637. . $exercise->id .')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> '
  638. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  639. . '</a>';
  640. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  641. foreach ($students_list as $student) {
  642. $total = 0;
  643. $student_submissions = [];
  644. foreach ($submissions_list as $submission) {
  645. if ($submission->userid == $student->userid) {
  646. $student_submissions[] = $submission;
  647. $total ++;
  648. }
  649. }
  650. print '<a href="#item-'.$exercise->id.'-'.$student->userid.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'>
  651. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  652. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  653. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  654. . '<i onclick="event.stopPropagation(); download_submission(\'student\', '.$student->userid.', '.$exercise->id.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.3rem; cursor: pointer; margin-left: 1rem; margin-top: .1rem;" aria-hidden="true"></i> '
  655. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  656. . ' </a>';
  657. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  658. print '<table class="table table-striped table-hover"><thead>
  659. <tr>
  660. <th scope="col">#</th>
  661. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  662. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  663. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  664. </tr>
  665. </thead><tbody>'; // "
  666. $i = 1;
  667. foreach ($student_submissions as $individual) {
  668. $date = new DateTime();
  669. $date->setTimestamp($individual->timecreated);
  670. print '<tr>';
  671. print '<td>'.$i++.'</td>';
  672. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  673. print '<td>'.$individual->grade.'</td>';
  674. print '<td>
  675. <i onclick="open_submission('.$individual->id.')" class="fa fa-external-link" style="color:#1177d1; cursor: pointer; font-size: 1.2rem; margin-right: .5rem;" aria-hidden="true"></i>
  676. <i onclick="download_submission(\'individual\', '.$individual->id.')" class="fa fa-download" style="color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-right: .5rem;" aria-hidden="true"></i>
  677. <i class="fa fa-times" onclick="delete_submission(\'individual\', '.$individual->id.', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; " aria-hidden="true"></i></td>';
  678. print " </tr>\n";
  679. }
  680. print '</tbody></table>';
  681. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  682. print '</div>';
  683. }
  684. print '</div>';
  685. }
  686. print '</div>';
  687. print $OUTPUT->footer();
  688. } // function all_submissions()
  689. /// This method runs activities auto evaluation in teacher area
  690. function auto_evaluate () {
  691. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  692. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  693. exit;
  694. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  695. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  696. // Get list of exercises in the instance:
  697. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  698. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  699. // Get list of enrolled students:
  700. $params_temp = array('shortname' => 'student');
  701. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  702. $context = context_course::instance($this->course->id);
  703. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  704. $students_list = $DB->get_records_sql(
  705. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  706. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  707. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  708. print $OUTPUT->header();
  709. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  710. print '<ul style="list-style-type: none; margin: 1em;">';
  711. foreach ($exercises_list as $exercise) {
  712. $matches = [];
  713. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  714. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  715. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  716. if ($matches[0][0]) {
  717. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="'.$matches[0][0].'" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">' . $exercise->name . '</label></li>';
  718. } else {
  719. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="('.$exercise->id.')" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">(' . $exercise->id . ') - ' . $exercise->name . '</label></li>';
  720. }
  721. } else {
  722. if ($matches[0][0]) {
  723. print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>' . $exercise->name . '</li>';
  724. } else {
  725. print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>(' . $exercise->id . ') - ' . $exercise->name . '</li>';
  726. }
  727. }
  728. }
  729. print '</ul>
  730. <center>
  731. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  732. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  733. <div id="evaluate_message" style="color: red"></div>
  734. <div id="evaluate_alerts"></div>
  735. <div>
  736. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  737. <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 1%; height: 100%;" aria-valuenow="0" aria-valuemin="1" aria-valuemax="100">1%</div>
  738. </div>
  739. </center>'; // close "
  740. print ' </div>' + "\n";
  741. print ' <script>';
  742. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  743. print ' var submissions = [';
  744. // Get list of student id have submit for each exercise:
  745. foreach ($exercises_list as $exercise) {
  746. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  747. print '
  748. {
  749. "exerciseid": "' . $exercise->id . '",
  750. "grade": ' . $exercise->grade . ',
  751. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  752. "submited": ['; // "
  753. $params_temp = array('iassign_statementid' => $exercise->id);
  754. $submited = $DB->get_records_sql( // Get userid and his grade
  755. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  756. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  757. foreach ($submited as $ss) {
  758. print($ss->userid . ',');
  759. }
  760. print '],';
  761. print '"allgrades": [';
  762. foreach ($submited as $ss) {
  763. print( $ss->grade . ',');
  764. }
  765. print ']
  766. },'; // close "
  767. } // foreach ($exercises_list as $exercise)
  768. print " ];\n";
  769. print '
  770. var total_submissions = 0;
  771. var selected_exercises;
  772. var count_steps;
  773. var value_by_step;
  774. var stoped = false;
  775. var time_interval = 5000;
  776. var var_interval;
  777. function add_hover_th (id_th, id_li) { //AJAX
  778. $("#" + id_th).hover(function() {
  779. $("#" + id_li).css("background-color", "#d9d8d8");
  780. $(this).css("background-color", "#d9d8d8");
  781. }, function() {
  782. $("#" + id_li).css("background-color", "");
  783. $(this).css("background-color", "");
  784. });
  785. }
  786. function start_evaluation () {
  787. stoped = false;
  788. //AJAX
  789. $("#progress_bar").css("display", "none");
  790. $("#evaluate_message").text("");
  791. $("#evaluate_alerts").text("");
  792. $(".added-col").remove();
  793. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  794. selected_exercises = [];
  795. var c = 0;
  796. for (var i = 0; i < exercises.length; i++) {
  797. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  798. selected_exercises[c++] = exercises[i];
  799. }
  800. }
  801. if (selected_exercises.length == 0) {
  802. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  803. return;
  804. } else {
  805. $("input:checkbox").attr("disabled", true); //AJAX
  806. for (var i = 0; i < selected_exercises.length; i++) {
  807. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  808. //AJAX
  809. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  810. $("#table-results tbody tr").each(function(e) {
  811. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  812. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  813. });
  814. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  815. }
  816. //AJAX
  817. $("#button_start").prop("disabled", true);
  818. $("#button_stop").prop("disabled", false);
  819. $("#progress_bar").css("display", "block");
  820. }
  821. total_submissions = selected_exercises.length * students.length;
  822. count_steps = 0;
  823. value_by_step = 100/total_submissions;
  824. actual_exercise = 0;
  825. actual_student = 0;
  826. actual_submission = 0;
  827. get_original_propositions();
  828. var_interval = setInterval(verifyBreak, time_interval);
  829. } // function start_evaluation()
  830. var actual_exercise;
  831. var actual_student;
  832. var actual_submission;
  833. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  834. function run_individual_evaluation () {
  835. if (stoped) return;
  836. // Verify if student really sent his answer
  837. var found = false;
  838. for (var j = 0; j < submissions.length; j++) {
  839. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  840. for (var k = 0; k < submissions[j].submited.length; k++) {
  841. if (students[actual_student] == submissions[j].submited[k]) {
  842. found = true;
  843. break;
  844. }
  845. }
  846. break;
  847. }
  848. }
  849. if (found == false) {
  850. postResultAutoEval();
  851. } else {
  852. // If it was sent, search it...
  853. var final_url = "";
  854. var student_answer = "' . $CFG->wwwroot . "/mod/iassign/view.php?action=get_student_submission&id=" . $this->cm->id . '" + "&iassign_student=" + students[actual_student] + "&iassign_exercise=" + selected_exercises[actual_exercise];
  855. for (var j = 0; j < submissions.length; j++) {
  856. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  857. final_url = submissions[j].ilm;
  858. break;
  859. }
  860. }
  861. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  862. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  863. window.frames["ifrm"].location=final_url;
  864. }
  865. } // function run_individual_evaluation()
  866. var break_student = -1;
  867. var break_exercise = -1;
  868. function verifyBreak () {
  869. if (actual_student == break_student && actual_exercise == break_exercise) {
  870. postResultAutoEval(-6);
  871. break_student = -1;
  872. break_exercise = -1;
  873. return;
  874. } else {
  875. break_student = actual_student;
  876. break_exercise = actual_exercise;
  877. }
  878. }
  879. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  880. function getStudentAnswerURL () {
  881. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  882. }
  883. // This function is called by the iLM!!!
  884. function getAutoEvalOriginalData () {
  885. return original_propositions[actual_exercise];
  886. }
  887. function updateProgressBar () {
  888. if (stoped) return;
  889. var temp = (count_steps * value_by_step)|0;
  890. count_steps ++;
  891. temp = temp > 100 ? 100 : temp;
  892. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  893. if (temp >= 100) {
  894. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  895. $("#button_start").prop("disabled", false);
  896. $("#button_stop").prop("disabled", true);
  897. $("input:checkbox").attr("disabled", false);
  898. clearInterval(var_interval);
  899. }
  900. }
  901. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  902. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  903. function postResultAutoEval (grade = null) {
  904. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  905. if (grade == null) {
  906. $("#"+id_t).html(\'<i class="fa fa-circle-o text-muted" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('not_post', 'iassign').'"></i>\');
  907. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  908. } else {
  909. // Verify if the re-evaluation grade is the of that one registered:
  910. var actual_value = 0;
  911. var actual_student_grade = 0;
  912. for (var k = 0; k < submissions.length; k++) {
  913. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  914. actual_value = submissions[k].grade;
  915. for (var h = 0; h < submissions[k].submited.length; h++) {
  916. if (submissions[k].submited[h] == students[actual_student]) {
  917. actual_student_grade = submissions[k].allgrades[h];
  918. break;
  919. }
  920. }
  921. break;
  922. }
  923. }
  924. // @FeedbackConvention
  925. if (grade < 0) {
  926. switch (grade) {
  927. case -1:
  928. // Test-cases are empty:
  929. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_empty_cases', 'iassign').'"></i></i>\');
  930. var mm = actual_exercise;
  931. $("#"+id_t).find(".details-button").click(function(e) {
  932. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_empty_cases', 'iassign').'</td></tr></table>\');
  933. });
  934. break;
  935. case -2:
  936. // Test-cases were manually altered by the student (fraud!):
  937. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_diff_cases', 'iassign').'"></i></i>\');
  938. var mm = actual_exercise;
  939. $("#"+id_t).find(".details-button").click(function(e) {
  940. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+"</td></tr><tr><td style=\'width: 30%;\' colspan=\'2\'><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_diff_cases', 'iassign').'</td></tr></table>");
  941. });
  942. //AJAX
  943. $.ajax({
  944. dataType: "html",
  945. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=post_auto_eval_result&id='.$this->cm->id.'&iassign_exercise="+selected_exercises[actual_exercise]+"&student="+students[actual_student]+"&grade=0",
  946. success: function(d) {} });
  947. break;
  948. case -5:
  949. // Execution failed:
  950. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_fail', 'iassign').'"></i></i>\');
  951. var mm = actual_exercise;
  952. //AJAX
  953. $("#"+id_t).find(".details-button").click(function(e) {
  954. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_fail', 'iassign').'</td></tr></table>\');
  955. });
  956. break;
  957. case -6: // iLM not answering was detected in "verifyBreak()"
  958. // The iLM are not answering:
  959. //AJAX
  960. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-clock-o fa-6" aria-hidden="true" style="color: orange; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_title_time', 'iassign').'"></i></i>\');
  961. $("#"+id_t).find(".details-button").click(function(e) {
  962. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  963. });
  964. break;
  965. }
  966. //AJAX
  967. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  968. } else {
  969. console.log((grade), (actual_student_grade));
  970. if ((grade) == (actual_student_grade)) {
  971. $("#"+id_t).html(\'<i class="fa fa-check-circle-o text-success" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_ok', 'iassign').'"></i>\');
  972. } else { // Notas diferem:
  973. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-exclamation-circle text-warning" aria-hidden="true" style="font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_different_grades', 'iassign').'"></i></i>\');
  974. var mm = actual_exercise;
  975. //AJAX
  976. $("#"+id_t).find(".details-button").click(function(e) {
  977. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('auto_evaluate_grade_registered', 'iassign').'</td><td>\'+(actual_student_grade*grade)+\'</td></tr><tr><td style="width: 30%;"><b>'.get_string('auto_evaluate_grade_new', 'iassign').'</b></td><td>\'+(grade * actual_value)+\'</td></tr><tr><td colspan="2">'.get_string('auto_evaluate_msg_grade_update', 'iassign').'</tr></table>\');
  978. });
  979. //AJAX
  980. // Send to the endpoint the post_auto_eval_result to verify:
  981. $.ajax({
  982. dataType: "html",
  983. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=post_auto_eval_result&id=' . $this->cm->id . '&iassign_exercise=" + selected_exercises[actual_exercise] + "&student=" + students[actual_student] + "&grade=" + (grade),
  984. success: function(d) {}
  985. });
  986. }
  987. //AJAX
  988. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  989. }
  990. }
  991. updateProgressBar();
  992. // Does it must continue in the same exercise or stop?
  993. if (actual_student < students.length) {
  994. actual_student ++;
  995. run_individual_evaluation();
  996. } else {
  997. actual_student = 0;
  998. // Does it go to next exercise or is it finished?
  999. if (actual_exercise < selected_exercises.length) {
  1000. actual_exercise++;
  1001. run_individual_evaluation();
  1002. } else {
  1003. //AJAX
  1004. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1005. }
  1006. }
  1007. }
  1008. var original_propositions;
  1009. function get_original_propositions () {
  1010. original_propositions = [];
  1011. var count = 0;
  1012. for (var i = 0; i < exercises.length; i++) {
  1013. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1014. //AJAX
  1015. $.ajax({
  1016. dataType: "html",
  1017. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1018. success: function(d) { // variable "d" has the iLM content
  1019. original_propositions[count] = d; // exercise original content
  1020. count ++;
  1021. if (count == selected_exercises.length) {
  1022. run_individual_evaluation();
  1023. }
  1024. }
  1025. });
  1026. }
  1027. }
  1028. }
  1029. function stop_evaluation () {
  1030. stoped = true;
  1031. //AJAX
  1032. $("#button_start").prop("disabled", false);
  1033. $("#button_stop").prop("disabled", true);
  1034. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1035. $("input:checkbox").attr("disabled", false);
  1036. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1037. clearInterval(var_interval);
  1038. }
  1039. var exercises = [ '; // '
  1040. foreach ($exercises_list as $exercise) {
  1041. print $exercise->id . ',';
  1042. }
  1043. print ' ];';
  1044. print ' var students = [ ';
  1045. foreach ($students_list as $student) {
  1046. print $student->userid . ',';
  1047. }
  1048. print '];';
  1049. print ' var ilms = [';
  1050. foreach ($exercises_list as $exercise) {
  1051. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1052. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1053. }
  1054. print ']';
  1055. print '</script>';
  1056. print '
  1057. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1058. <div class="modal-dialog modal-dialog-centered" role="document">
  1059. <div class="modal-content">
  1060. <div class="modal-header">
  1061. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1062. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1063. <span aria-hidden="true">&times;</span>
  1064. </button>
  1065. </div>
  1066. <div class="modal-body">
  1067. ...
  1068. </div>
  1069. <div class="modal-footer">
  1070. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1071. </div>
  1072. </div>
  1073. </div>
  1074. </div>'; //
  1075. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1076. print '<table id="table-results" class="table table-hover m-t-1">
  1077. <thead>
  1078. <tr id="cols-exercises">
  1079. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1080. </tr>
  1081. </thead>
  1082. <tbody>'; // "
  1083. foreach ($students_list as $student) {
  1084. $user = $DB->get_record('user', array('id' => $student->userid));
  1085. $avatar = new user_picture($user);
  1086. $avatar->courseid = $COURSE->id;
  1087. $avatar->link = true;
  1088. print ' <tr data-student="' . $student->userid . '">
  1089. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1090. </tr>' . "\n"; // "
  1091. }
  1092. print " </tbody>
  1093. </table>\n";
  1094. print $OUTPUT->footer();
  1095. } // function auto_evaluate()
  1096. /// This method moves an iAssign activity
  1097. function move_activity () {
  1098. global $USER, $CFG, $DB, $COURSE;
  1099. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1100. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1101. $update_entry_new_iassign = new stdClass();
  1102. $update_entry_new_iassign->id = $iassign_id;
  1103. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1104. // Update the iassign_statement
  1105. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1106. // Update file context
  1107. $c_i = context_module::instance($this->cm->id);
  1108. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1109. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1110. $path_module = context_course::instance($COURSE->id);
  1111. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1112. if ($context_file) {
  1113. $id_context = $context_file->id;
  1114. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1115. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1116. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1117. foreach ($files as $value) {
  1118. if ($value->get_filename() != ".") {
  1119. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1120. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1121. $updateentry = new stdClass();
  1122. $updateentry->id = $iassign_id;
  1123. $updateentry->filesid = $newfile->get_itemid();
  1124. $DB->update_record("iassign_statement", $updateentry);
  1125. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1126. break;
  1127. }
  1128. }
  1129. }
  1130. $this->return_home_course('moved_activity');
  1131. exit;
  1132. }
  1133. /// This method duplicates an iAssign activity
  1134. function duplicate_activity () {
  1135. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1136. $id = $this->cm->id;
  1137. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1138. $context = context_module::instance($this->cm->id);
  1139. $contextuser = context_user::instance($USER->id);
  1140. // Get the the iAssign acitivity to be duplicated
  1141. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1142. // Remove the current id of activity
  1143. $iassign_statement->id=0;
  1144. // Get the information about current author, and add this information in author_modified field
  1145. $author = $DB->get_record("user", array('id' => $USER->id));
  1146. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1147. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1148. // Store the activity in the table
  1149. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1150. // Duplicate activity file
  1151. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1152. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1153. foreach ($files as $value) {
  1154. if ($value->get_filename() != ".") {
  1155. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1156. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1157. $updateentry = new stdClass();
  1158. $updateentry->id = $id_;
  1159. $updateentry->filesid = $newfile->get_itemid();
  1160. // Update the duplicated iLM iAssign with new file id
  1161. $DB->update_record("iassign_statement", $updateentry);
  1162. }
  1163. }
  1164. }
  1165. // log event --------------------------------------------------------------------------------------
  1166. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1167. $this->return_home_course('duplicated_activity');
  1168. exit;
  1169. }
  1170. // / This method gets the content from comment and register it
  1171. function add_comment () {
  1172. global $USER, $DB;
  1173. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1174. $comment = false;
  1175. if ($submission_comment)
  1176. $comment = $this->write_comment_submission();
  1177. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1178. if (!$id_submission) {
  1179. $iassign_submission =
  1180. $DB->get_record("iassign_submission",
  1181. array(
  1182. "iassign_statementid" => $this->activity->get_activity()->id,
  1183. "userid" => $USER->id
  1184. )
  1185. );
  1186. if ($iassign_submission) {
  1187. $id_submission = $iassign_submission->id;
  1188. }
  1189. }
  1190. echo $this->search_comment_submission($id_submission);
  1191. }
  1192. /// This method gets the content from the iLM and register it
  1193. // It could be the "exercise template" (teacher) or an answer (student)
  1194. function get_answer () {
  1195. global $USER, $CFG, $DB, $OUTPUT;
  1196. $id = $this->cm->id;
  1197. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1198. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1199. if ($submission_ajax == 1) ob_start();
  1200. $comment = false;
  1201. if ($submission_comment)
  1202. $comment = $this->write_comment_submission();
  1203. // receives data of iLM using the current activity
  1204. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1205. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1206. // receives data of submission of current activity
  1207. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1208. // receives post and get
  1209. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1210. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1211. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1212. $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)
  1213. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1214. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1215. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1216. $msg = '';
  1217. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1218. $newentry = new stdClass();
  1219. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1220. $newentry->userid = $this->userid_iassign;
  1221. $newentry->timecreated = time();
  1222. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1223. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1224. $DB->insert_record("iassign_allsubmissions", $newentry);
  1225. }
  1226. // Feedback
  1227. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1228. $str_action = "view"; // repeat
  1229. if (strtolower($iassign_ilm->name) == "igeom") {
  1230. }
  1231. $title = get_string('evaluate_iassign', 'iassign');
  1232. print $OUTPUT->header();
  1233. print $OUTPUT->box_start();
  1234. // Action = { view ; repeat ; viewsubmission }
  1235. // * '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")
  1236. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1237. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1238. $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;
  1239. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1240. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1241. print '<table width=100% >';
  1242. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1243. //TODO alterar aqui???
  1244. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1245. // empty_answer_post = No solution was posted.
  1246. if ($comment)
  1247. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1248. else
  1249. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1250. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1251. } else {
  1252. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1253. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1254. // Correct answer!!
  1255. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1256. $this->write_solution = 1; //
  1257. $status = 3;
  1258. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1259. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1260. // log record
  1261. $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;
  1262. // Trigger module viewed event.
  1263. $event = \mod_iassign\event\submission_created::create(array(
  1264. 'objectid' => $this->iassign->id,
  1265. 'context' => $this->context,
  1266. 'other' => $info
  1267. ));
  1268. $event->add_record_snapshot('course', $this->course);
  1269. $event->trigger();
  1270. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1271. // Wrong answer...: get_answer_incorrect
  1272. $status = 2;
  1273. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1274. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1275. // log record
  1276. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1277. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1278. // Trigger module viewed event.
  1279. $event = \mod_iassign\event\submission_created::create(array(
  1280. 'objectid' => $this->iassign->id,
  1281. 'context' => $this->context,
  1282. 'other' => $info
  1283. ));
  1284. $event->add_record_snapshot('course', $this->course);
  1285. $event->trigger();
  1286. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1287. // Presents to the learner the result of the automatic evaluate?
  1288. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1289. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1290. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1291. print '<tr>';
  1292. // log record
  1293. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1294. // Trigger module viewed event.
  1295. $event = \mod_iassign\event\submission_created::create(array(
  1296. 'objectid' => $this->iassign->id,
  1297. 'context' => $this->context,
  1298. 'other' => $info
  1299. ));
  1300. $event->add_record_snapshot('course', $this->course);
  1301. $event->trigger();
  1302. } else { // yes!!!
  1303. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1304. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1305. print '<tr>';
  1306. print $msg;
  1307. }
  1308. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1309. $status = 1;
  1310. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1311. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1312. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1313. print '<tr>';
  1314. // log record
  1315. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1316. $event = \mod_iassign\event\submission_created::create(array(
  1317. 'objectid' => $this->iassign->id,
  1318. 'context' => $this->context,
  1319. 'other' => $info
  1320. ));
  1321. $event->add_record_snapshot('course', $this->course);
  1322. $event->trigger();
  1323. } // if ($iassign_ilm->evaluate == 1)
  1324. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1325. print '</tr></table>';
  1326. print $OUTPUT->box_end();
  1327. // add or update evaluate
  1328. if ($this->write_solution == 1) {
  1329. $timenow = time();
  1330. // new record
  1331. if (!$iassign_submission) {
  1332. $newentry = new stdClass();
  1333. $newentry->userid = $this->userid_iassign;
  1334. // $newentry->userid = $USER->id;
  1335. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1336. $newentry->timecreated = $timenow;
  1337. $newentry->timemodified = $timenow;
  1338. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1339. $newentry->grade = round($grade_student, 2);
  1340. $newentry->status = $status;
  1341. $newentry->experiment = 1;
  1342. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1343. print_error('error_insert', 'iassign');
  1344. } else {
  1345. // Trigger module viewed event.
  1346. $event = \mod_iassign\event\submission_created::create(array(
  1347. 'objectid' => $this->iassign->id,
  1348. 'context' => $this->context
  1349. ));
  1350. $event->add_record_snapshot('course', $this->course);
  1351. $event->trigger();
  1352. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1353. }
  1354. } elseif ($iassign_submission->status != 3) {
  1355. $newentry = new stdClass();
  1356. $newentry->id = $iassign_submission->id;
  1357. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1358. $newentry->userid = $iassign_submission->userid;
  1359. $newentry->timecreated = $iassign_submission->timecreated;
  1360. $newentry->timemodified = $timenow;
  1361. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1362. $newentry->grade = round($grade_student, 2);
  1363. $newentry->status = $status;
  1364. $newentry->experiment = $iassign_submission->experiment + 1;
  1365. if (!$DB->update_record("iassign_submission", $newentry)) {
  1366. print_error('error_update', 'iassign');
  1367. //D depurar...
  1368. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1369. //D $fp = fopen("teste1.txt","w");
  1370. //D fwrite($fp,$stringAux);
  1371. } else {
  1372. // Trigger module viewed event.
  1373. $event = \mod_iassign\event\submission_updated::create(array(
  1374. 'objectid' => $this->iassign->id,
  1375. 'context' => $this->context
  1376. ));
  1377. $event->add_record_snapshot('course', $this->course);
  1378. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1379. }
  1380. } else {
  1381. if ($return_get_answer == 1) {
  1382. $newentry = new stdClass();
  1383. $newentry->id = $iassign_submission->id;
  1384. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1385. $newentry->userid = $iassign_submission->userid;
  1386. $newentry->timecreated = $iassign_submission->timecreated;
  1387. $newentry->timemodified = $timenow;
  1388. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1389. $newentry->grade = round($grade_student, 2);
  1390. $newentry->status = $status;
  1391. $newentry->experiment = $iassign_submission->experiment + 1;
  1392. if (!$DB->update_record("iassign_submission", $newentry))
  1393. print_error('error_update', 'iassign');
  1394. else {
  1395. $event = \mod_iassign\event\submission_updated::create(array(
  1396. 'objectid' => $this->iassign->id,
  1397. 'context' => $this->context
  1398. ));
  1399. $event->add_record_snapshot('course', $this->course);
  1400. $event->trigger();
  1401. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1402. print $OUTPUT->box_start();
  1403. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1404. print $OUTPUT->box_end();
  1405. }
  1406. } elseif ($return_get_answer == 2) {
  1407. print $OUTPUT->box_start();
  1408. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1409. print $OUTPUT->box_end();
  1410. } else {
  1411. print $OUTPUT->box_start();
  1412. print "
  1413. <script type='text/javascript'>
  1414. //<![CDATA[
  1415. function overwrite () {
  1416. document.formEnvio.return_get_answer.value = 1;
  1417. document.formEnvio.submit();
  1418. }
  1419. function nooverwrite () {
  1420. document.formEnvio.return_get_answer.value = 2;
  1421. document.formEnvio.submit();
  1422. }
  1423. //]]>
  1424. </script>";
  1425. $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;
  1426. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1427. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1428. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1429. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1430. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1431. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1432. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1433. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1434. <input type='hidden' name='return_get_answer'/> ";
  1435. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1436. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1437. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1438. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1439. print " </form>";
  1440. print $OUTPUT->box_end();
  1441. }
  1442. }
  1443. } // if ($this->write_solution == 1)
  1444. print $OUTPUT->footer();
  1445. if ($submission_ajax == 1) {
  1446. ob_end_clean();
  1447. print 'OK';
  1448. }
  1449. die();
  1450. } // function get_answer()
  1451. /// Export in file the answer of student.
  1452. function export_file_answer () {
  1453. global $DB;
  1454. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1455. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1456. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1457. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1458. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1459. $extensions = explode(",", $iassign_ilm->extension);
  1460. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1461. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1462. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1463. header("Pragma: public");
  1464. header("Expires: 0");
  1465. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1466. header("Cache-Control: private", false);
  1467. header("Content-Type: document/unknown");
  1468. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1469. set_time_limit(0);
  1470. print($iassign_submission->answer);
  1471. exit;
  1472. } // function export_file_answer()
  1473. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1474. // @calledby $this->export_package_answer()
  1475. //TODO Precisa terminar! //TODO_HTML
  1476. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1477. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1478. <head>
  1479. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1480. $str_html .= " </head>
  1481. <body>\n";
  1482. $tam = sizeof($array_iassign_name);
  1483. for ($ii=0; $ii<$tam; $ii++) {
  1484. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1485. }
  1486. $str_html .= "
  1487. </body>\n</html>";
  1488. return $str_html;
  1489. }
  1490. /// Export an package (zip) with all answer of students
  1491. // @calledby $this->action()
  1492. function export_package_answer () {
  1493. global $DB, $CFG, $OUTPUT;
  1494. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1495. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1496. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1497. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1498. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1499. $userid = optional_param('userid', NULL, PARAM_INT);
  1500. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1501. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1502. //TODO_HTML echo "username=$username<br/>"; exit;
  1503. $current_date = date('Y_m_d_H');
  1504. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1505. // If temporary directory under Moodle data does not exists => create it
  1506. if (!is_dir($diretorio)) {
  1507. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1508. // created directory with permissions to be seen by everyone
  1509. }
  1510. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1511. if (!is_writable($diretorio)) { // send a highlighted message!
  1512. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1513. exit; // just in case
  1514. }
  1515. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1516. $zip = new zip_archive(); // create ZIP
  1517. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1518. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1519. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1520. $vet_student_filename = array();
  1521. $vet_student_content = array();
  1522. foreach ($iassign_statements as $iassign_statement) {
  1523. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1524. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1525. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1526. $extensions = explode(",", $iassign_ilm->extension);
  1527. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1528. if ($iassign_submission) {
  1529. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1530. $student_content = $iassign_submission->answer;
  1531. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1532. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1533. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1534. if ($resp) {
  1535. $vet_student_filename[] = $student_filename;
  1536. $vet_student_content[] = $student_content;
  1537. }
  1538. else { // send a highlighted message!
  1539. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1540. exit; // just in case
  1541. }
  1542. }
  1543. }
  1544. $zip->close(); // close the ZIP file
  1545. if (count($vet_student_filename)>0) {
  1546. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1547. $result_tf = $vet_result[0];
  1548. $filenameZip = $vet_result[1]->filename;
  1549. }
  1550. iassign_utils::download_file($zip_filename); // download the ZIP file
  1551. exit;
  1552. } // function export_package_answer()
  1553. /// Editing status of interactive activities
  1554. function edit_status () {
  1555. global $USER, $DB, $OUTPUT;
  1556. $newentry = new stdClass();
  1557. $newentry->id = $this->iassign_submission_current;
  1558. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1559. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1560. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1561. $newentry->status = $iassign_submission->status;
  1562. $newentry->teacher = $USER->id;
  1563. if (!$DB->update_record('iassign_submission', $newentry))
  1564. print_error('error_update', 'iassign');
  1565. else {
  1566. // Trigger module viewed event.
  1567. $event = \mod_iassign\event\submission_updated::create(array(
  1568. 'objectid' => $this->iassign->id,
  1569. 'context' => $this->context
  1570. ));
  1571. $event->add_record_snapshot('course', $this->course);
  1572. $event->trigger();
  1573. $this->action = 'viewsubmission';
  1574. $this->view_iassign_current();
  1575. } // if (!$DB->update_record('iassign_submission', $newentry))
  1576. } // function edit_status()
  1577. /// Editing grade of interactive activities
  1578. function edit_grade () {
  1579. global $USER, $DB, $OUTPUT;
  1580. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1581. if ($newgrade && $newgrade >= 0) {
  1582. $newentry = new stdClass();
  1583. $newentry->id = $this->iassign_submission_current;
  1584. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1585. $newentry->teacher = $USER->id;
  1586. if (!$DB->update_record('iassign_submission', $newentry))
  1587. print_error('error_update', 'iassign');
  1588. else {
  1589. // Trigger module viewed event.
  1590. $event = \mod_iassign\event\submission_updated::create(array(
  1591. 'objectid' => $this->iassign->id,
  1592. 'context' => $this->context
  1593. ));
  1594. $event->add_record_snapshot('course', $this->course);
  1595. $event->trigger();
  1596. }
  1597. } // if ($newgrade >= 0)
  1598. $this->action = 'viewsubmission';
  1599. $this->view_iassign_current();
  1600. }
  1601. /// Add or Edit interactive activities
  1602. // Get here when editing form and and submitted form data
  1603. // @calledby $this->action()
  1604. function add_edit_iassign () {
  1605. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1606. require_once('iassign_form.php');
  1607. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1608. $iassignid = $this->iassign->id;
  1609. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1610. $param->action = $this->action; // hidden
  1611. $param->id = $id; // hidden
  1612. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1613. $COURSE->cm = $id;
  1614. $COURSE->iassignid = $iassignid;
  1615. $COURSE->iassign_file_id = NULL;
  1616. $context = context_module::instance($this->cm->id);
  1617. $contextuser = context_user::instance($USER->id);
  1618. $component = 'mod_iassign';
  1619. $filearea = 'exercise';
  1620. if (!empty($this->iassign_current))
  1621. $COURSE->iassign_id = $this->iassign_current;
  1622. else
  1623. $COURSE->iassign_id = 0;
  1624. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1625. if ($this->action == 'add') {
  1626. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1627. $params_temp = array('iassignid' => $iassignid);
  1628. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1629. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1630. $total_of_activities = count($iassign_statement);
  1631. $param->iassignid = $iassignid;
  1632. $param->name = "";
  1633. $param->oldname = "";
  1634. $param->type_iassign = 3;
  1635. $param->proposition = "";
  1636. $author = $DB->get_record("user", array("id" => $USER->id));
  1637. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1638. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1639. $param->author = $param->author_name;
  1640. $param->author_modified = $param->author_modified_name;
  1641. $COURSE->iassign_list = array();
  1642. $param->iassign_list = array();
  1643. if ($iassign_statement) {
  1644. foreach ($iassign_statement as $iassign) {
  1645. $iassignid = $iassign->id;
  1646. $param->iassign_list[$iassignid] = 0;
  1647. $COURSE->iassign_list[$iassignid] = new stdClass();
  1648. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1649. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1650. $COURSE->iassign_list[$iassignid]->enable = 1;
  1651. } // foreach ($iassign_statement as $iassign)
  1652. }
  1653. $param->iassign_ilmid = 0;
  1654. $param->file = 0;
  1655. $param->fileold = 0;
  1656. $param->filename = "";
  1657. $param->grade = $iassign_data->grade;
  1658. $param->timemodified = time();
  1659. $param->timecreated = time();
  1660. $param->timeavailable = $iassign_data->timeavailable;
  1661. $param->timedue = $iassign_data->timedue;
  1662. $param->preventlate = $iassign_data->preventlate;
  1663. $param->test = $iassign_data->test;
  1664. $param->special_param1 = 0;
  1665. $param->visible = 1;
  1666. $param->max_experiment = $iassign_data->max_experiment;
  1667. $param->dependency = 0;
  1668. $param->automatic_evaluate = 1;
  1669. $param->show_answer = 1;
  1670. } // if ($this->action == 'add')
  1671. elseif ($this->action == 'edit') {
  1672. $COURSE->iassign_list = array();
  1673. $this_activity = $this->activity->get_activity();
  1674. if ($this_activity != null) { // first enter here: fill form data
  1675. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1676. $param->iassign_id = $iassign_statement_current->id; // oculto
  1677. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1678. $param->name = $iassign_statement_current->name;
  1679. $param->oldname = $iassign_statement_current->name;
  1680. $param->type_iassign = $iassign_statement_current->type_iassign;
  1681. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1682. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1683. $param->author_name = $iassign_statement_current->author_name; // oculto
  1684. $param->author = $iassign_statement_current->author_name;
  1685. $author = $DB->get_record("user", array('id' => $USER->id));
  1686. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1687. $param->author_modified = $param->author_modified_name;
  1688. $dependency = explode(';', $iassign_statement_current->dependency);
  1689. $param->iassign_list = array();
  1690. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1691. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1692. $array_dependency = array();
  1693. $subdependency = "";
  1694. $sub_subdependency = "";
  1695. // Dependents on this exercise
  1696. if ($iassign_statement_dependency) {
  1697. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1698. // to whom this exercise depends
  1699. foreach ($inter as $tmp)
  1700. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1701. $list_dependency = $subdependency . $sub_subdependency;
  1702. $array_dependency = explode(";", $list_dependency);
  1703. }
  1704. // Get all activities in the same iAssigment block:
  1705. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  1706. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1707. $total_of_activities = count($all_others_iassign_statement) + 1;
  1708. $inter = array();
  1709. if ($all_others_iassign_statement) {
  1710. foreach ($all_others_iassign_statement as $iassign)
  1711. if (in_array($iassign->id, $dependency))
  1712. $inter[] = $iassign->id;
  1713. }
  1714. if ($all_others_iassign_statement) {
  1715. foreach ($all_others_iassign_statement as $iassign) {
  1716. $iassignid = $iassign->id;
  1717. $COURSE->iassign_list[$iassignid] = new stdClass();
  1718. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1719. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1720. if (in_array($iassignid, $dependency))
  1721. $param->iassign_list[$iassignid] = 1;
  1722. else
  1723. $param->iassign_list[$iassignid] = 0;
  1724. if (in_array($iassignid, $array_dependency))
  1725. $COURSE->iassign_list[$iassignid]->enable = 0;
  1726. else
  1727. $COURSE->iassign_list[$iassignid]->enable = 1;
  1728. } // foreach ($all_others_iassign_statement as $iassign)
  1729. } // if ($all_others_iassign_statement)
  1730. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  1731. $param->fileold = 0;
  1732. $param->filesid = 0;
  1733. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1734. $param->filename = '';
  1735. $param->grade = $iassign_statement_current->grade;
  1736. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  1737. $param->timeavailable = $iassign_statement_current->timeavailable;
  1738. $param->timedue = $iassign_statement_current->timedue;
  1739. $param->preventlate = $iassign_statement_current->preventlate;
  1740. $param->test = $iassign_statement_current->test;
  1741. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  1742. $param->position = $iassign_statement_current->position; // hidden
  1743. $param->visible = $iassign_statement_current->visible;
  1744. $param->max_experiment = $iassign_statement_current->max_experiment;
  1745. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1746. $param->show_answer = $iassign_statement_current->show_answer;
  1747. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1748. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  1749. if ($files) {
  1750. foreach ($files as $file) {
  1751. if ($file->get_filename() != '.') {
  1752. $param->filename = $file->get_filename();
  1753. $param->file = $file->get_id();
  1754. $param->fileold = $file->get_id();
  1755. $COURSE->iassign_file_id = $file->get_id();
  1756. }
  1757. }
  1758. }
  1759. //TODO //MOOC2014 -- inicio
  1760. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1761. //D if ($iassign_ilm_configs) {
  1762. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1763. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1764. //D } //MOOC2014 -- fim
  1765. } // if ($this_activity != null)
  1766. } // elseif ($this->action == 'edit')
  1767. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1768. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1769. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1770. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1771. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1772. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1773. $param->position = $total_of_activities;
  1774. // Create form and associate its data
  1775. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  1776. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  1777. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  1778. if (isset($param->iassign_ilmid)) {
  1779. // array is additional atributes to 'form'
  1780. // 'special_param1 == 1' => script of iGeom : <select class="custom-select" name="special_param1" id="id_special_param1"> "Assignment with script(algorithm)? (Applicable only to iGeom iLM)"
  1781. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  1782. }
  1783. else {
  1784. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  1785. }
  1786. $mform->set_data($param); // define data in the form
  1787. if ($mform->is_cancelled()) {
  1788. $this->return_home_course('iassign_cancel');
  1789. exit;
  1790. }
  1791. else { // else if ($mform->is_cancelled())
  1792. $result = $mform->get_data();
  1793. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1794. if ($result) {
  1795. $result->context = $context;
  1796. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1797. $result->grade = 0;
  1798. if ($result->type_iassign == 1) {
  1799. $result->automatic_evaluate = 0;
  1800. $result->show_answer = 0;
  1801. }
  1802. elseif ($result->automatic_evaluate == 0)
  1803. $result->show_answer = 0;
  1804. // $_POST['iassign_list']
  1805. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1806. if ($result->iassign_list) {
  1807. foreach ($result->iassign_list as $key => $value)
  1808. $result->dependency .= $key . ';';
  1809. }
  1810. else
  1811. $result->dependency = 0;
  1812. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1813. //TODO Then get it directly from the form data $_POST!
  1814. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1815. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1816. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1817. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1818. if ($this->action == 'add') {
  1819. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1820. if ($iassign_statement_name) {
  1821. $this->return_home_course('error_iassign_name');
  1822. die();
  1823. }
  1824. // Really insert the new iActivity in table '*_iassign_statement'
  1825. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1826. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1827. // Trigger module viewed event.
  1828. $event = \mod_iassign\event\iassign_created::create(array(
  1829. 'objectid' => $iassignid,
  1830. 'context' => $context
  1831. ));
  1832. $event->add_record_snapshot('course', $this->course);
  1833. $event->trigger();
  1834. $this->return_home_course('iassign_add');
  1835. } // if ($this->action == 'add')
  1836. elseif ($this->action == 'edit') {
  1837. $iassignid = $this->activity->update_iassign($result);
  1838. $this->activity->update_calendar($iassignid, $result->oldname);
  1839. // Trigger module viewed event.
  1840. $event = \mod_iassign\event\iassign_updated::create(array(
  1841. 'objectid' => $iassignid,
  1842. 'context' => $context
  1843. ));
  1844. $event->add_record_snapshot('course', $this->course);
  1845. $event->trigger();
  1846. $this->return_home_course('iassign_update');
  1847. } // elseif ($this->action == 'edit')
  1848. die();
  1849. } // if ($result)
  1850. } // else if ($mform->is_cancelled())
  1851. print $OUTPUT->header();
  1852. $mform->display();
  1853. print $OUTPUT->footer();
  1854. die();
  1855. } // function add_edit_iassign()
  1856. /// Search for dependencies
  1857. function search_dependency ($search_iassing_id, $iassign_statement) {
  1858. global $DB, $OUTPUT;
  1859. $dependency = "";
  1860. if ($iassign_statement)
  1861. foreach ($iassign_statement as $iassign) {
  1862. $inter_dependency = explode(';', $iassign->dependency);
  1863. if (in_array($search_iassing_id, $inter_dependency)) {
  1864. $dependency .= $iassign->id . ";";
  1865. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1866. } // if (in_array($search_iassing_id, $inter_dependency))
  1867. } // foreach ($iassign_statement as $iassign)
  1868. return $dependency;
  1869. }
  1870. /// Search for "sub"dependency
  1871. function search_sub_dependency ($search_iassing_id) {
  1872. global $DB, $OUTPUT;
  1873. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1874. $dependency = "";
  1875. if ($iassign_statement) {
  1876. $inter_dependency = explode(';', $iassign_statement->dependency);
  1877. foreach ($inter_dependency as $tmp) {
  1878. if ($tmp != 0)
  1879. $dependency .= $tmp . ";";
  1880. $dependency .= $this->search_sub_dependency($tmp);
  1881. } // foreach ($inter_dependency as $tmp)
  1882. } // if ($iassign_statement)
  1883. return $dependency;
  1884. }
  1885. // Warning message
  1886. static function warning_message_iassign ($strcode) {
  1887. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1888. }
  1889. /// Update grade of iAssign
  1890. // Called always any iAssign activity is created
  1891. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1892. static function update_grade_iassign ($iassignid) {
  1893. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1894. require_once($CFG->libdir . '/gradelib.php');
  1895. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1896. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1897. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1898. // Each iAssign item is associated with one item on the "gradebook"
  1899. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1900. //$sum_grade = 0;
  1901. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1902. //foreach($grade as $tmp) {
  1903. // $sum_grade += $tmp->grade;
  1904. // }
  1905. //1 Solution 1
  1906. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1907. //1 $sum_grade = 0; //1
  1908. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1909. //2 Solution 2
  1910. $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
  1911. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1912. if (key($array_sum_grade))
  1913. $sum_grade = key($array_sum_grade); //2
  1914. else
  1915. $sum_grade = 0; //2
  1916. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1917. $grades = NULL;
  1918. $params_temp = array('itemname' => $grade_iassign->name);
  1919. $params_temp['iteminstance'] = $iassignid;
  1920. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  1921. //2016 if ($sum_grade != 0) {
  1922. $params_temp['grademax'] = $sum_grade;
  1923. $params_temp['rawgrademax'] = $sum_grade;
  1924. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  1925. $params_temp['grademin'] = 0;
  1926. // @calls /lib/gradelib.php: call to grade_item->insert()
  1927. //TODO: is there any error here in Moodle version 3.0?
  1928. //TODO: Incorrect property 'grademax' found when inserting grade object
  1929. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1930. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  1931. }
  1932. /// Update grade of student
  1933. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1934. global $CFG, $DB, $OUTPUT;
  1935. require_once($CFG->libdir . '/gradelib.php');
  1936. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1937. // Review all the student submission for this iAssign activity
  1938. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1939. $total_grade = 0;
  1940. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1941. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1942. if ($iassign_submission)
  1943. $total_grade += $iassign_submission->grade;
  1944. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1945. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1946. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1947. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1948. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1949. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1950. $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
  1951. if (key($array_sum_grade))
  1952. $sum_grade = key($array_sum_grade); //2
  1953. else
  1954. $sum_grade = 0; //2
  1955. $grades['userid'] = $userid;
  1956. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1957. $params_temp = array('itemname' => $grade_iassign->name);
  1958. $params_temp['iteminstance'] = $iassignid;
  1959. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  1960. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1961. $params_temp['grademax'] = $sum_grade;
  1962. $params_temp['rawgrademax'] = $sum_grade;
  1963. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  1964. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  1965. }
  1966. /// Display caption of icons
  1967. function view_legend_icons () {
  1968. global $USER, $CFG, $DB, $OUTPUT;
  1969. $id = $this->cm->id;
  1970. if ($this->action == 'print')
  1971. print '<table border=1 width=100%><tr>';
  1972. else
  1973. print '<table width=100%><tr>';
  1974. print '<td >';
  1975. if ($this->action != 'print')
  1976. print $OUTPUT->help_icon('legend', 'iassign');
  1977. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1978. // $imagetext = '');
  1979. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1980. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1981. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1982. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1983. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1984. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1985. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1986. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1987. print '</td>' . "\n";
  1988. if ($this->action != 'print') {
  1989. $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>";
  1990. $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>";
  1991. $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>";
  1992. $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>";
  1993. $link_all_submissions_manager = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=all_submissions&iassignid=" . $this->iassign->id . "'><i class='fa fa-files-o' aria-hidden='true' style='color: red'></i>&nbsp;" . get_string('all_submissions_manager', 'iassign') . "</a>";
  1994. print '<td width=10% align="right">' . $link_stats . '</td>' . "\n";
  1995. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  1996. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1997. print '<td width=16% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  1998. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1999. } // if ($this->action != 'print')
  2000. print '</tr></table>' . "\n";
  2001. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2002. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  2003. $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>";
  2004. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  2005. print '</tr></table>' . "\n";
  2006. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2007. else
  2008. print '</td></tr></table>' . "\n";
  2009. } // function view_legend_icons()
  2010. /// Display activity current
  2011. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2012. function view_iassign_current () {
  2013. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2014. $id = $this->cm->id;
  2015. $iassignid = $this->iassign->id;
  2016. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2017. $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
  2018. // 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 ...
  2019. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2020. if (!$iassign_statement_activity_item) {
  2021. print $OUTPUT->header();
  2022. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2023. print $OUTPUT->footer();
  2024. exit;
  2025. }
  2026. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2027. $ilm_name = '';
  2028. if ($ilm->ilm)
  2029. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2030. // 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
  2031. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2032. // log record
  2033. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2034. //Trigger module viewed event.
  2035. $event = \mod_iassign\event\submission_viewed::create(array(
  2036. 'objectid' => $iassign->id,
  2037. 'context' => $this->context,
  2038. 'other' => $info
  2039. ));
  2040. $event->add_record_snapshot('course', $this->course);
  2041. $event->trigger();
  2042. // Search of iLM data used in the current activity
  2043. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2044. // Add actual activity to navbar:
  2045. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2046. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2047. print $OUTPUT->header();
  2048. if ($this->action == 'viewsubmission') {
  2049. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2050. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2051. else
  2052. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2053. } else {
  2054. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2055. }
  2056. if ($iassign_submission)
  2057. $this->update_comment($iassign_submission->id);
  2058. $file = $iassign_statement_activity_item->filesid;
  2059. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2060. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2061. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2062. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2063. $this->bottonPost = 0; // hide submit button
  2064. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2065. $this->view_iassign = false; // disable visualization of activity
  2066. $repeat = "";
  2067. $last_iassign = "";
  2068. $student_answer = "";
  2069. $comment = "";
  2070. // *** Teacher access (view learner's submission)
  2071. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2072. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2073. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2074. // ---> access teacher for test
  2075. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2076. $this->bottonPost = 1;
  2077. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2078. $this->activity->view_dates();
  2079. $USER->iassignEdit = $this->bottonPost;
  2080. $this->activity->show_info_iassign();
  2081. if ($iassign_submission) {
  2082. //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;
  2083. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2084. } else {
  2085. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2086. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2087. }
  2088. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2089. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2090. // Prepare tags to present the iLM
  2091. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2092. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2093. // *** (end) Teacher access (view the activity)
  2094. // *** Teacher access (view learner's submission to the activity)
  2095. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2096. // It is teacher or 'nonediting teacher' that can evaluate
  2097. // ----> area teacher evaluate
  2098. $row = optional_param('row', 0, PARAM_INT);
  2099. $column = optional_param('column', 0, PARAM_INT);
  2100. $link_next = iassign_icons::insert('right_disable');
  2101. $link_previous = iassign_icons::insert('left_disable');
  2102. $link_up = iassign_icons::insert('up_disable');
  2103. $link_down = iassign_icons::insert('down_disable');
  2104. // next_activity
  2105. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2106. $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);
  2107. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2108. }
  2109. // previous_activity
  2110. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2111. $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);
  2112. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2113. }
  2114. // previous_student
  2115. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2116. $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);
  2117. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2118. }
  2119. // next_student
  2120. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2121. $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);
  2122. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2123. }
  2124. if ($iassign_submission) {
  2125. $student_answer = $iassign_submission->answer;
  2126. }
  2127. $last_iassign = get_string('last_iassign', 'iassign');
  2128. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2129. // Messages related to due date (and user role)
  2130. $this->activity->view_dates();
  2131. print $OUTPUT->box_start();
  2132. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2133. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2134. print $OUTPUT->user_picture($user_data);
  2135. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2136. print '</td>' . "\n";
  2137. print '<td width=20% align=right>' . "\n";
  2138. print '<table width=50 cellpadding="0">';
  2139. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2140. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2141. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2142. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2143. print '</table>' . "\n";
  2144. print '</td></tr></table>' . "\n";
  2145. print $OUTPUT->box_end();
  2146. print $OUTPUT->box_start();
  2147. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2148. print '<td width=60% valign="top">' . "\n";
  2149. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2150. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2151. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2152. $resp = get_string('yes');
  2153. else
  2154. $resp = get_string('no');
  2155. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2156. if ($iassign_statement_activity_item->show_answer == 1)
  2157. $resp = get_string('yes');
  2158. else
  2159. $resp = get_string('no');
  2160. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2161. print '</td>';
  2162. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2163. print '<td width=40% valign="top" align="left">';
  2164. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2165. // check status of solution sent by the student
  2166. if ($iassign_submission) {
  2167. switch ($iassign_submission->status) {
  2168. case 3 :
  2169. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2170. break;
  2171. case 2 :
  2172. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2173. break;
  2174. case 1 :
  2175. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2176. break;
  2177. default :
  2178. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2179. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2180. } // switch ($iassign_submission->status)
  2181. }
  2182. else { // if ($iassign_submission)
  2183. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2184. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2185. }
  2186. // update_status
  2187. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2188. $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);
  2189. print " <script type='text/javascript'>
  2190. //<![CDATA[
  2191. function overwriteStatus (newstatus) {
  2192. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2193. document.formEditStatus.return_status.value=newstatus;
  2194. document.formEditStatus.submit();
  2195. }
  2196. else
  2197. document.formEditStatus.return_status.value=-1;
  2198. }
  2199. //]]>
  2200. </script>";
  2201. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2202. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2203. 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";
  2204. print " <input type='hidden' name='return_status'>\n";
  2205. print "</form>\n";
  2206. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2207. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2208. $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);
  2209. print "
  2210. <script type='text/javascript'>
  2211. //<![CDATA[
  2212. function overwriteGrade (newgrade,maxgrade) {
  2213. if (newgrade<0 || newgrade>maxgrade) {
  2214. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2215. document.formEditGrade.return_grade.value=-1;
  2216. document.formEditGrade.submit();
  2217. }
  2218. else {
  2219. document.formEditGrade.return_grade.value=newgrade;
  2220. document.formEditGrade.submit();
  2221. }
  2222. }
  2223. //]]>
  2224. </script>";
  2225. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2226. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2227. print " <input type='text' name='grade' size='6'>";
  2228. print " <input type='hidden' name='return_grade'> ";
  2229. 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";
  2230. print "</form>";
  2231. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2232. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2233. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2234. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2235. if ($teacher)
  2236. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2237. } // if ($iassign_submission->experiment > 0)
  2238. print '</td>';
  2239. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2240. print '</tr></table>';
  2241. print $OUTPUT->box_end();
  2242. $USER->iassignEdit = $this->bottonPost;
  2243. if ($iassign_submission && $allow_resubmission) {
  2244. // Put the iLM to
  2245. print $OUTPUT->box_start();
  2246. print '<p><strong>' . $last_iassign . '</strong></p>';
  2247. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2248. $enderecoPOST = "";
  2249. // Prepare tags to present the iLM
  2250. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2251. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2252. print $OUTPUT->box_end();
  2253. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2254. // ATTENTION: exception used by iGeom (exercise with "script")
  2255. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2256. if (substr($ilm_name, 0, 5)=="igeom") {
  2257. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2258. $loadTeacherActivity = true;
  2259. }
  2260. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2261. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2262. // Prepare tags to present the iLM
  2263. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2264. }
  2265. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2266. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2267. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2268. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2269. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2270. // *** (end) Teacher access (view learner's submission to the activity)
  2271. // *** Student access (view the activity)
  2272. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2273. // It could be the learner (he could send or resend the activity)
  2274. // ---> access student
  2275. $time_now = time();
  2276. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2277. // activity of type example - not submit button for submission
  2278. $this->view_iassign = true;
  2279. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2280. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2281. // activity of type test - iLM automatic evaluator - submit button for submission
  2282. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2283. $this->bottonPost = 1;
  2284. $this->view_iassign = true;
  2285. } else
  2286. $this->view_iassign = false;
  2287. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2288. // activity of type exercise (learner can send his answer, if yet open...)
  2289. $this->view_iassign = true;
  2290. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2291. $this->view_iassign = false;
  2292. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2293. $this->bottonPost = 1; // allow the submit button
  2294. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2295. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2296. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2297. if (!$iassign_submission) {
  2298. $str_iassign_submission_id = '';
  2299. $str_iassign_submission_answer = '';
  2300. }
  2301. else {
  2302. $str_iassign_submission_id = $iassign_submission->id;
  2303. $str_iassign_submission_answer = $iassign_submission->answer;
  2304. }
  2305. if ($this->action != 'repeat') {
  2306. $repeat = "<a href='view.php?action=repeat&id="
  2307. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2308. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2309. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2310. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2311. }
  2312. $this->bottonPost = 1;
  2313. $this->write_solution = 1; // can register his submission
  2314. $student_answer = $str_iassign_submission_answer;
  2315. }
  2316. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2317. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2318. $last_iassign = get_string('last_iassign', 'iassign');
  2319. if ($iassign_submission) {
  2320. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2321. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2322. $student_answer = $iassign_submission->answer;
  2323. } else {
  2324. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2325. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2326. }
  2327. }
  2328. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2329. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2330. $this->bottonPost = 1;
  2331. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2332. } else {
  2333. $last_iassign = get_string('last_iassign', 'iassign');
  2334. if ($iassign_submission) {
  2335. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2336. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2337. $student_answer = $iassign_submission->answer;
  2338. } else {
  2339. // Symbol of "redo activity"
  2340. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2341. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2342. }
  2343. }
  2344. } // elseif ($iassign_statement_activity_item->test == 1)
  2345. elseif ($iassign_statement_activity_item->test == 0)
  2346. $this->view_iassign = false;
  2347. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2348. if ($iassign_submission)
  2349. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2350. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2351. else
  2352. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2353. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2354. $this->activity->view_dates();
  2355. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2356. print $OUTPUT->box_start();
  2357. print '<table width=100% border=0 valign="top">' . "\n";
  2358. print '<tr><td width=60% valign="top">' . "\n";
  2359. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2360. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2361. $flag_dependency = true;
  2362. if ($iassign_statement_activity_item->type_iassign == 3) {
  2363. if ($iassign_statement_activity_item->dependency == 0) {
  2364. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2365. } else {
  2366. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2367. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2368. foreach ($dependencys as $dependency) {
  2369. if ($dependency) {
  2370. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2371. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2372. if ($dependencysubmissions) {
  2373. if ($dependencysubmissions->status == 3)
  2374. $icon = iassign_icons::insert('correct');
  2375. elseif ($dependencysubmissions->status == 2) {
  2376. $icon = iassign_icons::insert('incorrect');
  2377. $flag_dependency = false;
  2378. } elseif ($dependencysubmissions->status == 1) {
  2379. $icon = iassign_icons::insert('post');
  2380. $flag_dependency = false;
  2381. } elseif ($dependencysubmissions->status == 0) {
  2382. $icon = iassign_icons::insert('not_post');
  2383. $flag_dependency = false;
  2384. }
  2385. } else {
  2386. $icon = iassign_icons::insert('not_post');
  2387. $flag_dependency = false;
  2388. } // if ($dependencysubmissions)
  2389. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2390. } // if ($dependency)
  2391. } // foreach ($dependencys as $dependency)
  2392. } // if ($iassign_statement_activity_item->dependency == 0)
  2393. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2394. if ($flag_dependency == false) {
  2395. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2396. $this->view_iassign = false;
  2397. print '</tr></table>' . "\n";
  2398. }
  2399. else {
  2400. $this->view_iassign = true;
  2401. print '</td>' . "\n";
  2402. } // if ($flag_dependency == false)
  2403. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2404. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2405. // receiver=1 - message to teacher
  2406. // receiver=2 - message to student
  2407. if ($iassign_submission) {
  2408. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2409. if ($verify_message)
  2410. $comment = iassign_icons::insert('comment_unread');
  2411. }
  2412. print '<td width=40% valign="top" align="left">';
  2413. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2414. if ($iassign_statement_activity_item->show_answer == 1) {
  2415. // check status of solution sent by the student
  2416. if ($iassign_submission) {
  2417. switch ($iassign_submission->status) {
  2418. case 3 :
  2419. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2420. break;
  2421. case 2 :
  2422. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2423. break;
  2424. case 1 :
  2425. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2426. break;
  2427. default :
  2428. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2429. $repeat = "";
  2430. $last_iassign = "";
  2431. } // switch ($iassign_submission->status)
  2432. } else {
  2433. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2434. $repeat = "";
  2435. $last_iassign = "";
  2436. }
  2437. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2438. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2439. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2440. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2441. if ($iassign_statement_activity_item->max_experiment == 0)
  2442. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2443. else {
  2444. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2445. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2446. $repeat = "";
  2447. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2448. $this->bottonPost = 0;
  2449. $this->write_solution = 0;
  2450. }
  2451. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2452. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2453. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2454. if ($teacher)
  2455. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2456. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2457. } // if ($iassign_statement_activity_item->show_answer==1)
  2458. else {
  2459. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2460. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2461. $repeat = "";
  2462. $last_iassign = "";
  2463. } elseif ($iassign_submission->status == 1) {
  2464. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2465. }
  2466. }
  2467. print '</td>';
  2468. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2469. print '</tr></table>' . "\n";
  2470. // Presents the iLM
  2471. print '<table width=100% border=0 valign="top">' . "\n";
  2472. print '<td width=80% align="left">';
  2473. 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\".
  2474. print '<td width=20% align="rigth">';
  2475. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2476. print $repeat; // symbol of "redo activity"
  2477. print '</td></tr></table>' . "\n";
  2478. //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)'
  2479. $output = '';
  2480. if (!$iassign_ilm) {
  2481. $iassign_ilm = new stdClass();
  2482. $iassign_ilm->file_jar = "";
  2483. }
  2484. $output .= $OUTPUT->box_start();
  2485. $USER->iassignEdit = $this->bottonPost;
  2486. // ---
  2487. // Presents the iLM
  2488. // Prepare tags to present the iLM
  2489. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2490. $student_answer = ""; //?
  2491. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2492. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2493. $student_answer = "";
  2494. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2495. } else {
  2496. // When student is redoing his activity
  2497. // ATTENTION: exception used by iGeom (exercise with "script")
  2498. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2499. if (substr($ilm_name, 0, 5)=="igeom") {
  2500. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2501. $loadTeacherActivity = true;
  2502. }
  2503. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2504. }
  2505. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2506. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2507. //1 $history_comment = '';
  2508. //1 if ($iassign_submission) {
  2509. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2510. //1 }
  2511. //1 if (!empty($history_comment)) {
  2512. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2513. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2514. //1 $output .= $history_comment;
  2515. //1 $output .= "</table>\n";
  2516. //1 }
  2517. //1 $output .= "</form></center>\n";
  2518. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2519. //1 }
  2520. $output .= $OUTPUT->box_end();
  2521. print $output;
  2522. } // if ($this->view_iassign)
  2523. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2524. } // if ($this->view_iassign)
  2525. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2526. else
  2527. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2528. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2529. print '<table width=100% border=0 valign="top">' . "\n";
  2530. print '<tr><td width=60% valign="top">' . "\n";
  2531. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2532. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2533. print '</tr></table>' . "\n";
  2534. $student_answer = "";
  2535. $enderecoPOST = "";
  2536. // Prepare tags to present the iLM
  2537. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2538. print $output;
  2539. }
  2540. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2541. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2542. 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
  2543. // Put a block with area to sent/answer comments
  2544. $output = '';
  2545. $history_comment = '';
  2546. $row = optional_param('row', 0, PARAM_INT);
  2547. $column = optional_param('column', 0, PARAM_INT);
  2548. if ($iassign_submission) {
  2549. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2550. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2551. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2552. }
  2553. else {
  2554. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2555. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2556. }
  2557. $output .= $OUTPUT->box_start();
  2558. //if (!empty($history_comment)) {
  2559. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2560. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2561. $output .= "</table>";
  2562. print " <script type='text/javascript'>
  2563. //<![CDATA[
  2564. function submit_comment(url) {
  2565. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2566. var formData = new FormData();
  2567. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2568. var request = new XMLHttpRequest();
  2569. request.open('POST', url);
  2570. document.getElementById('comments_history').innerHTML = '';
  2571. request.onload = function (e) {
  2572. if (request.readyState === 4) {
  2573. if (request.status === 200) {
  2574. document.getElementById('comments_history').innerHTML = request.responseText;
  2575. document.getElementById('check-message-success').style.visibility = 'visible';
  2576. setTimeout(function(){
  2577. document.getElementById('check-message-success').style.visibility = 'hidden';
  2578. }, 3000);
  2579. }
  2580. }
  2581. };
  2582. document.formEnvioComment.submission_comment.value = '';
  2583. request.send(formData);
  2584. }
  2585. //]]>
  2586. </script>";
  2587. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2588. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2589. $output .= "<p><button class='btn btn-primary' onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'>".get_string('submit_comment', 'iassign')."</button> <i id='check-message-success' class='fa fa-check' aria-hidden='true' style='position: absolute; color: green; font-size: 2.0rem; margin-left: 1rem; visibility: hidden;'></i> </p> \n";
  2590. $output .= "</form> </center>\n";
  2591. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2592. // }
  2593. $output .= $OUTPUT->box_end();
  2594. print $output;
  2595. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2596. // final block 'studant'
  2597. print $OUTPUT->footer();
  2598. die();
  2599. } // function view_iassign_current()
  2600. /// Export the data from performance report into CSV file format
  2601. function export_csv () {
  2602. global $USER, $CFG, $DB, $OUTPUT;
  2603. $str = "";
  2604. $fields = "student_id, student_name";
  2605. // Finding all iassign activities for the iassign:
  2606. $id = $this->cm->id;
  2607. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2608. $c = 1;
  2609. foreach ($iassign_list as $iassign) {
  2610. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2611. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2612. $c ++;
  2613. }
  2614. // Finding enrolled students:
  2615. $params_temp = array('shortname' => 'student');
  2616. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2617. $context = context_course::instance($this->course->id);
  2618. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2619. $students = $DB->get_records_sql(
  2620. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2621. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2622. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2623. foreach ($students as $student) {
  2624. $str .= $student->userid . ',';
  2625. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2626. foreach ($iassign_list as $iassign) {
  2627. $str .= ',' . $iassign->id . ',';
  2628. $str .= '"' . $iassign->name . '",';
  2629. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2630. if ($student_submissions) {
  2631. $str .= $student_submissions->experiment . ',';
  2632. $str .= $student_submissions->grade . ',';
  2633. switch ($student_submissions->status) {
  2634. case 3:
  2635. $str .= '"correct",';
  2636. break;
  2637. case 2:
  2638. $str .= '"incorrect",';
  2639. break;
  2640. case 1:
  2641. $str .= '"post",';
  2642. break;
  2643. case 0:
  2644. $str .= '"not_post",';
  2645. break;
  2646. }
  2647. }
  2648. else {
  2649. $str .= ',,"not_post",';
  2650. }
  2651. $str .= $iassign->iassign_ilmid . ',';
  2652. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2653. $str .= '"' . $ilm_activity->name . '"';
  2654. }
  2655. $str .= "\n";
  2656. }
  2657. $str = $fields . "\n" . $str;
  2658. header("Content-type: text/csv");
  2659. header("Content-disposition: attachment; filename=report.csv");
  2660. header("Pragma: no-cache");
  2661. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2662. header('Content-Length: ' . strlen($str));
  2663. header('Connection: close');
  2664. print $str;
  2665. flush();
  2666. } // function export_csv()
  2667. /// Display report of performance
  2668. function report () {
  2669. global $USER, $CFG, $DB, $OUTPUT;
  2670. $id = $this->cm->id;
  2671. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2672. if ($this->action != 'print') {
  2673. $title = get_string('report', 'iassign');
  2674. print $OUTPUT->header();
  2675. } // if ($this->action != 'print')
  2676. print $OUTPUT->box_start();
  2677. $this->view_legend_icons();
  2678. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2679. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2680. print $OUTPUT->box_end();
  2681. if ($this->action == 'print')
  2682. print '<table border=1 width="100%">' . "\n";
  2683. else
  2684. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped" width="100%">' . "\n";
  2685. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2686. // $num = array();
  2687. $i = 1;
  2688. $num = array();
  2689. $stylebutton = "background: none; -webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75); min-width: 4.5rem;";
  2690. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2691. $test_exercise = "";
  2692. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2693. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2694. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2695. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2696. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2697. $num[$i] = new stdClass();
  2698. $num[$i]->name = $iassign->name;
  2699. $num[$i]->id = $i;
  2700. $num[$i]->iassignid = $iassign->id;
  2701. print ' <tr >' . "\n";
  2702. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2703. print "<td class=\"cell c0 actvity\">";
  2704. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2705. print ' </tr>' . "\n";
  2706. $i++;
  2707. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2708. } // foreach ($iassign_list as $iassign)
  2709. $num_exerc = $i; // total of exercises
  2710. print "</table>";
  2711. print "<p></p>";
  2712. if ($this->action == 'print')
  2713. print '<table border=1 width="100%">' . "\n";
  2714. else // ./theme/boost/style/moodle.css: .generaltable
  2715. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  2716. $context = context_course::instance($this->course->id);
  2717. if ($num_exerc > 1) {
  2718. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2719. $params_temp = array('shortname' => 'student');
  2720. $role = $DB->get_record_sql(
  2721. "SELECT s.id, s.shortname FROM {role} s " .
  2722. " WHERE s.shortname = :shortname", $params_temp);
  2723. // $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");
  2724. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2725. $students = $DB->get_records_sql(
  2726. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2727. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2728. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2729. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2730. $width = 90/$num_exerc;
  2731. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  2732. $sum_iassign_correct[$j] = 0;
  2733. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2734. }
  2735. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2736. $sum_iassign = $j - 1;
  2737. print '</tr>' . "\n";
  2738. $total = 0;
  2739. $sum_student = 0;
  2740. $comment = iassign_icons::insert('comment_read');
  2741. $sum_comment = 0;
  2742. $sum_correct_iassign = array();
  2743. $sum_correct_student = array();
  2744. $USER->matrix_iassign = array();
  2745. if ($students) {
  2746. $w = 0;
  2747. foreach ($students as $tmp) { // count students
  2748. $users_array[$w] = $tmp;
  2749. $w++;
  2750. }
  2751. for ($x=0; $x<$w; $x++) { // for all students
  2752. print '<tr>' . "\n";
  2753. $sum_student ++;
  2754. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2755. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  2756. $total_student = 0;
  2757. $tentativas = 0;
  2758. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  2759. $sum_comment = $sum_verify_message = 0;
  2760. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2761. if ($student_submissions) {
  2762. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2763. $tentativas = $student_submissions->experiment;
  2764. // Get student comments
  2765. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2766. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  2767. $student_submissions_comment = $DB->get_record_sql(
  2768. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2769. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  2770. if ($student_submissions_comment) // student has comment
  2771. foreach ($student_submissions_comment as $tmp)
  2772. $sum_comment = $tmp;
  2773. // informations to previous activities
  2774. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  2775. else $iassign_previous = $num[$j - 1]->iassignid;
  2776. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2777. else $user_previous = $users_array[$x - 1]->userid;
  2778. // next
  2779. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2780. else $iassign_next = "-1";
  2781. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2782. else $user_next = "-1";
  2783. $position = "&row= $x&column=$j";
  2784. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2785. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2786. $url .= $position;
  2787. // receiver=1 - message to teacher
  2788. // receiver=2 - message to student
  2789. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2790. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2791. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2792. $verify_message = $DB->get_record_sql(
  2793. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2794. "WHERE iassign_submissionid = :iassign_submissionid " .
  2795. " AND return_status= :return_status " .
  2796. " AND receiver= :receiver", $params_temp);
  2797. if ($verify_message)
  2798. foreach ($verify_message as $tmp)
  2799. $sum_verify_message = $tmp;
  2800. if ($sum_verify_message > 0)
  2801. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  2802. else
  2803. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  2804. if ($student_submissions->status == 3) {
  2805. $sum_iassign_correct[$j] ++;
  2806. $total_student ++;
  2807. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  2808. }
  2809. elseif ($student_submissions->status == 2) {
  2810. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  2811. }
  2812. elseif ($student_submissions->status == 1) {
  2813. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2814. }
  2815. elseif ($student_submissions->status == 0) {
  2816. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2817. }
  2818. if ($this->action != 'print') {
  2819. if ($tentativas > 0)
  2820. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2821. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2822. . $feedback
  2823. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2824. . $tentativas
  2825. . '</span> </button>'
  2826. . '</a>' . "\n";
  2827. else
  2828. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2829. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2830. . $feedback
  2831. .'</button>'
  2832. . '</a>' . "\n";
  2833. if ($sum_comment > 0 && $sum_verify_message > 0)
  2834. print '<a href="' . $url . '"> '
  2835. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2836. . $comment
  2837. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2838. . $sum_verify_message . '/' . $sum_comment
  2839. . '</span> </button>'
  2840. . '</a>';
  2841. else if ($sum_comment > 0)
  2842. print '<a href="' . $url . '"> '
  2843. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  2844. . $comment
  2845. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2846. . $sum_comment
  2847. . '</span> </button>'
  2848. . '</a>';
  2849. print '</td>' . "\n";
  2850. }
  2851. if ($this->action == 'print')
  2852. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2853. } // if ($student_submissions)
  2854. else { // if ($student_submissions)
  2855. // Student does not have any submission
  2856. // informations to browse previous activities
  2857. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  2858. else $iassign_previous = $num[$j - 1]->iassignid;
  2859. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2860. else $user_previous = $users_array[$x - 1]->userid;
  2861. // next
  2862. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2863. else $iassign_next = "-1";
  2864. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2865. else $user_next = "-1";
  2866. $position = "&row= $x&column=$j";
  2867. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2868. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2869. $url .= $position;
  2870. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2871. if ($this->action == 'print')
  2872. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2873. else {
  2874. print '<td style="text-align: center;"> <a href="' . $url . '">'
  2875. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2876. . $feedback
  2877. .'</button>'
  2878. . '</a>' . "\n";
  2879. // print '<td> &nbsp;</td>';
  2880. if ($sum_comment > 0)
  2881. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  2882. // else print '<td> &nbsp;</td>';
  2883. print '</td>';
  2884. }
  2885. } // else if ($student_submissions)
  2886. $USER->matrix_iassign[$x][$j] = new stdClass();
  2887. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2888. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2889. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2890. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2891. if ($student_submissions)
  2892. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2893. else
  2894. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2895. //print '</td>' . "\n";
  2896. } // for ($j=1; $j<$num_exerc; $j++)
  2897. $total = $total + $total_student;
  2898. $porcentagem = ($total_student / ($j - 1)) * 100;
  2899. if ($tentativas != 0 && $tentativas != null) {
  2900. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2901. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2902. }
  2903. else {
  2904. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2905. }
  2906. print '</tr>' . "\n";
  2907. $sum_correct_student[$sum_student] = new stdClass();
  2908. $sum_correct_student[$sum_student]->name = $name;
  2909. $sum_correct_student[$sum_student]->sum = $total_student;
  2910. } // for ($x = 0; $x < $w; $x ++)
  2911. for ($i = 1; $i < $j; $i ++) {
  2912. if (is_null($sum_iassign_correct[$i]))
  2913. $sum_iassign_correct[$i] = 0;
  2914. $sum_correct_iassign[$i] = new stdClass();
  2915. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2916. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2917. }
  2918. // print '</tr></table>' . "\n";
  2919. }
  2920. } // if ($i>1)
  2921. else {
  2922. print_string('no_activity', 'iassign');
  2923. }
  2924. print "</table>\n";
  2925. if ($this->action != 'print')
  2926. print $OUTPUT->footer();
  2927. die();
  2928. } // function report()
  2929. /// Display graphics of performance
  2930. function stats () {
  2931. global $USER, $CFG, $DB, $OUTPUT;
  2932. $id = $this->cm->id;
  2933. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2934. if ($this->action != 'printstats')
  2935. $title = get_string('graphic', 'iassign');
  2936. $num = array();
  2937. $sum_correct_iassign = array();
  2938. $sum_correct_student = array();
  2939. $sum_student = 0;
  2940. $i = 1;
  2941. foreach ($iassign_list as $iassign) {
  2942. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2943. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2944. $sum_iassign_correct[$i] = 0;
  2945. $num[$i] = new stdClass();
  2946. $num[$i]->name = $iassign->name;
  2947. $num[$i]->id = $i;
  2948. $num[$i]->iassignid = $iassign->id;
  2949. $i ++;
  2950. } // if ($iassign->type_iassign == 3)
  2951. } // foreach ($iassign_list as $iassign)
  2952. $sum_iassign = $i - 1;
  2953. $context = context_course::instance($this->course->id);
  2954. if ($i > 1) {
  2955. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2956. $params_temp = array('shortname' => 'student');
  2957. $role = $DB->get_record_sql(
  2958. "SELECT s.id, s.shortname FROM {role} s " .
  2959. " WHERE s.shortname = :shortname", $params_temp);
  2960. // $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");
  2961. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2962. $students = $DB->get_records_sql(
  2963. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2964. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2965. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2966. $total = 0;
  2967. $sum_student = 0;
  2968. $j = 0;
  2969. $sum_correct_iassign = array();
  2970. $sum_correct_student = array();
  2971. $sum_experiment = array();
  2972. if ($students) {
  2973. foreach ($students as $users) {
  2974. $sum_student ++;
  2975. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2976. // rows
  2977. $total_student = 0;
  2978. for ($j = 1; $j < $i; $j ++) {
  2979. $total_experiment = 0;
  2980. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2981. if ($student_submissions) {
  2982. if ($student_submissions->status == 3) {
  2983. $sum_iassign_correct[$j] ++;
  2984. $total_student ++;
  2985. } // if ($student_submissions->status == 3)
  2986. $total_experiment += $student_submissions->experiment;
  2987. }
  2988. $sum_experiment[$j] = $total_experiment;
  2989. } // for ($j=1; $j<$i; $j++)
  2990. $total = $total + $total_student;
  2991. $sum_correct_student[$sum_student] = new stdClass();
  2992. $sum_correct_student[$sum_student]->name = $name;
  2993. $sum_correct_student[$sum_student]->sum = $total_student;
  2994. } // foreach ($students as $users)
  2995. }
  2996. for ($i = 1; $i < $j; $i ++) {
  2997. if (is_null($sum_iassign_correct[$i]))
  2998. $sum_iassign_correct[$i] = 0;
  2999. $sum_correct_iassign[$i] = new stdClass();
  3000. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3001. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3002. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3003. } // for ($i = 1; $i < $j; $i++)
  3004. } // if ($i > 1)
  3005. if ($this->action != 'printstats') {
  3006. $title = get_string('graphic', 'iassign');
  3007. print $OUTPUT->header();
  3008. $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>";
  3009. $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>";
  3010. print '<table width=100%><tr>';
  3011. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3012. print '<td width=15% align="right">' . $link_report . '</td>';
  3013. print '</td></tr></table>' . "\n";
  3014. print "<br><br>";
  3015. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3016. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3017. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3018. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3019. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3020. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3021. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3022. print '</tr>' . "\n";
  3023. $sum_correct = 0;
  3024. if ($sum_correct_iassign) {
  3025. foreach ($sum_correct_iassign as $iassign) {
  3026. if (is_null($iassign->experiment))
  3027. $iassign->experiment = 0;
  3028. $bar = "";
  3029. $sum = $iassign->sum;
  3030. $percent = ($sum / $sum_student) * 100;
  3031. $text = number_format($percent, 1) . '%';
  3032. $sum_correct += $sum;
  3033. if ($sum > 0) {
  3034. for ($i = 1; $i < $percent * 2; $i ++)
  3035. $bar .= iassign_icons::insert('hbar_blue');
  3036. $bar .= iassign_icons::insert('hbar_blue_r');
  3037. } // if ($sum > 0)
  3038. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3039. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3040. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3041. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3042. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3043. print '</tr>' . "\n";
  3044. } // foreach ($sum_correct_iassign as $iassign)
  3045. }
  3046. print "</table>";
  3047. print "<br><br>";
  3048. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3049. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3050. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3051. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3052. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3053. print '</tr>' . "\n";
  3054. $sum_correct = 0;
  3055. foreach ($sum_correct_student as $student) {
  3056. $bar = "";
  3057. $sum = $student->sum;
  3058. $percent = ($sum / $sum_iassign) * 100;
  3059. $text = number_format($percent, 1) . '%';
  3060. $sum_correct += $sum;
  3061. if ($sum > 0) {
  3062. for ($i = 1; $i < $percent * 2; $i ++)
  3063. $bar .= iassign_icons::insert('hbar_blue');
  3064. $bar .= iassign_icons::insert('hbar_blue_r');
  3065. } // if ($sum > 0)
  3066. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3067. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3068. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3069. print '</tr>' . "\n";
  3070. } // foreach ($sum_correct_student as $student)
  3071. print "</table>\n";
  3072. print "<br><br>\n";
  3073. $var = 0;
  3074. $cv = 0;
  3075. $dv = 0;
  3076. $avg = 0;
  3077. if ($sum_correct_student) {
  3078. $avg = $sum_correct / $sum_student;
  3079. if ($avg > 0) {
  3080. foreach ($sum_correct_student as $student)
  3081. $var += pow($student->sum - $avg, 2);
  3082. $var = $var / $sum_student;
  3083. $dv = sqrt($var);
  3084. $cv = ($dv / $avg) * 100;
  3085. }
  3086. }
  3087. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3088. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3089. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3090. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3091. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3092. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3093. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3094. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3095. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3096. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3097. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3098. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3099. print "</table>\n";
  3100. print $OUTPUT->footer();
  3101. } else {
  3102. print "<STYLE TYPE='text/css'>
  3103. <!--
  3104. .boldtable {
  3105. font-family:sans-serif;
  3106. font-size:10pt;
  3107. }
  3108. -->
  3109. </STYLE>\n";
  3110. print '<table border=1 width=100%>' . "\n";
  3111. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3112. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3113. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3114. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3115. print '</tr>' . "\n";
  3116. $sum_correct = 0;
  3117. foreach ($sum_correct_iassign as $iassign) {
  3118. $bar = "";
  3119. $sum = $iassign->sum;
  3120. $percent = ($sum / $sum_student) * 100;
  3121. $text = number_format($percent, 1) . '%';
  3122. $sum_correct += $sum;
  3123. if ($sum > 0) {
  3124. for ($i = 1; $i < $percent * 2; $i ++)
  3125. $bar .= iassign_icons::insert('hbar_blue');
  3126. $bar .= iassign_icons::insert('hbar_blue_r');
  3127. } // if ($sum > 0)
  3128. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3129. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3130. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3131. print '</tr>' . "\n";
  3132. } // foreach ($sum_correct_iassign as $iassign)
  3133. print "</table>";
  3134. print "<br><br>";
  3135. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3136. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3137. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3138. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3139. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3140. print '</tr>' . "\n";
  3141. $sum_correct = 0;
  3142. foreach ($sum_correct_student as $student) {
  3143. $bar = "";
  3144. $sum = $student->sum;
  3145. $percent = ($sum / $sum_iassign) * 100;
  3146. $text = number_format($percent, 1) . '%';
  3147. $sum_correct += $sum;
  3148. if ($sum > 0) {
  3149. for ($i = 1; $i < $percent * 2; $i ++)
  3150. $bar .= iassign_icons::insert('hbar_blue');
  3151. $bar .= iassign_icons::insert('hbar_blue_r');
  3152. } // if ($sum > 0)
  3153. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3154. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3155. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3156. print '</tr>' . "\n";
  3157. } // foreach ($sum_correct_student as $student)
  3158. print "</table>\n";
  3159. print "<br/><br/>\n";
  3160. $var = 0;
  3161. $cv = 0;
  3162. $dv = 0;
  3163. $avg = 0;
  3164. if ($sum_correct_student) {
  3165. $avg = $sum_correct / $sum_student;
  3166. if ($avg > 0) {
  3167. foreach ($sum_correct_student as $student)
  3168. $var += pow($student->sum - $avg, 2);
  3169. $var = $var / $sum_student;
  3170. $dv = sqrt($var);
  3171. $cv = ($dv / $avg) * 100;
  3172. }
  3173. }
  3174. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3175. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3176. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3177. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3178. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3179. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3180. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3181. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3182. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3183. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3184. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3185. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3186. print "</table>\n";
  3187. } // if ($this->action != 'printstats')
  3188. die();
  3189. }
  3190. /// Display graphics of performance for students
  3191. function stats_students () {
  3192. global $USER, $CFG, $DB, $OUTPUT;
  3193. $id = $this->cm->id;
  3194. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3195. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3196. $title = get_string('results', 'iassign');
  3197. $sum_correct = 0;
  3198. $sum_incorrect = 0;
  3199. $sum_post = 0;
  3200. $sum_nopost = 0;
  3201. $sum_iassign = count($iassign_statement_list);
  3202. $bar_nopost = "";
  3203. $bar_correct = "";
  3204. $bar_incorrect = "";
  3205. $bar_post = "";
  3206. $text_nopost = "";
  3207. $text_correct = "";
  3208. $text_incorrect = "";
  3209. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3210. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3211. if ($iassign_submission) {
  3212. if ($iassign_submission->status == 3)
  3213. $sum_correct ++;
  3214. elseif ($iassign_submission->status == 2)
  3215. $sum_incorrect ++;
  3216. elseif ($iassign_submission->status == 1)
  3217. $sum_post ++;
  3218. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3219. $sum_nopost ++;
  3220. } // if ($iassign_submission)
  3221. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3222. if ($sum_iassign > 0) {
  3223. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3224. $text_correct = number_format($percent_correct, 1) . '%';
  3225. }
  3226. if ($sum_correct > 0) {
  3227. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3228. $bar_correct .= iassign_icons::insert('hbar_green');
  3229. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3230. } // if ($sum_correct > 0)
  3231. if ($sum_iassign > 0) {
  3232. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3233. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3234. }
  3235. if ($sum_incorrect > 0) {
  3236. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3237. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3238. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3239. } // if ($sum_incorrect > 0)
  3240. if ($sum_iassign > 0) {
  3241. $percent_post = ($sum_post / $sum_iassign) * 100;
  3242. $text_post = number_format($percent_post, 1) . '%';
  3243. }
  3244. if ($sum_post > 0) {
  3245. for ($i = 1; $i < $percent_post * 2; $i ++)
  3246. $bar_post .= iassign_icons::insert('hbar_blue');
  3247. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3248. } // if ($sum_post > 0)
  3249. if ($sum_iassign > 0) {
  3250. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3251. $text_nopost = number_format($percent_nopost, 1) . '%';
  3252. }
  3253. if ($sum_nopost > 0) {
  3254. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3255. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3256. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3257. } // if ($sum_nopost > 0)
  3258. print $OUTPUT->header();
  3259. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3260. print '<table width=100%><tr>';
  3261. print '<td align="right">' . $link_return . '</td>' . "\n";
  3262. print '</td></tr></table>' . "\n";
  3263. print "<br/><br/>\n";
  3264. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  3265. print '<tr><th colspan=3 class="header c1">' . "\n";
  3266. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3267. // $imagetext = '');
  3268. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3269. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3270. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3271. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3272. print '</tr>' . "\n";
  3273. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3274. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3275. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3276. print '</tr>' . "\n";
  3277. if ($sum_post) {
  3278. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3279. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3280. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3281. print '</tr>' . "\n";
  3282. } // if ($sum_post)
  3283. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3284. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3285. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3286. print '</tr>' . "\n";
  3287. print "</table>";
  3288. print "<br><br>";
  3289. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3290. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3291. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3292. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3293. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3294. $sum_grade = 0;
  3295. $sum_grade_student = 0;
  3296. $avg = 0;
  3297. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3298. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3299. if (!$iassign_submission) {
  3300. $iassign_submission = new stdClass();
  3301. $iassign_submission->grade = 0;
  3302. }
  3303. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3304. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3305. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3306. print '</tr>' . "\n";
  3307. $sum_grade += $iassign_statement_activity_item->grade;
  3308. $sum_grade_student += $iassign_submission->grade;
  3309. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3310. if ($sum_grade > 0)
  3311. $avg = $sum_grade_student / $sum_grade * 100;
  3312. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3313. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3314. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3315. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3316. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3317. print "</table>";
  3318. print $OUTPUT->footer();
  3319. die();
  3320. } // function stats_students()
  3321. /// Display page of iAssign's activity
  3322. function view_iassigns () {
  3323. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3324. $id = $this->cm->id;
  3325. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3326. $notice = optional_param('notice', '', PARAM_TEXT);
  3327. if (strpos($notice, 'error'))
  3328. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3329. else if ($notice != '')
  3330. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3331. print $OUTPUT->box_start();
  3332. print '<table width=100% border=0><tr>' . "\n";
  3333. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3334. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  3335. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  3336. $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>";
  3337. $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>";
  3338. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3339. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3340. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3341. // Has capability to see "report": teacher or up
  3342. print '<td width=10% align="left">' . "\n";
  3343. print $link_help;
  3344. print '</td>' . "\n";
  3345. print '<td width=10% align="left">' . "\n";
  3346. print $link_report;
  3347. print '</td>' . "\n";
  3348. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3349. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3350. print '<td width=15% align="left">' . "\n";
  3351. print $link_add;
  3352. print "</td>\n";
  3353. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3354. //print '</tr></table>' . "\n";
  3355. print '<div style="float: right;">';
  3356. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3357. if ($iassign_list) {
  3358. print '<td align="right">' . "\n";
  3359. // $USER->iassignEdit == 0 view 'Turn editing off'
  3360. // $USER->iassignEdit == 1 view 'Turn editing on'
  3361. if (!isset($USER->iassignEdit))
  3362. $USER->iassignEdit = 0;
  3363. if ($USER->iassignEdit == 0) {
  3364. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3365. $botton = 1;
  3366. } // if ($USER->iassignEdit == 0)
  3367. elseif ($USER->iassignEdit == 1) {
  3368. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3369. $botton = 0;
  3370. } // elseif ($USER->iassignEdit == 1)
  3371. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3372. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3373. print " <input type=submit value='$bottonEdit_message'/>\n";
  3374. print "</form>\n";
  3375. print "</td>\n";
  3376. } // if ($iassign_list)
  3377. }
  3378. print '</tr></table>' . "\n";
  3379. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3380. // $this->view_legend_icons();
  3381. print $OUTPUT->box_end();
  3382. $iassign_array_exercise = array();
  3383. $i_exercise = 0;
  3384. $iassign_array_test = array();
  3385. $i_test = 0;
  3386. $iassign_array_example = array();
  3387. $i_example = 0;
  3388. $iassign_array_general = array();
  3389. $i_general = 0;
  3390. if ($iassign_list) {
  3391. if ($this->iassign->activity_group == 0) {
  3392. foreach ($iassign_list as $iassign) {
  3393. $iassign_array_general[$i_general] = $iassign;
  3394. $i_general ++;
  3395. }
  3396. } // if ($this->iassign->activity_group == 0)
  3397. else {
  3398. foreach ($iassign_list as $iassign) {
  3399. if ($iassign->type_iassign == 3) {
  3400. $iassign_array_exercise[$i_exercise] = $iassign;
  3401. $i_exercise ++;
  3402. } // if ($iassign->type_iassign == 3)
  3403. if ($iassign->type_iassign == 2) {
  3404. $iassign_array_test[$i_test] = $iassign;
  3405. $i_test ++;
  3406. } // if ($iassign->type_iassign == 2)
  3407. if ($iassign->type_iassign == 1) {
  3408. $iassign_array_example[$i_example] = $iassign;
  3409. $i_example ++;
  3410. } // if ($iassign->type_iassign == 1)
  3411. }
  3412. }
  3413. if ($iassign_array_exercise) {
  3414. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3415. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3416. }
  3417. if ($iassign_array_test) {
  3418. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3419. $this->show_iassign($title, $iassign_array_test, $i_test);
  3420. }
  3421. if ($iassign_array_example) {
  3422. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3423. $this->show_iassign($title, $iassign_array_example, $i_example);
  3424. }
  3425. if ($iassign_array_general) {
  3426. $title = "";
  3427. $this->show_iassign($title, $iassign_array_general, $i_general);
  3428. }
  3429. } else { // if ($iassign_list)
  3430. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3431. }
  3432. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3433. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3434. print $OUTPUT->box_start();
  3435. print '<table width=100% border=0><tr>' . "\n";
  3436. print '<td width=10% align="left">' . "\n";
  3437. print $link_report;
  3438. print '</td>' . "\n";
  3439. print '</tr></table>' . "\n";
  3440. print $OUTPUT->box_end();
  3441. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3442. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3443. print $OUTPUT->box_start();
  3444. print '<table width=100% border=0><tr>' . "\n";
  3445. print '<td align="left">' . "\n";
  3446. print $link_add;
  3447. print '</td>' . "\n";
  3448. print '</tr></table>' . "\n";
  3449. print $OUTPUT->box_end();
  3450. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3451. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3452. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3453. $this->view_legend_icons();
  3454. } // function view_iassigns()
  3455. /// Display all iAssigns
  3456. function show_iassign ($title, $iassign_array, $i) {
  3457. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3458. $id = $this->cm->id;
  3459. print $OUTPUT->box_start();
  3460. print " <script type='text/javascript'>
  3461. //<![CDATA[
  3462. function validate_move () {
  3463. var radios = document.getElementsByName('iassign_destiny');
  3464. var formValid = false;
  3465. //alert('aqui validate_move()');
  3466. var i = 0;
  3467. while (!formValid && i < radios.length) {
  3468. if (radios[i].checked) formValid = true;
  3469. i++;
  3470. }
  3471. if (!formValid) {
  3472. document.getElementById('move_dest').classList.add('alert-danger');
  3473. }
  3474. return formValid;
  3475. }
  3476. var modal;
  3477. function load_move(id_ias) {
  3478. document.form_move_activity.iassign_current.value = id_ias;
  3479. modal.style.display = 'block';
  3480. var radios = document.getElementsByName('iassign_destiny');
  3481. var i = 0;
  3482. while (i < radios.length) {
  3483. radios[i].checked = false;
  3484. i++;
  3485. }
  3486. document.getElementById('move_dest').classList.remove('alert-danger');
  3487. }
  3488. function load_modal_elements() {
  3489. modal = document.getElementById('myModal');
  3490. var span = document.getElementById('close_modal');
  3491. span.onclick = function() {
  3492. modal.style.display = 'none';
  3493. }
  3494. window.onclick = function(event) {
  3495. if (event.target == modal) {
  3496. modal.style.display = 'none';
  3497. }
  3498. }
  3499. }
  3500. window.onload = load_modal_elements;
  3501. //]]>
  3502. </script>\n";
  3503. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3504. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3505. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3506. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3507. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3508. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3509. <input type='hidden' name='iassign_current' value='' />";
  3510. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3511. $section = $course_sections[0];
  3512. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3513. for ($k = 0; $k < count($ids_sections); $k++) {
  3514. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3515. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3516. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3517. if ($c_cm) {
  3518. if ($ccm->instance == $c_cm->instance) {
  3519. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3520. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3521. }
  3522. else {
  3523. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3524. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3525. }
  3526. }
  3527. }
  3528. $radio_buttons .= "</ul>";
  3529. }
  3530. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3531. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3532. </form>
  3533. </div></div> </div></div>\n";
  3534. print " <style>.modal {
  3535. display: none;
  3536. position: fixed;
  3537. z-index: 1;
  3538. left: 0;
  3539. top: 0;
  3540. width: 100%;
  3541. height: 100%;
  3542. overflow: scroll;
  3543. background-color: rgb(0,0,0);
  3544. background-color: rgba(0,0,0,0.4);
  3545. }
  3546. .modal-content {
  3547. background-color: #fefefe;
  3548. margin: 15% auto;
  3549. padding: 10px 10px;
  3550. border: 1px solid #888;
  3551. width: 50%;
  3552. }
  3553. #close_modal {
  3554. color: #aaa;
  3555. float: right;
  3556. font-size: 28px;
  3557. font-weight: bold;
  3558. margin-top: -15px;
  3559. margin-right: -3px;
  3560. }
  3561. #close_modal:hover,
  3562. #close_modal:focus {
  3563. color: black;
  3564. text-decoration: none;
  3565. cursor: pointer;
  3566. }
  3567. #modal_title {
  3568. min-height: 3rem;
  3569. color: initial;
  3570. background: initial;
  3571. font-size: 1.5rem;
  3572. line-height: 1.5;
  3573. padding: 15px;
  3574. border-bottom: 1px solid #e5e5e5;
  3575. }
  3576. .input_move {
  3577. width: 90%;
  3578. padding: 2px;
  3579. }
  3580. .input_move:hover {
  3581. background: #eff0ef;
  3582. }
  3583. </style>";
  3584. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3585. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3586. for ($j = 0; $j < $i; $j ++) {
  3587. $iassign_current = $iassign_array[$j]->id;
  3588. // receiver=1 - message to teacher
  3589. // receiver=2 - message to student
  3590. $sum_comment = 0;
  3591. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3592. foreach ($iassign_submissions as $iassign_submission) {
  3593. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3594. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3595. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  3596. if ($verify_message)
  3597. foreach ($verify_message as $tmp)
  3598. $sum_comment += $tmp;
  3599. } // foreach ($iassign_submissions as $iassign_submission)
  3600. if ($sum_comment == 0)
  3601. $comment_unread = "";
  3602. else {
  3603. $comment_unread_message = get_string('comment_unread', 'iassign');
  3604. if ($sum_comment == 1)
  3605. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3606. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3607. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3608. }
  3609. if ($j == $i - 1)
  3610. $iassign_down = $iassign_array[$j]->id;
  3611. else
  3612. $iassign_down = $iassign_array[$j + 1]->id;
  3613. if ($j > 0)
  3614. $iassign_up = $iassign_array[$j - 1]->id;
  3615. else
  3616. $iassign_up = $iassign_array[$j]->id;
  3617. if ($iassign_array[$j]->visible == 0)
  3618. $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>";
  3619. else
  3620. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3621. $links .= $comment_unread;
  3622. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3623. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3624. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3625. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3626. if ($j==0) // first activity
  3627. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3628. else
  3629. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3630. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3631. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3632. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3633. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3634. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3635. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3636. if (count($iassign_array) > 1) {
  3637. if ($j == 0)
  3638. $links .= $link_down;
  3639. elseif ($j == $i - 1)
  3640. $links .= $link_up;
  3641. else
  3642. $links .= $link_up . $link_down;
  3643. } // if (count($iassign_array) > 1)
  3644. $links .= $link_edit . $link_delete;
  3645. if ($iassign_array[$j]->visible == 0)
  3646. $links .= $link_visible_show;
  3647. else
  3648. $links .= $link_visible_hide;
  3649. $links .= $link_duplicate_activity . $link_move_activity;
  3650. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3651. print '<p>' . $links . '</p>' . "\n";
  3652. }
  3653. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3654. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3655. print '<table width=100% ><tr>' . "\n";
  3656. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3657. print '</tr></table>' . "\n";
  3658. for ($j = 0; $j < $i; $j ++) {
  3659. $icon_status = "";
  3660. $icon_comment = "";
  3661. if ($iassign_array[$j]->visible == 1) {
  3662. $iassign_current = $iassign_array[$j]->id;
  3663. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3664. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3665. $icon_status = "";
  3666. $icon_comment = "";
  3667. if ($iassign_submission) {
  3668. // receiver=1 - message to teacher
  3669. // receiver=2 - message to student
  3670. // $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");
  3671. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3672. $verify_message = $DB->get_record_sql(
  3673. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3674. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  3675. if ($verify_message)
  3676. foreach ($verify_message as $tmp)
  3677. $sum_comment = $tmp;
  3678. if ($sum_comment > 0) {
  3679. $comment_unread_message = get_string('comment_unread', 'iassign');
  3680. if ($sum_comment == 1)
  3681. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3682. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3683. }
  3684. // $icon_comment = iassign_icons::insert('comment_unread');
  3685. if ($iassign_array[$j]->type_iassign == 3) {
  3686. if ($iassign_array[$j]->show_answer == 1) {
  3687. if ($iassign_submission->status == 3)
  3688. $icon_status = iassign_icons::insert('correct');
  3689. elseif ($iassign_submission->status == 2)
  3690. $icon_status = iassign_icons::insert('incorrect');
  3691. elseif ($iassign_submission->status == 1)
  3692. $icon_status = iassign_icons::insert('post');
  3693. elseif ($iassign_submission->status == 0)
  3694. $icon_status = iassign_icons::insert('not_post');
  3695. } // if ($iassign_array[$j]->show_answer==1)
  3696. else {
  3697. if ($iassign_submission->status == 0)
  3698. $icon_status = iassign_icons::insert('not_post');
  3699. else
  3700. $icon_status = iassign_icons::insert('post');
  3701. }
  3702. } // if ($iassign_array[$j]->type_iassign == 3)
  3703. } // if ($iassign_submission)
  3704. elseif ($iassign_array[$j]->type_iassign == 3) {
  3705. $icon_status = iassign_icons::insert('not_post');
  3706. } // if ($iassign_array[$j]->type_iassign == 3)
  3707. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3708. } // if ($iassign_array[$j]->visible == 1)
  3709. } // for ($j = 0; $j < $i; $j++)
  3710. } else if (isguestuser()) {
  3711. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3712. print '<table width=100% ><tr>' . "\n";
  3713. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3714. print '</tr></table>' . "\n";
  3715. for ($j = 0; $j < $i; $j ++) {
  3716. $icon_status = "";
  3717. $icon_comment = "";
  3718. if ($iassign_array[$j]->visible == 1) {
  3719. $iassign_current = $iassign_array[$j]->id;
  3720. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3721. print '<p>' . $links . '</p>' . "\n";
  3722. } // if ($iassign_array[$j]->visible == 1)
  3723. }
  3724. }
  3725. print $OUTPUT->box_end();
  3726. } // function show_iassign($title, $iassign_array, $i)
  3727. /// Show message of return
  3728. function return_home_course ($message) {
  3729. //D global $DB, $OUTPUT;
  3730. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3731. //D echo $OUTPUT->box_start();
  3732. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3733. //D echo '<tr><td align="left"><strong>' . "\n";
  3734. //D print_string($message, 'iassign');
  3735. //D echo '</strong></td>' . "\n";
  3736. //D echo '<td width=20% align="right">' . "\n";
  3737. //D echo $link_return;
  3738. //D echo '</td></tr></table>' . "\n";
  3739. //D echo $OUTPUT->box_end();
  3740. //D // echo $OUTPUT->footer();
  3741. redirect(new moodle_url($this->return . '&notice=' . $message));
  3742. exit;
  3743. }
  3744. /// Search comment of activity
  3745. function search_comment_submission ($iassign_submissionid) {
  3746. global $USER, $DB, $OUTPUT, $COURSE;
  3747. // $context = context_course::instance($COURSE->id);
  3748. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3749. $colorEdit2 = "#d2e5fc";
  3750. $has_capability = 0;
  3751. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3752. $text = "";
  3753. if ($comments) {
  3754. $even = 1;
  3755. foreach ($comments as $tmp) {
  3756. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3757. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3758. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3759. // $text .= $tmp->comment . "</td></tr>";
  3760. //} else {
  3761. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3762. $avatar = new user_picture($user_data);
  3763. $avatar->courseid = $COURSE->id;
  3764. $avatar->link = true;
  3765. $user_picture = $OUTPUT->render($avatar);
  3766. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3767. if ($even) {
  3768. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit1 . "'>$user_picture</td><td bgcolor='" . $colorEdit1 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  3769. $even = 0;
  3770. } else {
  3771. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit2 . "'>$user_picture</td><td bgcolor='" . $colorEdit2 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  3772. $even = 1;
  3773. }
  3774. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3775. } // foreach ($comments as $tmp)
  3776. }
  3777. return $text;
  3778. }
  3779. /// Update comment of activity
  3780. function update_comment ($iassign_submissionid) {
  3781. global $USER, $DB, $OUTPUT;
  3782. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3783. $receiver = 1; // student message to teacher
  3784. else
  3785. $receiver = 2; // teacher message to student
  3786. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3787. if ($verify_message) {
  3788. foreach ($verify_message as $message) {
  3789. if ($message->receiver == $receiver) {
  3790. $newentry = new stdClass();
  3791. $newentry->id = $message->id;
  3792. $newentry->return_status = 1;
  3793. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3794. print_error('error_update', 'iassign');
  3795. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3796. } // if ($message->receiver == $receiver)
  3797. // Trigger module viewed event.
  3798. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3799. 'objectid' => $this->iassign->id,
  3800. 'context' => $this->context
  3801. ));
  3802. $event->add_record_snapshot('course', $this->course);
  3803. $event->trigger();
  3804. } // foreach ($verify_message as $message)
  3805. }
  3806. }
  3807. /// Record comment of activity
  3808. function write_comment_submission () {
  3809. global $USER, $CFG, $DB;
  3810. $id = $this->cm->id;
  3811. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3812. $row = optional_param('row', 0, PARAM_INT);
  3813. $column = optional_param('column', 0, PARAM_INT);
  3814. $sum_comment = 0;
  3815. $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);
  3816. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3817. $str1 = trim($submission_comment);
  3818. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3819. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3820. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3821. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3822. $receiver = 1; // student message to teacher
  3823. $this->action = 'view';
  3824. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3825. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3826. } else {
  3827. $receiver = 2; // teacher message to student
  3828. $this->action = 'viewsubmission';
  3829. //D $tousers = array(); //MOOC 2016
  3830. //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
  3831. }
  3832. //MOOC 2016: foi p/ 15 linhas acima:
  3833. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3834. // verificar se existe uma submissão para o exercício e aluno informados
  3835. if (!$iassign_submission) {
  3836. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3837. }
  3838. if (!$iassign_submission) {
  3839. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3840. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3841. $this->iassign_submission_current = $id_submission;
  3842. }
  3843. else {
  3844. $id_submission = $iassign_submission->id;
  3845. } // if (!$iassign_submission)
  3846. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3847. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3848. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3849. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3850. $comments = $DB->get_record_sql(
  3851. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3852. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  3853. if ($comments)
  3854. foreach ($comments as $tmp)
  3855. $sum_comment = $tmp;
  3856. if ($sum_comment == 0) {
  3857. $newentry = new stdClass();
  3858. $newentry->iassign_submissionid = $id_submission;
  3859. $newentry->comment_authorid = $USER->id;
  3860. $newentry->timecreated = time();
  3861. $newentry->comment = $submission_comment;
  3862. $newentry->receiver = $receiver;
  3863. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3864. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3865. //T $eventdata = new stdClass();
  3866. //T $eventdata->component = 'mod_iassign'; //your component name
  3867. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3868. //T $eventdata->userfrom = $USER;
  3869. //T $eventdata->userto = $touser;
  3870. //T $eventdata->subject = "Teste de Subject";
  3871. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3872. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3873. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3874. //T $eventdata->smallmessage = "Teste de Mensagem";
  3875. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3876. //T // alteracao tulio faria
  3877. //T //message_send($eventdata);
  3878. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3879. // Trigger module viewed event.
  3880. $event = \mod_iassign\event\submission_comment_created::create(array(
  3881. 'objectid' => $this->iassign->id,
  3882. 'context' => $this->context
  3883. ));
  3884. $event->add_record_snapshot('course', $this->course);
  3885. $event->trigger();
  3886. }
  3887. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3888. // if ($this->action=='viewsubmission') {
  3889. // echo $OUTPUT->header();
  3890. // $this->return_last('confirm_add_comment', $link_return);
  3891. // die;
  3892. // }
  3893. return true;
  3894. } // function write_comment_submission()
  3895. /// Writes a new submission
  3896. // The first student answer is under 'function get_answer()'
  3897. function new_submission ($iassignid, $id_user, $receiver) {
  3898. global $USER, $DB, $OUTPUT;
  3899. $newentry = new stdClass();
  3900. $newentry->iassign_statementid = $iassignid;
  3901. $newentry->userid = $id_user;
  3902. $newentry->timecreated = time();
  3903. $newentry->timemodified = time();
  3904. $newentry->answer = 0; // student only submit message
  3905. if ($receiver == 2) // teacher message to student (write id teacher)
  3906. $newentry->teacher = $USER->id;
  3907. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3908. return_home_course('error_insert_submissions');
  3909. else {
  3910. // Trigger module view event
  3911. $event = \mod_iassign\event\submission_created::create(array(
  3912. 'objectid' => $this->iassign->id,
  3913. 'context' => $this->context
  3914. ));
  3915. $event->add_record_snapshot('course', $this->course);
  3916. $event->trigger();
  3917. }
  3918. return $newentry->id;
  3919. }
  3920. /// Return to a specific address of page
  3921. function return_last ($message, $link_return) {
  3922. global $DB, $OUTPUT;
  3923. print $OUTPUT->box_start();
  3924. print '<table width=100% border=0 valign="top">' . "\n";
  3925. print '<tr><td align="left"><strong>' . "\n";
  3926. print_string($message, 'iassign');
  3927. print '</strong></td>' . "\n";
  3928. print '<td width=20% align="right">' . "\n";
  3929. print $link_return;
  3930. print '</td></tr></table>' . "\n";
  3931. print $OUTPUT->box_end();
  3932. print $OUTPUT->footer();
  3933. die();
  3934. } // function return_last($message, $link_return)
  3935. } // class iassign
  3936. /// Class for manage activities
  3937. class activity {
  3938. var $activity;
  3939. /// Constructor of class.
  3940. // @param int $id Id of activity
  3941. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3942. //D public function activity($id) { self::__construct($id); }
  3943. function __construct ($id) {
  3944. global $DB;
  3945. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3946. if (empty($this->activity))
  3947. $this->activity = null;
  3948. }
  3949. /// Get an activity
  3950. // @return NULL
  3951. function get_activity () {
  3952. if ($this->activity != null)
  3953. return $this->activity;
  3954. else
  3955. return null;
  3956. }
  3957. /// Delete interactive activities
  3958. function delete ($return) {
  3959. global $USER, $CFG, $DB, $OUTPUT;
  3960. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3961. $output = $OUTPUT->header();
  3962. $output .= $OUTPUT->box_start();
  3963. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3964. if ($iassign_submission_currents) {
  3965. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3966. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3967. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3968. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3969. $output .= $OUTPUT->box_end();
  3970. $output .= $OUTPUT->footer();
  3971. print $output;
  3972. die();
  3973. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3974. } // if ($iassign_submission_currents)
  3975. else
  3976. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3977. $output .= '<table width=50% border=0>';
  3978. $output .= '<tr valign="top"><td>';
  3979. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3980. $output .= '</td><td>';
  3981. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3982. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3983. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3984. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3985. $output .= "</form>\n";
  3986. $output .= '</td><td>';
  3987. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3988. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3989. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3990. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3991. $output .= "</form>\n";
  3992. $output .= '</td></tr></table>' . "\n";
  3993. $output .= $OUTPUT->box_end();
  3994. $output .= $OUTPUT->footer();
  3995. print $output;
  3996. } // function delete($return)
  3997. /// Function for confirm the delete of activity
  3998. // @param String $return Url of return
  3999. // @param Object $iassign Object content an activity
  4000. function deleteyes ($return, $iassign) {
  4001. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4002. $msg = '';
  4003. if (!empty($this->activity->id)) {
  4004. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4005. if ($iassign_submission_currents) {
  4006. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4007. foreach ($iassign_submission_currents as $iassign_submission)
  4008. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4009. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4010. } // if ($iassign_submission_currents)
  4011. }
  4012. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4013. // Remove all files associated to this activity:
  4014. $fs = get_file_storage();
  4015. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4016. $this->delete_calendar($this->activity->id);
  4017. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4018. iassign::update_grade_iassign($this->activity->iassignid);
  4019. if ($delete_iassign_current) {
  4020. $iassign->return_home_course('confirm_delete_iassign');
  4021. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4022. } else {
  4023. $iassign->return_home_course('error_confirm_delete_iassign');
  4024. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4025. }
  4026. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4027. }
  4028. }
  4029. /// Changes position of activities (between those inside a group of interactive activities)
  4030. // @param $move_action = must be "up" or "down"
  4031. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4032. function move_iassign ($move_action, $target, $return) {
  4033. global $DB, $OUTPUT;
  4034. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4035. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4036. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4037. if ($move_action=="firstdown") {
  4038. $final_position_source = 2;
  4039. $final_position_target = 1;
  4040. }
  4041. else
  4042. if ($move_action=="down") {
  4043. $final_position_target = $this->activity->position;
  4044. $final_position_source = $final_position_target + 1;
  4045. }
  4046. else
  4047. if ($move_action=="up") {
  4048. $final_position_target = $this->activity->position;
  4049. $final_position_source = $final_position_target - 1;
  4050. }
  4051. else { // error:
  4052. print_error('error_update_move_iassign', 'iassign');
  4053. exit;
  4054. }
  4055. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4056. $newentry->id = $this->activity->id; // ID of the "source activity"
  4057. $newentry->position = $final_position_source;
  4058. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4059. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4060. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4061. print_error('error_update_move_iassign', 'iassign');
  4062. }
  4063. else { // first update performed successfully
  4064. $newentry->id = $iassign_target->id;
  4065. $newentry->position = $final_position_target;
  4066. if (!$DB->update_record('iassign_statement', $newentry))
  4067. print_error('error_update_move_iassign', 'iassign');
  4068. }
  4069. redirect($return);
  4070. }
  4071. /// Enable or disable the display of interactive activities
  4072. function visible_iassign ($return) {
  4073. global $DB;
  4074. $newentry = new stdClass();
  4075. $newentry->id = $this->activity->id;
  4076. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4077. if (!$DB->update_record('iassign_statement', $newentry))
  4078. print_error('error_update_visible_iassign', 'iassign');
  4079. redirect($return);
  4080. }
  4081. /// Add news interactive activities (register in table 'iassign_statement')
  4082. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4083. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4084. function new_iassign ($param) {
  4085. global $DB;
  4086. $newentry = new stdClass();
  4087. $newentry->iassignid = $param->iassignid;
  4088. $newentry->name = $param->name;
  4089. $newentry->type_iassign = $param->type_iassign;
  4090. $newentry->store_all_submissions = $param->store_all_submissions;
  4091. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4092. $proposition = $param->proposition;
  4093. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4094. else $proposition_text = $proposition;
  4095. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4096. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4097. //TODO Then get it directly from the form data $_POST!
  4098. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4099. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4100. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4101. $newentry->author_name = $param->author_name;
  4102. $newentry->author_modified_name = $param->author_modified_name;
  4103. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4104. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4105. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4106. $newentry->grade = $param->grade;
  4107. $newentry->timemodified = time();
  4108. $newentry->timecreated = time();
  4109. if ($param->type_iassign == 1) {
  4110. $newentry->timedue = 0;
  4111. $newentry->timeavailable = 0;
  4112. } // if ($param->type_iassign == 1)
  4113. else {
  4114. $newentry->timedue = $param->timedue;
  4115. $newentry->timeavailable = $param->timeavailable;
  4116. }
  4117. $newentry->preventlate = $param->preventlate;
  4118. $newentry->test = $param->test;
  4119. $newentry->special_param1 = $param->special_param1;
  4120. $newentry->visible = $param->visible;
  4121. $newentry->position = $param->position;
  4122. $newentry->max_experiment = $param->max_experiment;
  4123. $newentry->dependency = $param->dependency;
  4124. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4125. $newentry->show_answer = $param->show_answer;
  4126. $id = $DB->insert_record("iassign_statement", $newentry);
  4127. if ($id) {
  4128. $component = 'mod_iassign';
  4129. $filearea = 'exercise';
  4130. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4131. $file = $fs->get_file_by_id($param->file);
  4132. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4133. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4134. //$itemid = $id;
  4135. // File already inserted in other context!
  4136. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4137. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4138. $updateentry = new stdClass();
  4139. $updateentry->id = $id;
  4140. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4141. $updateentry->filesid = $newfile->get_itemid();
  4142. if (!$DB->update_record("iassign_statement", $updateentry))
  4143. print_error('error_add', 'iassign');
  4144. if ($param->type_iassign == 3)
  4145. iassign::update_grade_iassign($param->iassignid);
  4146. //TODO iLM_HTML5 :: //MOOC2014
  4147. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4148. //D if ($iassign_ilm_configs) {
  4149. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4150. //D if ($iassign_ilm_config->param_type != 'static') {
  4151. //D $newentry = new stdClass();
  4152. //D $newentry->iassign_statementid = $id;
  4153. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4154. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4155. //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});
  4156. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4157. //D print_error('error_add_param', 'iassign');
  4158. //D }
  4159. //D }
  4160. //D }
  4161. // log event --------------------------------------------------------------------------------------
  4162. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4163. // log event --------------------------------------------------------------------------------------
  4164. return $id;
  4165. }
  4166. else
  4167. print_error('error_add', 'iassign');
  4168. } // function new_iassign($param)
  4169. /// Add the calendar entries for this iassign
  4170. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4171. // @return bool
  4172. static function add_calendar ($iassignid) {
  4173. global $DB, $CFG;
  4174. require_once($CFG->dirroot . '/calendar/lib.php');
  4175. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4176. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4177. $event = new stdClass();
  4178. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4179. $event->description = $iassign_statement_activity_item->name;
  4180. $event->courseid = $iassign->course;
  4181. $event->groupid = 0;
  4182. $event->userid = 0;
  4183. $event->modulename = 'iassign';
  4184. $event->instance = $iassign->id;
  4185. $event->eventtype = 'due';
  4186. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4187. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4188. calendar_event::create($event);
  4189. }
  4190. /// Update the calendar entries for this iassign
  4191. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4192. // @return bool
  4193. function update_calendar ($iassignid, $olddescription) {
  4194. global $DB, $CFG;
  4195. require_once($CFG->dirroot . '/calendar/lib.php');
  4196. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4197. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4198. $event = new stdClass();
  4199. $event->id = 0;
  4200. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4201. if ($events) {
  4202. foreach ($events as $value) {
  4203. if ($value->description == $olddescription) {
  4204. $event->id = $value->id;
  4205. }
  4206. }
  4207. }
  4208. if ($event->id != 0) {
  4209. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4210. $event->description = $iassign_statement_activity_item->name;
  4211. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4212. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4213. $calendarevent = calendar_event::load($event->id);
  4214. $calendarevent->update($event);
  4215. } else
  4216. $this->add_calendar($iassignid);
  4217. }
  4218. /// Update the calendar entries for this iassign
  4219. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4220. // @return bool
  4221. function delete_calendar ($iassignid) {
  4222. global $DB, $CFG;
  4223. require_once($CFG->dirroot . '/calendar/lib.php');
  4224. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4225. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4226. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4227. if ($events) {
  4228. foreach ($events as $value) {
  4229. if ($value->description == $iassign_statement_activity_item->name) {
  4230. $DB->delete_records('event', array('id' => $value->id));
  4231. }
  4232. }
  4233. }
  4234. }
  4235. /// Update interactive activities
  4236. function update_iassign ($param) {
  4237. global $DB;
  4238. $component = 'mod_iassign';
  4239. $filearea = 'exercise';
  4240. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4241. $file = $fs->get_file_by_id($param->file);
  4242. $fileold = $fs->get_file_by_id($param->fileold);
  4243. if ($param->file != $param->fileold) {
  4244. if ($fileold) {
  4245. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4246. foreach ($fileoldarea as $value) {
  4247. $value->delete();
  4248. }
  4249. }
  4250. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4251. $itemid = $file->get_itemid() + $param->iassign_id;
  4252. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4253. $param->file = $newfile->get_itemid();
  4254. } else
  4255. $param->file = $file->get_itemid();
  4256. } else {
  4257. $param->file = $file->get_itemid();
  4258. }
  4259. $newentry = new stdClass();
  4260. $newentry->id = $param->iassign_id;
  4261. $newentry->name = $param->name;
  4262. $newentry->type_iassign = $param->type_iassign;
  4263. $newentry->store_all_submissions = $param->store_all_submissions;
  4264. //2019 $newentry->proposition = $param->proposition;
  4265. $proposition = $param->proposition;
  4266. if (is_array($proposition))
  4267. $proposition_text = $proposition['text'];
  4268. else
  4269. $proposition_text = $proposition;
  4270. $newentry->proposition = $proposition_text;
  4271. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4272. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4273. $newentry->grade = $param->grade;
  4274. $newentry->author_modified_name = $param->author_modified_name;
  4275. $newentry->timemodified = time();
  4276. if ($param->type_iassign == 1) {
  4277. $newentry->timedue = 0;
  4278. $newentry->timeavailable = 0;
  4279. } // if ($param->type_iassign == 1)
  4280. else {
  4281. $newentry->timedue = $param->timedue;
  4282. $newentry->timeavailable = $param->timeavailable;
  4283. }
  4284. $newentry->preventlate = $param->preventlate;
  4285. $newentry->test = $param->test;
  4286. if (isset($param->special_param1))
  4287. $newentry->special_param1 = $param->special_param1;
  4288. else
  4289. $newentry->special_param1 = NULL;
  4290. $newentry->visible = $param->visible;
  4291. $newentry->max_experiment = $param->max_experiment;
  4292. $newentry->dependency = $param->dependency;
  4293. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4294. $newentry->show_answer = $param->show_answer;
  4295. if (!$DB->update_record("iassign_statement", $newentry))
  4296. print_error('error_update', 'iassign');
  4297. if ($param->type_iassign == 3) {
  4298. iassign::update_grade_iassign($param->iassignid);
  4299. }
  4300. //$id = $newentry->id; // MOOC 2016 --- inicio
  4301. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4302. //if ($iassign_activity_item_configs) {
  4303. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4304. // $newentry = new stdClass();
  4305. // $newentry->id = $iassign_activity_item_config->id;
  4306. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4307. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4308. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4309. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4310. // print_error('error_edit_param', 'iassign');
  4311. // }
  4312. // } // MOOC 2016 --- final
  4313. // log event --------------------------------------------------------------------------------------
  4314. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4315. // log event --------------------------------------------------------------------------------------
  4316. return $newentry->id;
  4317. // if ($param->type_iassign==3)
  4318. // $this->update_grade_iassign($param->iassignid);
  4319. } // function update_iassign($param)
  4320. /// Show information of activity
  4321. function show_info_iassign () {
  4322. global $DB, $OUTPUT;
  4323. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  4324. if ($this->activity->type_iassign == 3) {
  4325. if ($this->activity->dependency == 0) {
  4326. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  4327. } else {
  4328. $dependencys = explode(';', $this->activity->dependency);
  4329. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  4330. foreach ($dependencys as $dependency) {
  4331. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4332. if ($dependencyiassign)
  4333. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4334. } // foreach ($dependencys as $dependency)
  4335. } // if ($iassign_statement_activity_item->dependency == 0)
  4336. if ($this->activity->max_experiment == 0)
  4337. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4338. else
  4339. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4340. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4341. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4342. print $OUTPUT->box($output);
  4343. } // function show_info_iassign()
  4344. /// Shows date of opening and closing activities
  4345. function view_dates () {
  4346. global $USER, $CFG, $DB, $OUTPUT;
  4347. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4348. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4349. $status_iassign = "";
  4350. $status_iassign1 = "";
  4351. $status_iassign2 = "";
  4352. if ($this->activity->type_iassign == 1) // activity of type example
  4353. $type_iassign = get_string('example_iassign', 'iassign');
  4354. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4355. $type_iassign = get_string('test_iassign', 'iassign');
  4356. if ($this->activity->timeavailable > time()) {
  4357. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4358. } elseif ($this->activity->timedue < time()) {
  4359. $status_iassign = get_string('last_timedue', 'iassign');
  4360. }
  4361. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4362. $type_iassign = get_string('exercise_iassign', 'iassign');
  4363. if ($this->activity->timeavailable > time()) {
  4364. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4365. } elseif ($this->activity->timedue < time()) { // after delivery
  4366. $status_iassign = get_string('last_timedue', 'iassign');
  4367. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4368. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4369. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4370. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4371. if ($this->activity->test == 1) // allowed to test after of deadline
  4372. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4373. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4374. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4375. } // elseif ($iassign_statement_activity_item->test == 0)
  4376. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4377. } // elseif ($iassign_statement_activity_item->timedue < time())
  4378. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4379. $output = '<table width=100% >' . "\n";
  4380. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4381. $output .= '<tr>' . "\n";
  4382. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4383. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4384. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4385. // leo $output .= '<td width=80%>' . $type_iassign;
  4386. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4387. // $output .= '</td>' . "\n";
  4388. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4389. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4390. $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>";
  4391. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4392. } else {
  4393. $link_next = "";
  4394. $link_previous = "";
  4395. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4396. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4397. // previous_activity
  4398. if ($iassign_previous) {
  4399. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4400. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4401. } // next_activity
  4402. if ($iassign_next) {
  4403. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4404. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4405. }
  4406. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4407. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4408. $output .= '</tr></table>' . "\n";
  4409. $output .= '<table width=100% >' . "\n";
  4410. if ($this->activity->type_iassign > 1) {
  4411. if ($this->activity->timeavailable)
  4412. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4413. if ($this->activity->timedue)
  4414. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4415. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4416. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4417. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4418. $output .= '</table>' . "\n";
  4419. print $OUTPUT->box($output);
  4420. } // function view_dates()
  4421. } // class activity
  4422. /// Class to manage Interactive Learning Module (iLM)
  4423. class ilm {
  4424. var $ilm;
  4425. /// Constructor of class
  4426. // @param int $id Id of iLM
  4427. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4428. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4429. function __construct ($id) {
  4430. global $DB;
  4431. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4432. if (empty($this->ilm))
  4433. $this->ilm = null;
  4434. }
  4435. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4436. // @calledby view_iassign_current()
  4437. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4438. global $USER, $CFG, $DB;
  4439. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4440. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4441. $typec = strtolower($iassign_ilm->type);
  4442. require_once 'ilm_handlers/' . $typec . '.php';
  4443. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4444. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4445. return $retorno;
  4446. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4447. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4448. // @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);
  4449. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4450. // @param Object $file File in use in activity
  4451. // @return int Return the id of log
  4452. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4453. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4454. $newentry = new stdClass();
  4455. $newentry->iassign_statementid = $iassign_activity_itemid;
  4456. $newentry->userid = $USER->id;
  4457. $newentry->filesid = $content_or_id_from_ilm_security;
  4458. $newentry->timecreated = time();
  4459. $newentry->view = 1;
  4460. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4461. if (!$id_iLM_security) {
  4462. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4463. } // from (!$DB->insert_record("iassign_security", $newentry))
  4464. return $id_iLM_security;
  4465. }
  4466. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4467. // @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);
  4468. // @param int $userid
  4469. // @param int $iassign_activity_itemid Id of iassign statement
  4470. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4471. global $DB;
  4472. // 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")
  4473. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4474. }
  4475. } // class ilm
  4476. /// Class to manage settings of iLM.
  4477. class ilm_settings {
  4478. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4479. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4480. // @param int $ilm_id Id of iLM
  4481. // @param array $options An array with options for create dynamic tag html APPLET
  4482. // @return string Return with a tag html APPLET created
  4483. static function build_ilm_tags ($ilm_id, $options = array()) {
  4484. global $DB;
  4485. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4486. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4487. $typec = strtolower($iassign_ilm->type);
  4488. require_once 'ilm_handlers/' . $typec . '.php';
  4489. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4490. return $retorno;
  4491. } // static function build_ilm_tags($ilm_id, $options = array())
  4492. /// Function for get modified date of iLM file
  4493. // @param string $file_jar String with Ids of iLM files
  4494. // @return string Return with the filenames and modified date
  4495. static function applet_filetime ($file_jar) {
  4496. $filetime = "";
  4497. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4498. $files_jar = explode(",", $file_jar);
  4499. foreach ($files_jar as $one_file) {
  4500. $file = $fs->get_file_by_id($one_file);
  4501. if ($file)
  4502. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4503. }
  4504. return $filetime;
  4505. }
  4506. /// Function for verify an default applet
  4507. // @param String $file_jar String containing an list de ids of applet files
  4508. // @return boolean Return true or fale if applet is default
  4509. static function applet_default ($file_jar) {
  4510. $is_default = true;
  4511. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4512. $files_jar = explode(",", $file_jar);
  4513. foreach ($files_jar as $one_file) {
  4514. $file = $fs->get_file_by_id($one_file);
  4515. if ($file)
  4516. $is_default &= ($file->get_itemid() == 0);
  4517. }
  4518. return $is_default;
  4519. }
  4520. /// Function for get form variables for add, edit, or copy iLM
  4521. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4522. // @see settings_form.php
  4523. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4524. // @param int $ilm_id Id of iLM
  4525. // @param string $action String with the action
  4526. // @return object Return an object with forms variables
  4527. static function add_edit_copy_ilm ($ilm_id, $action) {
  4528. global $USER, $DB, $CFG;
  4529. require_once('settings_form.php'); // put the form
  4530. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4531. $param = new stdClass();
  4532. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  4533. $param->action = $action;
  4534. $param->ilm_id = $ilm_id;
  4535. $CFG->action_ilm = $action;
  4536. $CFG->ilm_id = $ilm_id;
  4537. if ($action == 'add') {
  4538. $param->title = get_string('add_ilm', 'iassign');
  4539. $param->name = "";
  4540. $param->version = "";
  4541. $param->url = "";
  4542. $param->description = "";
  4543. $param->extension = "";
  4544. $param->author = $USER->id;
  4545. $param->file_jar = "";
  4546. $param->file_jar_static = "";
  4547. $param->file_class = "";
  4548. $param->width = 800;
  4549. $param->height = 600;
  4550. $param->enable = 0; // 0 - hide / 1 - show
  4551. $param->timecreated = time();
  4552. $param->timemodified = time();
  4553. $param->evaluate = 0;
  4554. $param->parent = 0;
  4555. }
  4556. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4557. if ($iassign_ilm) {
  4558. $description = json_decode($iassign_ilm->description);
  4559. $param->title = get_string('edit_ilm', 'iassign');
  4560. $param->id = $iassign_ilm->id;
  4561. $param->name_ilm = $iassign_ilm->name;
  4562. $param->name = $iassign_ilm->name;
  4563. $param->version = $iassign_ilm->version;
  4564. $param->ilm_type = $iassign_ilm->type;
  4565. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4566. $param->url = $iassign_ilm->url; // iLM official URL
  4567. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  4568. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4569. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4570. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4571. if (!isset($description->{current_language()})) {
  4572. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4573. else
  4574. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4575. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4576. }
  4577. else
  4578. $param->description = $description->{current_language()};
  4579. $param->description_lang = $iassign_ilm->description;
  4580. $param->extension = $iassign_ilm->extension;
  4581. $param->author = $iassign_ilm->author;
  4582. $param->file_jar = $iassign_ilm->file_jar;
  4583. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4584. $param->file_class = $iassign_ilm->file_class;
  4585. $param->width = $iassign_ilm->width;
  4586. $param->height = $iassign_ilm->height;
  4587. $param->enable = $iassign_ilm->enable;
  4588. $param->timecreated = $iassign_ilm->timecreated;
  4589. $param->timemodified = time();
  4590. $param->evaluate = $iassign_ilm->evaluate;
  4591. $param->parent = $iassign_ilm->parent;
  4592. }
  4593. }
  4594. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4595. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4596. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4597. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4598. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4599. // echo "Sem dados<br/>"; exit;
  4600. return;
  4601. }
  4602. $description = json_decode($iassign_ilm->description);
  4603. if ($iassign_ilm) {
  4604. if ($iassign_ilm->parent == 0)
  4605. $iassign_ilm->parent = $ilm_id;
  4606. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4607. $param->title = get_string('new_version_ilm', 'iassign');
  4608. $param->name_ilm = $iassign_ilm->name;
  4609. $param->name = $iassign_ilm->name;
  4610. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4611. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4612. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4613. $param->ilm_type = $iassign_ilm->type;
  4614. $param->url = $iassign_ilm->url;
  4615. $param->description = $description->{current_language()};
  4616. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4617. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4618. $param->extension = $iassign_ilm->extension;
  4619. $param->author = $USER->id;
  4620. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4621. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4622. $param->file_jar_static = '';
  4623. $param->file_class = $iassign_ilm->file_class;
  4624. $param->width = $iassign_ilm->width;
  4625. $param->height = $iassign_ilm->height;
  4626. $param->enable = 0;
  4627. $param->timecreated = time();
  4628. $param->timemodified = time();
  4629. $param->evaluate = $iassign_ilm->evaluate;
  4630. $param->parent = $iassign_ilm->parent;
  4631. }
  4632. }
  4633. elseif ($action == 'copy') {
  4634. $description = json_decode($iassign_ilm->description);
  4635. if ($iassign_ilm) {
  4636. if ($iassign_ilm->parent == 0)
  4637. $iassign_ilm->parent = $ilm_id;
  4638. $param->title = get_string('copy_ilm', 'iassign');
  4639. $param->id = $iassign_ilm->id;
  4640. $param->name_ilm = $iassign_ilm->name;
  4641. $param->name = $iassign_ilm->name;
  4642. $param->version = "";
  4643. $param->ilm_type = $iassign_ilm->type;
  4644. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4645. $param->url = $iassign_ilm->url;
  4646. $param->description = $description->{current_language()};
  4647. $param->description_lang = $iassign_ilm->description;
  4648. $param->extension = $iassign_ilm->extension;
  4649. $param->author = $USER->id;
  4650. $param->file_jar = '';
  4651. $param->file_jar_static = '';
  4652. $param->file_class = $iassign_ilm->file_class;
  4653. $param->width = $iassign_ilm->width;
  4654. $param->height = $iassign_ilm->height;
  4655. $param->enable = 0;
  4656. $param->timecreated = time();
  4657. $param->timemodified = time();
  4658. $param->evaluate = $iassign_ilm->evaluate;
  4659. $param->parent = $iassign_ilm->parent;
  4660. }
  4661. }
  4662. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  4663. //D var_dump(debug_backtrace());
  4664. //D print_r(debug_backtrace());
  4665. return $param;
  4666. } // static function add_edit_copy_ilm($ilm_id, $action)
  4667. /// Function for save iLM file in moodledata
  4668. // @param int $itemid Itemid of file save in draft (upload file)
  4669. // @param int $ilm_id Id of iLM
  4670. // @return string Return an string with ids of iLM files
  4671. static function new_file_ilm ($itemid, $iassign_ilm) {
  4672. global $CFG, $USER, $DB;
  4673. $return = null;
  4674. $file_jar = array();
  4675. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4676. $contextuser = context_user::instance($USER->id);
  4677. $contextsystem = context_system::instance();
  4678. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4679. if ($files_ilm) {
  4680. foreach ($files_ilm as $value) {
  4681. // CHECK IF file is HTML type
  4682. if ($iassign_ilm->type == 1) {
  4683. // Check if the file extension is ZIP
  4684. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4685. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4686. if ((strtolower($ext) == 'zip')) {
  4687. // Coping...:
  4688. $destination = 'ilm_debug/' . $value->get_filename();
  4689. $value->copy_content_to($destination);
  4690. // Extracting content...:
  4691. $zip = new ZipArchive();
  4692. $extracted = './ilm';
  4693. $dir = "";
  4694. if ($zip->open($destination) === TRUE) {
  4695. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4696. if (is_dir($dir)) {
  4697. $i = 1;
  4698. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4699. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4700. $i ++;
  4701. }
  4702. $name = $previous . "_" . $i;
  4703. $dir = './ilm/' . $name . "/";
  4704. $j = 0;
  4705. while ($item_name = $zip->getNameIndex($j)) {
  4706. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4707. $j++;
  4708. }
  4709. $zip->close();
  4710. }
  4711. $zip->open($destination);
  4712. $zip->extractTo($extracted);
  4713. $zip->close();
  4714. // After the extraction, remove it from DEBUG
  4715. unlink($destination);
  4716. } else { // Error trying to open destination...
  4717. // After the extraction error, also remove it from DEBUG
  4718. unlink($destination);
  4719. print_error('error_add_ilm_zip', 'iassign');
  4720. }
  4721. return $dir;
  4722. }
  4723. } // if ($iassign_ilm->type == 1)
  4724. if ($value->get_filename() != '.') {
  4725. $file_ilm = array(
  4726. 'userid' => $USER->id,
  4727. 'contextid' => $contextsystem->id,
  4728. 'component' => 'mod_iassign',
  4729. 'filearea' => 'ilm',
  4730. 'itemid' => rand(1, 999999999),
  4731. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4732. 'filename' => $value->get_filename());
  4733. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4734. array_push($file_jar, $file_ilm->get_id());
  4735. }
  4736. }
  4737. if (!empty($file_jar)) {
  4738. $return = implode(",", $file_jar);
  4739. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4740. foreach ($old_file_jar as $value) {
  4741. $file = $fs->get_file_by_id($value);
  4742. if ($file)
  4743. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4744. }
  4745. }
  4746. }
  4747. else // if ($files_ilm)
  4748. $return = $iassign_ilm->file_jar;
  4749. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4750. return $return;
  4751. } // static function new_file_ilm($itemid, $iassign_ilm)
  4752. /// Function for save in database an new iLM
  4753. // @param object $param An object with iLM params
  4754. static function new_ilm ($itemid) {
  4755. global $CFG, $USER, $OUTPUT;
  4756. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4757. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4758. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4759. }
  4760. $pathtemp = $CFG->dataroot . '/temp/';
  4761. $contextuser = context_user::instance($USER->id);
  4762. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4763. $zip = new zip_packer();
  4764. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4765. foreach ($files as $file) {
  4766. if (!$file->is_directory())
  4767. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4768. }
  4769. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4770. // Verifica se o pacote possui o XML
  4771. if (!$application_xml) {
  4772. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4773. return;
  4774. } else {
  4775. $missing = "";
  4776. if (!isset($application_xml->name)) {
  4777. $missing .= "name";
  4778. }
  4779. if (!isset($application_xml->version)) {
  4780. $missing .= ", version";
  4781. }
  4782. if (!isset($application_xml->type)) {
  4783. $missing .= ", type";
  4784. }
  4785. if (!isset($application_xml->extension)) {
  4786. $missing .= ", extension";
  4787. }
  4788. if (!isset($application_xml->file_jar)) {
  4789. $missing .= ", file_jar";
  4790. }
  4791. if (!isset($application_xml->file_class)) {
  4792. $missing .= ", file_class";
  4793. }
  4794. if (!isset($application_xml->width)) {
  4795. $missing .= ", width";
  4796. }
  4797. if (!isset($application_xml->height)) {
  4798. $missing .= ", height";
  4799. }
  4800. if (!isset($application_xml->evaluate)) {
  4801. $missing .= ", evaluate";
  4802. }
  4803. if (strlen($missing) > 2) {
  4804. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4805. return;
  4806. }
  4807. }
  4808. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4809. $typec = strtolower($application_xml->type);
  4810. require_once 'ilm_handlers/' . $typec . '.php';
  4811. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4812. return $retorno;
  4813. } // static function new_ilm($itemid)
  4814. /// Function for save in database an iLM edit
  4815. // @param object $param An object with iLM params
  4816. static function edit_ilm ($param, $itemid) {
  4817. // Descobrir o tipo de iLM:
  4818. global $DB, $USER, $CFG;
  4819. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4820. $pathtemp = $CFG->dataroot . '/temp/';
  4821. $contextuser = context_user::instance($USER->id);
  4822. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4823. $zip = new zip_packer();
  4824. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4825. $files_extract = null;
  4826. foreach ($files as $file) {
  4827. if (!$file->is_directory())
  4828. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4829. }
  4830. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4831. $typec = strtolower($iassign_t->type);
  4832. require_once 'ilm_handlers/' . $typec . '.php';
  4833. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4834. }
  4835. /// Function for register the new iLM (in database and in the directory)
  4836. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4837. // @param object $param An object with iLM params
  4838. static function copy_new_version_ilm ($param) {
  4839. global $DB, $CFG, $USER;
  4840. $itemid = $param->file;
  4841. $pathtemp = $CFG->dataroot . '/temp/';
  4842. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4843. //D echo "pathtemp=$pathtemp<br/>";
  4844. $contextuser = context_user::instance($USER->id);
  4845. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4846. $zip = new zip_packer();
  4847. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4848. $files_extract = null;
  4849. foreach ($files as $file) {
  4850. if (!$file->is_directory())
  4851. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4852. }
  4853. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4854. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4855. $typec = strtolower($iassign_t->type);
  4856. require_once 'ilm_handlers/' . $typec . '.php';
  4857. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4858. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4859. } // static function copy_new_version_ilm($param)
  4860. //VER::
  4861. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4862. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4863. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4864. /// Function for change visibility of iLM
  4865. // @param int $ilm_id Id of iLM
  4866. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4867. static function visible_ilm ($ilm_id, $status) {
  4868. global $DB;
  4869. if ($status == 0)
  4870. $visible = 1;
  4871. else
  4872. $visible = 0;
  4873. $newentry = new stdClass();
  4874. $newentry->id = $ilm_id;
  4875. $newentry->enable = $visible;
  4876. if (!$DB->update_record("iassign_ilm", $newentry))
  4877. error(get_string('error_edit_ilm', 'iassign'));
  4878. }
  4879. /// Function for confirm change default iLM
  4880. // @param int $ilm_id Id of iLM
  4881. // @param int $ilm_parent Id of parent iLM
  4882. // @return string Return with an string for create default page confirmation
  4883. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4884. global $OUTPUT, $DB;
  4885. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4886. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4887. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4888. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4889. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4890. return $return;
  4891. }
  4892. /// Function for change the default iLM
  4893. // @see settings_ilm.php
  4894. // @param int $ilm_id Id of iLM
  4895. // @return int Return Id of default iLM
  4896. static function default_ilm ($ilm_id) {
  4897. global $DB;
  4898. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4899. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4900. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4901. $iassign_ilm_default->id = $iassign_ilm->id;
  4902. $iassign_ilm_default->parent = 0;
  4903. $iassign_ilm->parent = $iassign_ilm_default->id;
  4904. $iassign_ilm->id = 0;
  4905. $iassign_ilm_default->enable = 1;
  4906. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4907. print_error('error_edit_ilm', 'iassign');
  4908. }
  4909. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4910. if (!$inserted) {
  4911. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4912. print_error($msg_error);
  4913. //xx print_error('error_add_ilm', 'iassign');
  4914. }
  4915. return $iassign_ilm_default->id;
  4916. } // static function default_ilm ($ilm_id)
  4917. /// Function for confirm delete iLM
  4918. // @param int $ilm_id Id of iLM
  4919. // @param int $ilm_parent Id of parent iLM
  4920. // @return string Return with an string for create delete page confirmation
  4921. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4922. global $OUTPUT, $DB;
  4923. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4924. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4925. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4926. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4927. }
  4928. /// Function for delete directory where the iLM is allocated.
  4929. // @param string $dirPath
  4930. // @throws InvalidArgumentException
  4931. public static function delete_dir ($dirPath) {
  4932. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4933. $dirPath .= '/';
  4934. }
  4935. $files = glob($dirPath . '*', GLOB_MARK);
  4936. foreach ($files as $file) {
  4937. if (is_dir($file)) {
  4938. ilm_settings::delete_dir($file);
  4939. } else {
  4940. unlink($file);
  4941. }
  4942. }
  4943. rmdir($dirPath);
  4944. }
  4945. /// Function for delete iLM
  4946. // @param int $ilm_id Id of iLM
  4947. // @return int Return Id of parent iLM
  4948. static function delete_ilm ($ilm_id) {
  4949. global $DB;
  4950. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4951. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4952. $typec = strtolower($iassign_ilm->type);
  4953. require_once 'ilm_handlers/' . $typec . '.php';
  4954. $retorno = $typec::delete_ilm($ilm_id);
  4955. return $retorno;
  4956. }
  4957. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4958. // @param int $ilm_id Id of iLM
  4959. static function export_ilm ($ilm_id) {
  4960. global $DB;
  4961. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4962. if (!$iassign_ilm) return; // security debug...
  4963. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4964. $typec = strtolower($iassign_ilm->type);
  4965. if (!$typec) $typec = "html5"; // security debug...
  4966. require_once 'ilm_handlers/' . $typec . '.php';
  4967. $typec::export_ilm($ilm_id);
  4968. } // static function export_ilm($ilm_id)
  4969. //TODO iLM_HTML5 :: //MOOC 2016
  4970. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4971. // @param int $ilm_id Id of iLM
  4972. static function export_update_ilm ($ilm_id) {
  4973. global $DB, $CFG;
  4974. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4975. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4976. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4977. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4978. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4979. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4980. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4981. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4982. $upgrade_descriptor .= '</upgrade>' . "\n";
  4983. file_put_contents($xml_filename, $upgrade_descriptor);
  4984. header("Pragma: public");
  4985. header("Expires: 0");
  4986. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4987. header("Cache-Control: private", false);
  4988. header('Content-Type: application/xml; charset=utf-8');
  4989. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4990. header("Content-Length: " . @filesize($xml_filename));
  4991. set_time_limit(0);
  4992. @readfile("$xml_filename") || die("File not found.");
  4993. unlink($xml_filename);
  4994. exit;
  4995. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4996. /// Function for save iLM from XML descriptor
  4997. // @param array $application_xml Data of XML descriptor
  4998. // @param array $files_extract Filenames of extract files
  4999. // @return array Return an array content id of JAR files
  5000. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5001. global $CFG, $USER;
  5002. // Tratamento diferenciado se for do tipo HTML5:
  5003. $source = "";
  5004. $diretorio = "";
  5005. if (strtolower($application_xml->type) == 'html5') {
  5006. $i = 0;
  5007. foreach ($files_extract as $key => $value) {
  5008. $file = $CFG->dataroot . '/temp/' . $key;
  5009. // Verifica se já existe a pasta no diretório dos iLM:
  5010. if ($i == 0) {
  5011. $source = $file;
  5012. if (file_exists("ilm/" . basename($file))) {
  5013. $j = 1;
  5014. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5015. $j ++;
  5016. }
  5017. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5018. // mkdir($diretorio, 0777, true);
  5019. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5020. }
  5021. else {
  5022. $diretorio = 'ilm/' . basename($file);
  5023. // mkdir($diretorio, 0777, true);
  5024. mkdir($diretorio, 0755, true);
  5025. }
  5026. break;
  5027. }
  5028. $i ++;
  5029. }
  5030. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5031. if ($item->isDir()) {
  5032. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5033. }
  5034. else {
  5035. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5036. }
  5037. }
  5038. ilm_settings::delete_dir($source);
  5039. return "./" . $diretorio;
  5040. }
  5041. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5042. $file_jar = array();
  5043. $files_ilm = explode(",", $application_xml->file_jar);
  5044. $contextsystem = context_system::instance();
  5045. foreach ($files_ilm as $value) {
  5046. $file_ilm = array(
  5047. 'userid' => $USER->id,
  5048. 'contextid' => $contextsystem->id,
  5049. 'component' => 'mod_iassign',
  5050. 'filearea' => 'ilm',
  5051. 'itemid' => rand(1, 999999999),
  5052. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5053. 'filename' => $value);
  5054. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5055. array_push($file_jar, $file_ilm->get_id());
  5056. }
  5057. foreach ($files_extract as $key => $value) {
  5058. $file = $CFG->dataroot . '/temp/' . $key;
  5059. if (file_exists($file))
  5060. unlink($file);
  5061. }
  5062. return $file_jar;
  5063. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5064. /// Function for import the iLM from an package
  5065. // @param int $itemid Itemid of zip file
  5066. static function import_ilm ($itemid) {
  5067. global $CFG, $USER, $OUTPUT;
  5068. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5069. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5070. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5071. }
  5072. $pathtemp = $CFG->dataroot . '/temp/';
  5073. $contextuser = context_user::instance($USER->id);
  5074. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5075. $zip = new zip_packer();
  5076. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5077. foreach ($files as $file) {
  5078. if (!$file->is_directory())
  5079. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5080. }
  5081. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5082. // Verifica se o pacote possui o XML
  5083. if (!$application_xml) {
  5084. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5085. return;
  5086. } else {
  5087. $missing = "";
  5088. if (!isset($application_xml->name)) {
  5089. $missing .= "name";
  5090. }
  5091. if (!isset($application_xml->version)) {
  5092. $missing .= ", version";
  5093. }
  5094. if (!isset($application_xml->type)) {
  5095. $missing .= ", type";
  5096. }
  5097. if (!isset($application_xml->extension)) {
  5098. $missing .= ", extension";
  5099. }
  5100. if (!isset($application_xml->file_jar)) {
  5101. $missing .= ", file_jar";
  5102. }
  5103. if (!isset($application_xml->file_class)) {
  5104. $missing .= ", file_class";
  5105. }
  5106. if (!isset($application_xml->width)) {
  5107. $missing .= ", width";
  5108. }
  5109. if (!isset($application_xml->height)) {
  5110. $missing .= ", height";
  5111. }
  5112. if (!isset($application_xml->evaluate)) {
  5113. $missing .= ", evaluate";
  5114. }
  5115. if (strlen($missing) > 2) {
  5116. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5117. return;
  5118. }
  5119. }
  5120. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5121. $typec = strtolower($application_xml->type);
  5122. require_once 'ilm_handlers/' . $typec . '.php';
  5123. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5124. } // static function import_ilm($itemid)
  5125. /// Function for list iLM defaults
  5126. // @return string Return an string with a table of iLM
  5127. static function list_ilm () {
  5128. global $DB, $OUTPUT;
  5129. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5130. $str = '';
  5131. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5132. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5133. if ($iassign_ilm) {
  5134. foreach ($iassign_ilm as $ilm) {
  5135. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5136. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5137. $str .= '<tr><td>';
  5138. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5139. $str .= '<tr>';
  5140. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5141. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5142. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5143. $str .= '</tr>';
  5144. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5145. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5146. $str .= '</table>';
  5147. $str .= '</td></tr>';
  5148. }
  5149. }
  5150. $str .= '</table>';
  5151. return $str;
  5152. }
  5153. /// Function for download and install an upgrade of an iLM
  5154. // @param int $ilm_id Id of iLM
  5155. static function upgrade_ilm ($ilm_id) {
  5156. global $DB, $CFG, $USER;
  5157. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5158. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5159. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5160. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5161. if (!$result)
  5162. print_error('error_upgrade_ilm', 'iassign');
  5163. else {
  5164. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5165. $extension = explode(".", $zip_filename);
  5166. if ($extension[count($extension) - 1] != 'ipz') {
  5167. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5168. die;
  5169. }
  5170. $zip = new zip_packer();
  5171. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5172. $contextuser = context_user::instance($USER->id);
  5173. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5174. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5175. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5176. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5177. if (file_exists($zip_filename))
  5178. unlink($zip_filename);
  5179. if (empty($file_jar)) {
  5180. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5181. print_error($msg_error);
  5182. //xx print_error('error_add_ilm', 'iassign');
  5183. }
  5184. else {
  5185. $newentry = new stdClass();
  5186. $newentry->name = (String) $application_xml->name;
  5187. $newentry->version = (String) $application_xml->version;
  5188. $newentry->url = (String) $application_xml->url;
  5189. $newentry->description = $description_str;
  5190. $newentry->extension = strtolower((String) $application_xml->extension);
  5191. $newentry->file_jar = implode(",", $file_jar);
  5192. $newentry->file_class = (String) $application_xml->file_class;
  5193. $newentry->width = (String) $application_xml->width;
  5194. $newentry->height = (String) $application_xml->height;
  5195. $newentry->enable = 0;
  5196. $newentry->timemodified = time();
  5197. $newentry->author = $USER->id;
  5198. $newentry->timecreated = time();
  5199. $newentry->evaluate = (String) $application_xml->evaluate;
  5200. $newentry->parent = $ilm_id;
  5201. }
  5202. }
  5203. return $iassign_ilm->id;
  5204. } // static function upgrade_ilm($ilm_id)
  5205. //MOOC2014 -- inicio
  5206. //TODO: REVIEW
  5207. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5208. // static function move_iassign($ilm_id)
  5209. //MOOC2014 -- final
  5210. /// Function for list iLM versions with all informations
  5211. // @return string Return an string with a table of iLM
  5212. static function view_ilm ($ilmid, $from) {
  5213. global $DB;
  5214. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5215. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5216. $typec = strtolower($iassign_ilm->type);
  5217. require_once 'ilm_handlers/' . $typec . '.php';
  5218. $retorno = $typec::view_ilm($ilmid, $from);
  5219. return $retorno;
  5220. }
  5221. /// Function for get form variables for add, edit, or copy iLM params
  5222. // @param int $ilm_param_id Id of iLM param
  5223. // @param string $action String with the action
  5224. // @return object Return an object with forms variables
  5225. static function add_edit_copy_param ($ilm_param_id, $action) {
  5226. global $DB;
  5227. require_once('params_form.php');
  5228. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5229. $param = new stdClass();
  5230. $param->action = $action;
  5231. $param->ilm_param_id = $ilm_param_id;
  5232. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5233. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5234. $type = $iassign_ilm_config->param_type;
  5235. if ($action == 'add') {
  5236. $param->title = get_string('add_ilm', 'iassign');
  5237. $param->iassign_ilmid = $ilm_param_id;
  5238. $param->param_name = "";
  5239. $param->param_value = "";
  5240. $param->description = "";
  5241. $param->visible = 1;
  5242. }
  5243. elseif ($action == 'edit') {
  5244. if ($iassign_ilm_config) {
  5245. $param->title = get_string('edit_ilm', 'iassign');
  5246. $param->id = $iassign_ilm_config->id;
  5247. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5248. $param->param_type = $type; //MOOC2014
  5249. $param->param_name = $iassign_ilm_config->param_name;
  5250. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5251. $param->param_value = $iassign_ilm_config->param_value;
  5252. else //MOOC2014
  5253. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5254. $param->param_value = $iassign_ilm_config->param_value;
  5255. $param->description = $iassign_ilm_config->description;
  5256. $param->visible = $iassign_ilm_config->visible;
  5257. }
  5258. }
  5259. elseif ($action == 'copy') {
  5260. if ($iassign_ilm_config) {
  5261. $param->title = get_string('copy_ilm', 'iassign');
  5262. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5263. $param->param_type = $type; //MOOC2014
  5264. $param->param_name = $iassign_ilm_config->param_name;
  5265. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5266. $param->param_value = $iassign_ilm_config->param_value;
  5267. else //MOOC2014
  5268. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5269. $param->description = $iassign_ilm_config->description;
  5270. $param->visible = $iassign_ilm_config->visible;
  5271. }
  5272. }
  5273. return $param;
  5274. } // static function add_edit_copy_param($ilm_param_id, $action)
  5275. /// Function for change visibility of iLM param
  5276. // @param int $ilm_param_id Id of iLM param
  5277. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5278. static function visible_param ($ilm_param_id, $status) {
  5279. global $DB, $CFG;
  5280. if ($status == 0)
  5281. $visible = 1;
  5282. else
  5283. $visible = 0;
  5284. $newentry = new stdClass();
  5285. $newentry->id = $ilm_param_id;
  5286. $newentry->visible = $visible;
  5287. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5288. error(get_string('error_edit_param', 'iassign'));
  5289. }
  5290. /// Function for save in database an new iLM param
  5291. // @param object $param An object with iLM params
  5292. static function add_param ($param) {
  5293. global $DB;
  5294. $newentry = new stdClass();
  5295. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5296. //MOOC2014 $newentry->param_name = $param->param_name;
  5297. $newentry->param_type = $param->param_type; //MOOC2014
  5298. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5299. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5300. $newentry->param_value = $param->param_value;
  5301. else //MOOC2014
  5302. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5303. $newentry->description = $param->description;
  5304. $newentry->visible = $param->visible;
  5305. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5306. if (!$newentry->id) {
  5307. print_error('error_add_param', 'iassign');
  5308. }
  5309. }
  5310. /// Function for save in database a iLM param edit
  5311. // @param object $param An object with iLM params
  5312. static function edit_param ($param) {
  5313. global $DB;
  5314. $updentry = new stdClass();
  5315. $updentry->id = $param->id;
  5316. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5317. $updentry->param_type = $param->param_type; //MOOC2014
  5318. // $updentry->param_name = $param->param_name;
  5319. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5320. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5321. $updentry->param_value = $param->param_value;
  5322. else //MOOC2014
  5323. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5324. $updentry->description = $param->description;
  5325. $updentry->visible = $param->visible;
  5326. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5327. error(get_string('error_edit_param', 'iassign'));
  5328. }
  5329. }
  5330. /// Function for save in database a iLM param copy
  5331. // @param object $param An object with iLM params
  5332. static function copy_param ($param) {
  5333. global $DB;
  5334. $newentry = new stdClass();
  5335. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5336. //$newentry->param_name = $param->param_name;
  5337. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5338. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5339. $newentry->param_value = $param->param_value;
  5340. else //MOOC2014
  5341. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5342. $newentry->description = $param->description;
  5343. $newentry->visible = $param->visible;
  5344. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5345. if (!$newentry->id) {
  5346. print_error('error_add_param', 'iassign');
  5347. }
  5348. }
  5349. /// Function for delete iLM param of database
  5350. // @param int $param_id Id of iLM param
  5351. static function delete_param ($param_id) {
  5352. global $DB;
  5353. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5354. print_error('error_delete_param', 'iassign');
  5355. }
  5356. }
  5357. } // class ilm_settings
  5358. /// Class for manage iLM files (editor).
  5359. class ilm_manager {
  5360. var $id; // course id
  5361. var $url;
  5362. var $from;
  5363. /// Constructor for the base ilm_manager class
  5364. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5365. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5366. function __construct ($id, $url, $from) {
  5367. $this->id = $id; // course id
  5368. $this->url = $url;
  5369. $this->from = $from;
  5370. }
  5371. /// Function to get iAssign content file in Moodle data (exercise)
  5372. // @calledby x function preview_ilm($iassign_ilm) :
  5373. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5374. function get_file_ilm () {
  5375. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5376. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5377. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5378. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5379. $md_file = $fs->get_file_by_id($fileid);
  5380. $ilm_content_file = $md_file->get_content();
  5381. return $ilm_content_file;
  5382. }
  5383. /// Function for creating a new file from the iLM online editor
  5384. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5385. function ilm_editor_new () {
  5386. global $CFG, $DB, $OUTPUT, $PAGE;
  5387. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5388. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5389. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5390. $context = context_course::instance($this->id);
  5391. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5392. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5393. if (!$iassign) {
  5394. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5395. die();
  5396. }
  5397. $temp = explode(",", $iassign->extension);
  5398. $extension = $temp[0]; // default extension for this iLM
  5399. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5400. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5401. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5402. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5403. if ($stringArchiveContent != NULL) {
  5404. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5405. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5406. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5407. $filename = optional_param('filename', NULL, PARAM_RAW);
  5408. //Leo $filename = iassign_utils::format_filename($filename); //
  5409. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5410. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5411. //2019/02 $arrayfilename = explode(".", $filename);
  5412. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5413. //2019/02 $count_dots = count($arrayfilename);
  5414. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5415. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5416. //2019/02 if ($last_name != $extension)
  5417. //2019/02 $filename = $filename . '.' . $extension;
  5418. //2019/02 }
  5419. //2019/02 else { // no extension...
  5420. //2019/02 $filename = $filename . '.' . $extension;
  5421. //2019/02 }
  5422. // Store the name of recent created file
  5423. $_SESSION['file_name'] = $filename;
  5424. //$this->write_file_iassign($string, $filename);
  5425. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5426. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5427. die();
  5428. }
  5429. else { // if ($stringArchiveContent != NULL)
  5430. // iLM On-line editor
  5431. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5432. $str_get_iLM = "window.frames.iLM";
  5433. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5434. }
  5435. else { // otherwise it is JAR named 'iLM'
  5436. $str_get_iLM = "document.iLM";
  5437. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5438. }
  5439. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5440. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5441. $files_array = '';
  5442. foreach ($files as $value) {
  5443. if ($value->get_filename() != ".")
  5444. $files_array .= "'" . $value->get_filename() . "',";
  5445. }
  5446. $files_array .= "''";
  5447. $file = null;
  5448. $ia_content = "";
  5449. $filename = "";
  5450. $error_files_exists = get_string('error_file_exists', 'iassign');
  5451. $output = "<script type='text/javascript'>
  5452. //<![CDATA[
  5453. //D alert('locallib.php: ilm_editor_new');
  5454. function submit_iLM_Answer () {
  5455. var docFormOnLineEditor = document.formEnvio;
  5456. var resposta_exerc = new Array(3);
  5457. var valor_resposta = new Array(3);
  5458. var sessao = new Array(3);
  5459. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5460. resposta_exerc[0] = doc_iLM.getAnswer();
  5461. valor_resposta[0] = doc_iLM.getEvaluation();
  5462. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5463. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5464. var files = new Array(" . $files_array . ");
  5465. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5466. if (docFormOnLineEditor.filename.value=='') {
  5467. // ERROR: the file name is empty
  5468. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5469. return false;
  5470. }
  5471. // }
  5472. for (i=0; i<files.length; i++) {
  5473. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5474. alert('" . $error_files_exists . "');
  5475. return false;
  5476. }
  5477. }
  5478. docFormOnLineEditor.submit();
  5479. return true;
  5480. }
  5481. //]]>
  5482. </script>\n";
  5483. $output .= "
  5484. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5485. $output .= $OUTPUT->box_start();
  5486. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5487. $output .= "
  5488. <table width='100%' cellpadding='20'>
  5489. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5490. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5491. </tr>
  5492. </table>\n";
  5493. $output .= $OUTPUT->box_end();
  5494. $output .= "<center>\n";
  5495. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5496. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5497. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5498. $output .= $output_ilm;
  5499. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5500. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5501. </center>
  5502. </form>\n";
  5503. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5504. $PAGE->navbar->add($title);
  5505. $PAGE->set_title($title);
  5506. $PAGE->set_heading($title); // insert title above the navigation bar
  5507. print $OUTPUT->header();
  5508. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5509. print $output;
  5510. print $OUTPUT->footer();
  5511. }
  5512. die();
  5513. } // function ilm_editor_new()
  5514. /// Function for editing an file in online editor
  5515. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5516. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5517. global $CFG, $DB, $OUTPUT, $PAGE;
  5518. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5519. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5520. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5521. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5522. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5523. // If iLM is not registered, error!
  5524. if (!$iassign) {
  5525. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5526. die;
  5527. }
  5528. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5529. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5530. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5531. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5532. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5533. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5534. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5535. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5536. if ($stringArchiveContent != NULL) {
  5537. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5538. die();
  5539. } else { // if ($stringArchiveContent != NULL)
  5540. $end_file = '';
  5541. if ($content_file) {
  5542. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5543. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5544. }
  5545. $temp = explode(",", $iassign->extension);
  5546. $extension = $temp[0]; // default extension for this iLM
  5547. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5548. $str_get_iLM = "window.frames.iLM";
  5549. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5550. } else { // otherwise it is JAR named 'iLM'
  5551. $str_get_iLM = "document.iLM";
  5552. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5553. }
  5554. $output = "<script type='text/javascript'>
  5555. //<![CDATA[
  5556. function submit_iLM_Answer () {
  5557. var docFormEditor = document.formEnvio;
  5558. var activityAnswer; // to get activity answer (text)
  5559. var activityValue; // to get activity answer value (float)
  5560. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5561. //activityAnswer = doc_iLM.getAnswer();
  5562. //activityValue = doc_iLM.getEvaluation();
  5563. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5564. activityValue = " . $str_get_iLM . ".getEvaluation();
  5565. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5566. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5567. docFormEditor.submit();
  5568. return true;
  5569. }
  5570. //]]>
  5571. </script>\n";
  5572. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5573. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5574. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5575. // return true;
  5576. // }
  5577. $output .= "
  5578. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5579. $output .= $OUTPUT->box_start();
  5580. $output .= "
  5581. <table width='100%' cellpadding='20'>
  5582. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5583. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5584. <input type='hidden' name='filename' value='$filename'/></td>
  5585. <td>
  5586. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5587. </tr>
  5588. </table>\n";
  5589. $output .= $OUTPUT->box_end();
  5590. $output .= " <center>\n";
  5591. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5592. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5593. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5594. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5595. </center>
  5596. </form>\n";
  5597. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5598. $PAGE->navbar->add($title);
  5599. $PAGE->set_title($title);
  5600. $PAGE->set_heading($title); // insert title above the navigation bar
  5601. print $OUTPUT->header();
  5602. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5603. print $output;
  5604. print $OUTPUT->footer();
  5605. } // else if ($stringArchiveContent != NULL)
  5606. die();
  5607. } // function ilm_editor_update()
  5608. /// Function for write iAssign file in Moodle data (exercise)
  5609. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5610. // @param string $stringArchiveContent Content of iassign file
  5611. // @param string $filename Filename of iassign file
  5612. function write_file_iassign ($stringArchiveContent, $filename) {
  5613. global $USER;
  5614. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5615. $context = context_course::instance($this->id);
  5616. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5617. $dirid = $this->get_dir_ilm('dirid');
  5618. $dir = $fs->get_file_by_id($dirid);
  5619. $fileinfo = array('contextid' => $context->id, // ID of course
  5620. 'component' => 'mod_iassign', // usually = table name
  5621. 'filearea' => 'activity', // usually = table name
  5622. 'itemid' => 0, // usually = ID of row in table
  5623. 'filepath' => '/', // any path beginning and ending whith '/'
  5624. 'userid' => $USER->id,
  5625. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5626. 'filename' => $filename); // any filename
  5627. // Create file containing text. '$stringArchiveContent'
  5628. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5629. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5630. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5631. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5632. // 'Activité interactive enregistrée avec succès sous le nom:';
  5633. // 'Atividade interativa gravada com sucesso sob o nome:'
  5634. $output = "
  5635. <script type='text/javascript'>
  5636. //<![CDATA[
  5637. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5638. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5639. //]]>
  5640. </script>";
  5641. print $output;
  5642. die();
  5643. }
  5644. /// Function for write iAssign file in Moodle data (exercise)
  5645. // @param string $stringArchiveContent Content of iassign file
  5646. // @param string $filename Filename of iassign file
  5647. // @param int $itemid Itemid of iassign file
  5648. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5649. global $OUTPUT, $USER;
  5650. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5651. $context = context_course::instance($this->id);
  5652. $dirid = $this->get_dir_ilm('dirid');
  5653. if ($stringArchiveContent != (-1)) {
  5654. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5655. $file = $fs->get_file_by_id($fileid);
  5656. if (!$file) {
  5657. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5658. die;
  5659. }
  5660. $fileinfo = array('contextid' => $context->id, // ID of context
  5661. 'component' => 'mod_iassign', // usually = table name
  5662. 'filearea' => 'activity', // usually = table name
  5663. 'itemid' => 0, // usually = ID of row in table
  5664. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5665. 'userid' => $USER->id,
  5666. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5667. 'license' => 'allrightsreserved', // allrightsreserved
  5668. 'timecreated' => $file->get_timecreated(),
  5669. 'filename' => $file->get_filename()); // any filename
  5670. $file->delete();
  5671. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5672. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5673. }
  5674. $output = "<script type='text/javascript'>
  5675. //<![CDATA[
  5676. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5677. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5678. //]]>
  5679. </script>";
  5680. print $output;
  5681. die();
  5682. }
  5683. /// Function for create an tag for iAssign filter
  5684. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5685. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5686. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5687. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5688. // @param int $fileid Id of file
  5689. // @return string Return an string with an tag of iassign filter
  5690. function tag_ilm ($fileid) {
  5691. global $DB;
  5692. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5693. $width = '600';
  5694. $height = '400';
  5695. $file = $fs->get_file_by_id($fileid);
  5696. $filetype = explode(".", $file->get_filename());
  5697. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5698. foreach ($iassign_ilm as $value) {
  5699. $extensions = explode(",", $value->extension);
  5700. if (in_array($filetype[1], $extensions)) {
  5701. $width = $value->width;
  5702. $height = $value->height;
  5703. }
  5704. }
  5705. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5706. }
  5707. /// Function for delete iAssign file in Moodle data (exercise)
  5708. function delete_file_ilm () {
  5709. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5710. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5711. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5712. $file = $fs->get_file_by_id($fileid);
  5713. if ($file)
  5714. $file->delete();
  5715. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5716. die();
  5717. }
  5718. /// Function for delete selected iAssign file in Moodle data (exercise)
  5719. function delete_selected_ilm () {
  5720. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5721. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5722. $context = context_course::instance($this->id);
  5723. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5724. $dirid = $this->get_dir_ilm('dirid');
  5725. foreach ($files_id as $file_id) {
  5726. $file = $fs->get_file_by_id($file_id);
  5727. if ($file) {
  5728. if (!$file->is_directory())
  5729. $file->delete();
  5730. else {
  5731. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5732. foreach ($files_delete as $value)
  5733. $value->delete();
  5734. $file->delete();
  5735. }
  5736. }
  5737. }
  5738. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5739. die();
  5740. }
  5741. /// Function for duplicate iAssign file from "online" edition
  5742. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5743. function duplicate_file_ilm () {
  5744. global $USER, $COURSE;
  5745. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5746. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5747. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5748. $filename = optional_param('filename', NULL, PARAM_RAW);
  5749. $file = $fs->get_file_by_id($fileid);
  5750. $context = context_course::instance($this->id);
  5751. $fileinfo = array(
  5752. 'contextid' => $context->id, // ID of context
  5753. 'component' => 'mod_iassign', // usually = table name
  5754. 'filearea' => 'activity', // usually = table name
  5755. 'itemid' => 0, // usually = ID of row in table
  5756. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5757. 'userid' => $USER->id,
  5758. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5759. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5760. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5761. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5762. die();
  5763. }
  5764. /// Function for rename iAssign file
  5765. function rename_file_ilm () {
  5766. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5767. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5768. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5769. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5770. $file = $fs->get_file_by_id($fileid);
  5771. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5772. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5773. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5774. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5775. die();
  5776. }
  5777. /// Function for get iassign file for iassign form
  5778. function add_ilm () {
  5779. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5780. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5781. $output = "
  5782. <script type='text/javascript'>
  5783. //<![CDATA[
  5784. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5785. iassign_file_link.innerHTML = '$filename';
  5786. window.opener.document.forms['mform1'].file.value='$fileid';
  5787. window.opener.document.forms['mform1'].filename.value='$filename';
  5788. window.close();
  5789. //]]>
  5790. </script>";
  5791. print $output;
  5792. die();
  5793. }
  5794. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5795. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5796. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5797. function preview_ilm ($courseid, $iassign_ilm) {
  5798. global $OUTPUT, $CFG, $USER;
  5799. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5800. $title = get_string('modulename', 'iassign'); // iAssign
  5801. print $OUTPUT->header();
  5802. print $OUTPUT->box_start();
  5803. $javascript = "
  5804. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5805. <script type='text/javascript'>
  5806. //<![CDATA[
  5807. function submit_close () {
  5808. window.opener.location.reload();
  5809. window.close();
  5810. }
  5811. //]]>
  5812. </script>\n";
  5813. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5814. // to the complete "applet" tag
  5815. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5816. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5817. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5818. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5819. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5820. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5821. if ($ilm_name != "ivprog") {
  5822. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5823. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5824. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5825. } else {
  5826. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5827. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5828. $timecreated = time();
  5829. $token = md5($timecreated);
  5830. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5831. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5832. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5833. $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)
  5834. }
  5835. $html = "
  5836. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5837. <table border='1'>
  5838. <tr><td>
  5839. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5840. <!-- iLM calls : end -->
  5841. </td></tr>
  5842. </table>
  5843. <table>
  5844. <tr>
  5845. <td align='center'>
  5846. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5847. </td></tr>
  5848. </table>
  5849. </form>\n";
  5850. print $javascript . $html;
  5851. print $OUTPUT->box_end();
  5852. //NAO echo format_string($html); // Moodle 3.X
  5853. die();
  5854. } // function preview_ilm($courseid, $iassign_ilm)
  5855. //r_ function preview_ilm ($iassign_ilm)
  5856. //r_ /// Function for preview iassign file from iassign filter.
  5857. //r_ function preview_ilm() {
  5858. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5859. //r_ $tag_filter = $this->tag_ilm($fileid);
  5860. //r_ $javascript = "<script type='text/javascript'>
  5861. //r_ //<![CDATA[
  5862. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5863. //r_ //]]>
  5864. //r_ </script>";
  5865. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5866. //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>
  5867. //r_ </table></form></body></html>";
  5868. //r_ echo $javascript . format_text($html);
  5869. //r_ die;
  5870. //r_ }
  5871. /// Function for export an package (zip) of iassign files
  5872. function export_files_ilm () {
  5873. global $CFG;
  5874. $context = context_course::instance($this->id);
  5875. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5876. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5877. $zip = new zip_archive();
  5878. $zip->open($zip_filename);
  5879. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5880. foreach ($files_id as $file_id) {
  5881. $file = $fs->get_file_by_id($file_id);
  5882. if (!$file->is_directory())
  5883. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5884. else {
  5885. $zip->add_directory($file->get_filepath());
  5886. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5887. foreach ($files_zip as $value) {
  5888. if (!$value->is_directory())
  5889. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5890. else
  5891. $zip->add_directory($value->get_filepath());
  5892. }
  5893. }
  5894. }
  5895. $zip->close();
  5896. header("Pragma: public");
  5897. header("Expires: 0");
  5898. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5899. header("Cache-Control: private", false);
  5900. header("Content-Type: application/zip");
  5901. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5902. header("Content-Transfer-Encoding: binary");
  5903. header("Content-Length: " . @filesize($zip_filename));
  5904. set_time_limit(0);
  5905. @readfile("$zip_filename") || die("File not found.");
  5906. unlink($zip_filename);
  5907. exit;
  5908. }
  5909. /// Function of execute a command in button editor tinymce
  5910. // @param int $fileid Id of file
  5911. function tinymce_ilm ($fileid) {
  5912. $tag_filter = $this->tag_ilm($fileid);
  5913. $output = "<script type='text/javascript'>
  5914. //<![CDATA[
  5915. var tag_filter = '$tag_filter';
  5916. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5917. // all right, insert it
  5918. } else {
  5919. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5920. }
  5921. // window.close();
  5922. //]]>
  5923. </script>\n";
  5924. print $output;
  5925. die();
  5926. }
  5927. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5928. /// Function to add content to the Editor Window
  5929. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5930. // @param int $fileid Id of file
  5931. function editor_ilm ($fileid, $editor) {
  5932. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5933. $output1 = "<script type='text/javascript'>
  5934. //<![CDATA[
  5935. var tag_filter = '$tag_filter';\n";
  5936. if ($editor == 'atto') {
  5937. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5938. } elseif ($editor == 'tinyMCE') {
  5939. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5940. } else
  5941. $output2 = "";
  5942. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5943. window.close();
  5944. //]]>
  5945. </script>\n";
  5946. //D var_dump($output);
  5947. print $output1 . $output2 . $output3;
  5948. die();
  5949. }
  5950. /// Function to add content to the Atto Editor Window
  5951. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5952. // @param int $fileid Id of file
  5953. function atto_ilm ($fileid) {
  5954. global $CFG, $DB;
  5955. $tag_filter = $this->tag_ilm($fileid);
  5956. $output = "<script type='text/javascript'>
  5957. //<![CDATA[
  5958. var tag_filter = '$tag_filter';
  5959. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5960. // all right, insert iLM tag to this editor
  5961. } else {
  5962. // error trying to insert
  5963. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5964. }
  5965. //window.close();
  5966. //]]>
  5967. </script>\n";
  5968. print $output;
  5969. die();
  5970. }
  5971. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5972. // @param string $key Key for return information
  5973. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5974. function get_dir_ilm ($key) {
  5975. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5976. $context = context_course::instance($this->id);
  5977. $dirid = optional_param('dirid', 0, PARAM_INT);
  5978. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5979. if ($dirid == 0) {
  5980. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5981. $dirid = $dir->get_id();
  5982. }
  5983. else {
  5984. $dir = $fs->get_file_by_id($dirid);
  5985. $dir_base = $dir->get_filepath();
  5986. }
  5987. $dir_parent = $dir->get_parent_directory();
  5988. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5989. return $data[$key];
  5990. }
  5991. /// Function for create an new dir
  5992. function new_dir_ilm () {
  5993. global $USER;
  5994. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5995. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5996. $dir_base = $this->get_dir_ilm('dir_base');
  5997. $context = context_course::instance($this->id);
  5998. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5999. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6000. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6001. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6002. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6003. }
  6004. /// Function for delete an dir
  6005. function delete_dir_ilm () { //
  6006. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6007. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6008. $context = context_course::instance($this->id);
  6009. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6010. $dir_parent = $this->get_dir_ilm('dir_parent');
  6011. if ($dir) {
  6012. if ($dir->is_directory()) {
  6013. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6014. foreach ($files_delete as $value)
  6015. $value->delete();
  6016. $dir->delete();
  6017. }
  6018. }
  6019. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6020. die();
  6021. }
  6022. /// Function for rename an dir
  6023. function rename_dir_ilm () {
  6024. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6025. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6026. $context = context_course::instance($this->id);
  6027. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6028. $dir_parent = $this->get_dir_ilm('dir_parent');
  6029. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6030. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6031. if ($dir->is_directory()) {
  6032. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6033. foreach ($files_rename_path as $value)
  6034. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6035. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6036. }
  6037. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6038. die();
  6039. }
  6040. /// Function for move an dir and your content for other dir
  6041. function selected_move_ilm () {
  6042. global $PAGE, $OUTPUT, $CFG;
  6043. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6044. $context = context_course::instance($this->id);
  6045. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6046. $dirid = $this->get_dir_ilm('dirid');
  6047. $dir_base = $this->get_dir_ilm('dir_base');
  6048. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6049. $code_javascript_ilm = "
  6050. <script type='text/javascript'>
  6051. //<![CDATA[
  6052. function getRadiobutton () {
  6053. var radioButtons = document.getElementsByTagName('input');
  6054. var param = '';
  6055. for (var counter=0; counter < radioButtons.length; counter++) {
  6056. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6057. param = radioButtons[counter].value;
  6058. }
  6059. return param;
  6060. }
  6061. function move_selected_ilm () {
  6062. var msgAnswer;
  6063. if (getRadiobutton() != '') {
  6064. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6065. if (msgAnswer)
  6066. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6067. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6068. }
  6069. else
  6070. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6071. }
  6072. function cancel_selected_ilm () {
  6073. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6074. }
  6075. //]]>
  6076. </script>\n";
  6077. $title = get_string('move_files', 'iassign');
  6078. $PAGE->set_title($title);
  6079. $PAGE->set_pagelayout('base');
  6080. print $OUTPUT->header();
  6081. print $OUTPUT->heading($title);
  6082. $dir_paths = array();
  6083. print $OUTPUT->box_start();
  6084. print "<center>";
  6085. foreach ($files_id as $file_id) {
  6086. $file = $fs->get_file_by_id($file_id);
  6087. if ($file) {
  6088. if (!$file->is_directory())
  6089. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6090. else {
  6091. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6092. array_push($dir_paths, $file->get_filepath());
  6093. }
  6094. }
  6095. }
  6096. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6097. if ($dir_base != '/') {
  6098. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6099. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6100. }
  6101. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6102. foreach ($files_tree as $file) {
  6103. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6104. $is_parent = false;
  6105. foreach ($dir_paths as $dir) {
  6106. $path = explode("/", $dir);
  6107. array_pop($path);
  6108. $path[count($path) - 1] = '';
  6109. $path = implode("/", $path);
  6110. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6111. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6112. }
  6113. if ($is_parent == false) {
  6114. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6115. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6116. }
  6117. }
  6118. }
  6119. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6120. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6121. print "</center>";
  6122. print $OUTPUT->box_end();
  6123. print $OUTPUT->footer();
  6124. print $code_javascript_ilm;
  6125. die;
  6126. }
  6127. /// Function for move files for an dir
  6128. function move_files_ilm () {
  6129. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6130. $context = context_course::instance($this->id);
  6131. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6132. $dirid = $this->get_dir_ilm('dirid');
  6133. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6134. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6135. foreach ($files_id as $file_id) {
  6136. $file = $fs->get_file_by_id($file_id);
  6137. if ($file) {
  6138. if ($file->is_directory()) {
  6139. $pathname = explode("/", $file->get_filepath());
  6140. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6141. foreach ($files_move_path as $value) {
  6142. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6143. $value->rename($path_move, $value->get_filename());
  6144. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6145. }
  6146. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6147. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6148. $file->rename($path_move, $file->get_filename());
  6149. } else {
  6150. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6151. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6152. }
  6153. }
  6154. }
  6155. //die;
  6156. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6157. die();
  6158. } // function move_files_ilm()
  6159. /// Function for recover files in use on all activities of a course
  6160. function recover_files_ilm () {
  6161. global $DB, $USER;
  6162. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6163. $courseid = optional_param('id', NULL, PARAM_INT);
  6164. $dirid = $this->get_dir_ilm('dirid');
  6165. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6166. $contextfile = context_course::instance($this->id);
  6167. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6168. foreach ($iassigns as $iassign) {
  6169. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6170. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6171. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6172. $context = context_module::instance($cm->id);
  6173. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6174. if ($files) {
  6175. foreach ($files as $value) {
  6176. $extension = explode(".", $value->get_filename());
  6177. if (!$value->is_directory()) {
  6178. $fileinfo = array('contextid' => $contextfile->id,
  6179. 'component' => 'mod_iassign',
  6180. 'filearea' => 'activity',
  6181. 'itemid' => 0,
  6182. 'filepath' => $this->get_dir_ilm('dir_base'),
  6183. 'userid' => $USER->id,
  6184. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6185. 'license' => 'allrightsreserved',
  6186. 'timecreated' => time(),
  6187. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6188. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6189. }
  6190. }
  6191. } // if ($files)
  6192. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6193. } // foreach ($iassigns as $iassign)
  6194. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6195. die();
  6196. } // function recover_files_ilm()
  6197. /// Auxiliary function the get all files in a given context
  6198. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6199. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6200. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6201. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6202. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6203. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6204. // (NAO s_iassign_statement.file = s_files.id)
  6205. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6206. $dir_base = $this->get_dir_ilm('dir_base');
  6207. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6208. $countf = 0;
  6209. $array_files_id = array(); // all files from this context
  6210. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6211. //$filename = $item_fc->get_filename();
  6212. //$filepath = $item_fc->get_filepath();
  6213. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6214. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6215. // $array_files_aux[] = $item_fc;
  6216. $itemid = $item_fc->get_id();
  6217. if (!in_array($itemid, $array_files_id)) {
  6218. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6219. if ($fileuserid == $userid)
  6220. $filesfrommine[] = $item_fc;
  6221. else
  6222. $filesfromothers[] = $item_fc;
  6223. $array_files_id[] = $itemid;
  6224. $countf++;
  6225. }
  6226. }
  6227. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6228. return $countf;
  6229. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6230. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6231. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6232. function get_all_ilm_files_by_fileid ($fileid) {
  6233. global $DB, $USER;
  6234. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6235. //TODO Criar coluna 'authorid'
  6236. $str_query = "SELECT * FROM {iassign_statement} " .
  6237. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6238. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6239. return $array_iassign_ilm;
  6240. }
  6241. //NN
  6242. //NN
  6243. // Build string with JavaScript code with function to edit/remove/double iLM files
  6244. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6245. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6246. global $CFG;
  6247. $error_files_exists = get_string('error_file_exists', 'iassign');
  6248. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6249. $code_javascript_ilm = "
  6250. <script type='text/javascript'>
  6251. //<![CDATA[
  6252. function preview_ilm (fileid, ilmid) { //JavaScript function
  6253. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6254. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6255. }
  6256. function update_ilm (ilmid, fileid) { //JavaScript function
  6257. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6258. }
  6259. function delete_ilm (ilmid, fileid) { //JavaScript function
  6260. var msgAnswer;
  6261. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6262. if (msgAnswer) {
  6263. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6264. }
  6265. }
  6266. function delete_selected_ilm () { //JavaScript function
  6267. var msgAnswer;
  6268. var param = getCheckbox();
  6269. if (param.join() != '') {
  6270. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6271. if (msgAnswer)
  6272. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6273. }
  6274. else
  6275. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6276. }
  6277. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6278. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6279. }
  6280. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6281. var filenamecopy;
  6282. var i;
  6283. var files = new Array(" . $files_array . ");
  6284. do {
  6285. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6286. } while (filenamecopy == '');
  6287. if (filenamecopy == null)
  6288. return false;\n
  6289. else {
  6290. for (i=0;i<files.length;i++) {
  6291. if (files[i]==filenamecopy) {
  6292. alert('" . $error_files_exists . "');
  6293. return false;\n
  6294. }
  6295. }\n" .
  6296. // @see: function 'duplicate_file_ilm()' above
  6297. "
  6298. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6299. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6300. } // else
  6301. }
  6302. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6303. var filenamecopy;
  6304. var i;
  6305. var files = new Array($files_array);
  6306. do {
  6307. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6308. } while (filenamecopy == '');
  6309. if (filenamecopy == null)
  6310. return false;
  6311. else {
  6312. for (i=0;i<files.length;i++) {
  6313. if (files[i]==filenamecopy) {
  6314. alert('" . $error_files_exists . "');
  6315. return false;
  6316. }
  6317. }
  6318. 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;
  6319. }
  6320. }
  6321. function export_files_ilm () { //JavaScript function
  6322. var param = getCheckbox();
  6323. if (param.join() != '')
  6324. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6325. else
  6326. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6327. }
  6328. function select_all_ilm () { //JavaScript function
  6329. var checkBoxes = document.getElementsByTagName('input');
  6330. var selectAll = document.getElementById('select_all');
  6331. for (var counter=0; counter < checkBoxes.length; counter++) {
  6332. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6333. checkBoxes[counter].checked = selectAll.checked;
  6334. }
  6335. }
  6336. function getCheckbox () { //JavaScript function
  6337. var checkBoxes = document.getElementsByTagName('input');
  6338. var param = new Array();
  6339. for (var counter=0; counter < checkBoxes.length; counter++) {
  6340. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6341. param.push(checkBoxes[counter].value);
  6342. }
  6343. return param;
  6344. }
  6345. function new_dir_ilm () { //JavaScript function
  6346. var dirname = '';
  6347. var i;
  6348. var dirs = new Array(" . $dirs_array . ");
  6349. do {
  6350. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6351. } while (dirname == '');
  6352. if (dirname == null)
  6353. return false;\n
  6354. else {
  6355. for (i=0;i<dirs.length;i++) {
  6356. if (dirs[i]==dirname) {
  6357. alert('" . $error_dir_exists . "');
  6358. return false;\n
  6359. }
  6360. }
  6361. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6362. }
  6363. }
  6364. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6365. var msgAnswer;
  6366. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6367. if (msgAnswer) {
  6368. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6369. }
  6370. }
  6371. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6372. var dirnamecopy;
  6373. var i;
  6374. var dirs = new Array($dirs_array);
  6375. do {
  6376. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6377. } while (dirnamecopy == '');
  6378. if (dirnamecopy == null)
  6379. return false;\n
  6380. else {
  6381. for (i=0;i<dirs.length;i++) {
  6382. if (dirs[i]==dirnamecopy) {
  6383. alert('" . $error_dir_exists . "');
  6384. return false;\n
  6385. }
  6386. }
  6387. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6388. }
  6389. }
  6390. function move_selected_ilm (ilmid) { //JavaScript function
  6391. var param = getCheckbox();
  6392. if (param.join() != '')
  6393. 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();
  6394. else
  6395. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6396. }
  6397. function recover_files_ilm () { //JavaScript function
  6398. var msgAnswer;
  6399. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6400. if (msgAnswer) {
  6401. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6402. }
  6403. }
  6404. window.onload = function() { //JavaScript function
  6405. var xPosition = 0;
  6406. var yPosition = 0;
  6407. element=document.getElementById('new_file');
  6408. while(element) {
  6409. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6410. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6411. element = element.offsetParent;
  6412. }
  6413. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6414. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6415. location.hash = '#new_file';
  6416. };
  6417. //]]>
  6418. </script>\n"; // end of $code_javascript_ilm
  6419. return $code_javascript_ilm;
  6420. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6421. /// List iassign files from course directory
  6422. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6423. function view_files_ilm ($iassign_ilm_class, $extension) {
  6424. global $CFG, $DB, $USER, $OUTPUT;
  6425. $fs = get_file_storage();
  6426. $context = context_course::instance($this->id);
  6427. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6428. $dirid = $this->get_dir_ilm('dirid');
  6429. $dir_base = $this->get_dir_ilm('dir_base');
  6430. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6431. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6432. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6433. $files_array = '';
  6434. foreach ($files_course as $value) {
  6435. if (!$value->is_directory())
  6436. $files_array .= "'" . $value->get_filename() . "',";
  6437. }
  6438. $files_array .= "''";
  6439. $error_files_exists = get_string('error_file_exists', 'iassign');
  6440. $dirs_array = '';
  6441. foreach ($files_course as $value) {
  6442. if ($value->is_directory()) {
  6443. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6444. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6445. }
  6446. }
  6447. $dirs_array .= "''";
  6448. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6449. // TODO Rever o preview pois só deixar ver uma vez.
  6450. $code_javascript_ilm = "
  6451. <script type='text/javascript'>
  6452. //<![CDATA[
  6453. function preview_ilm (fileid, ilmid) {
  6454. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6455. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6456. }
  6457. function update_ilm (ilmid, fileid) {
  6458. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6459. }
  6460. function delete_ilm (ilmid, fileid) {
  6461. var msgAnswer;
  6462. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6463. if (msgAnswer) {
  6464. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6465. }
  6466. }
  6467. function delete_selected_ilm () {
  6468. var msgAnswer;
  6469. var param = getCheckbox();
  6470. if (param.join() != '') {
  6471. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6472. if (msgAnswer)
  6473. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6474. }
  6475. else
  6476. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6477. }
  6478. function add_ilm_iassign (ilmid, filename, fileid) {
  6479. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6480. }
  6481. function duplicate_ilm (ilmid, filename, fileid) {
  6482. var filenamecopy;
  6483. var i;
  6484. var files = new Array($files_array);
  6485. do {
  6486. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6487. } while (filenamecopy == '');
  6488. if (filenamecopy == null)
  6489. return false;\n
  6490. else {
  6491. for (i=0;i<files.length;i++) {
  6492. if (files[i]==filenamecopy) {
  6493. alert('$error_files_exists');
  6494. return false;\n
  6495. }
  6496. }\n" .
  6497. // @see: function 'duplicate_file_ilm()' above
  6498. "
  6499. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6500. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6501. } // else
  6502. }
  6503. function rename_ilm (ilmid, filename, fileid) {
  6504. var filenamecopy;
  6505. var i;
  6506. var files = new Array($files_array);
  6507. do {
  6508. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6509. } while (filenamecopy == '');
  6510. if (filenamecopy == null)
  6511. return false;
  6512. else {
  6513. for (i=0;i<files.length;i++) {
  6514. if (files[i]==filenamecopy) {
  6515. alert('$error_files_exists');
  6516. return false;
  6517. }
  6518. }
  6519. 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;
  6520. }
  6521. }
  6522. function export_files_ilm () {
  6523. var param = getCheckbox();
  6524. if (param.join() != '')
  6525. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6526. else
  6527. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6528. }
  6529. function select_all_ilm () {
  6530. var checkBoxes = document.getElementsByTagName('input');
  6531. var selectAll = document.getElementById('select_all');
  6532. for (var counter=0; counter < checkBoxes.length; counter++) {
  6533. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6534. checkBoxes[counter].checked = selectAll.checked;
  6535. }
  6536. }
  6537. function getCheckbox () {
  6538. var checkBoxes = document.getElementsByTagName('input');
  6539. var param = new Array();
  6540. for (var counter=0; counter < checkBoxes.length; counter++) {
  6541. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6542. param.push(checkBoxes[counter].value);
  6543. }
  6544. return param;
  6545. }
  6546. function new_dir_ilm () {
  6547. var dirname = '';
  6548. var i;
  6549. var dirs = new Array($dirs_array);
  6550. do {
  6551. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6552. } while (dirname == '');
  6553. if (dirname == null)
  6554. return false;\n
  6555. else {
  6556. for (i=0;i<dirs.length;i++) {
  6557. if (dirs[i]==dirname) {
  6558. alert('$error_dir_exists');
  6559. return false;\n
  6560. }
  6561. }
  6562. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6563. }
  6564. }
  6565. function delete_dir_ilm (ilmid, dirid) {
  6566. var msgAnswer;
  6567. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6568. if (msgAnswer) {
  6569. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6570. }
  6571. }
  6572. function rename_dir_ilm (ilmid, dirname, dirid) {
  6573. var dirnamecopy;
  6574. var i;
  6575. var dirs = new Array($dirs_array);
  6576. do {
  6577. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6578. } while (dirnamecopy == '');
  6579. if (dirnamecopy == null)
  6580. return false;\n
  6581. else {
  6582. for (i=0;i<dirs.length;i++) {
  6583. if (dirs[i]==dirnamecopy) {
  6584. alert('$error_dir_exists');
  6585. return false;\n
  6586. }
  6587. }
  6588. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6589. }
  6590. }
  6591. function move_selected_ilm (ilmid) {
  6592. var param = getCheckbox();
  6593. if (param.join() != '')
  6594. 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();
  6595. else
  6596. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6597. }
  6598. function recover_files_ilm () {
  6599. var msgAnswer;
  6600. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6601. if (msgAnswer) {
  6602. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6603. }
  6604. }
  6605. window.onload = function() {
  6606. var xPosition = 0;
  6607. var yPosition = 0;
  6608. element=document.getElementById('new_file');
  6609. while(element) {
  6610. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6611. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6612. element = element.offsetParent;
  6613. }
  6614. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6615. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6616. location.hash = '#new_file';
  6617. };
  6618. //]]>
  6619. </script>\n";
  6620. $output = "";
  6621. $select_all = "";
  6622. $count_files = 0;
  6623. $extensions_allow = array();
  6624. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6625. foreach ($iassign_ilm as $item_iassign_ilm)
  6626. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6627. foreach ($files_course as $value) {
  6628. $filename = $value->get_filename();
  6629. $filepath = $value->get_filepath();
  6630. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6631. $pathname = $pathname[count($pathname) - 1];
  6632. $fileid = $value->get_id();
  6633. $tmp = explode(".", $filename);
  6634. if (count($tmp)>1) // avoid error if the file has no extension
  6635. $filetype = $tmp[1];
  6636. else // probably error...
  6637. $filetype = '';
  6638. $author = $value->get_author();
  6639. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6640. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6641. $extensions = explode(",", $extension);
  6642. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6643. $count_files ++;
  6644. // buscar fileid nas tabelas do iassign
  6645. $list_filein_use = "";
  6646. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6647. if ($iassign_statement_activity_list) {
  6648. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6649. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6650. }
  6651. }
  6652. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6653. if (!$iassign_ilm) {
  6654. $iassign_ilm = new stdClass();
  6655. $iassign_ilm->id = $ilmid;
  6656. }
  6657. // Do not use $var inside "..." - problem with some "unusual" operational system
  6658. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6659. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6660. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6661. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6662. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6663. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6664. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6665. $check_select = "";
  6666. $link_rename = "";
  6667. $link_delete = "";
  6668. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6669. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6670. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6671. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6672. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6673. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6674. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6675. if ($value->get_userid() == $USER->id) {
  6676. if ($iassign_statement_activity_list) {
  6677. $check_select = "";
  6678. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6679. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6680. $link_rename = "";
  6681. } else {
  6682. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6683. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6684. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6685. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6686. }
  6687. }
  6688. if (!in_array($filetype, $extensions_allow)) {
  6689. $link_edit = "";
  6690. $link_add_ilm_iassign = "";
  6691. $link_add_ilm_tinymce = "";
  6692. $link_add_ilm_atto = "";
  6693. $link_filter = "";
  6694. }
  6695. if ($value->is_directory()) {
  6696. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6697. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6698. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6699. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6700. <td><center>$author</center></td>
  6701. <td><center>$timecreated</center></td>
  6702. <td><center>$timemodified</center></td></tr>\n";
  6703. }
  6704. else if ($this->from == 'iassign') {
  6705. $new_id = "";
  6706. $new_class = "";
  6707. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6708. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6709. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6710. }
  6711. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6712. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6713. <td><center>$author</center></td>
  6714. <td><center>$timecreated</center></td>
  6715. <td><center>$timemodified</center></td></tr>\n";
  6716. }
  6717. else if ($this->from == 'block') {
  6718. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6719. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6720. <td><center>$author</center></td>
  6721. <td><center>$timecreated</center></td>
  6722. <td><center>$timemodified</center></td></tr>\n";
  6723. }
  6724. else if ($this->from == 'tinymce') {
  6725. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6726. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6727. <td><center>$author</center></td>
  6728. <td><center>$timecreated</center></td>
  6729. <td><center>$timemodified</center></td></tr>\n";
  6730. }
  6731. else if ($this->from == 'atto') {
  6732. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6733. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6734. <td><center>$author</center></td>
  6735. <td><center>$timecreated</center></td>
  6736. <td><center>$timemodified</center></td></tr>\n";
  6737. }
  6738. }
  6739. }
  6740. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6741. $dir_base = "";
  6742. $header = "";
  6743. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6744. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6745. foreach ($basename as $value) {
  6746. $dir_base .= $value . "/";
  6747. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6748. if ($dir_id) {
  6749. if ($value == "") {
  6750. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6751. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6752. } else {
  6753. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6754. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6755. }
  6756. }
  6757. } // foreach ($basename as $value)
  6758. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6759. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6760. $html .= "
  6761. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6762. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6763. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6764. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6765. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6766. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6767. </table>\n";
  6768. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6769. $html .= "<table width='100%'><tr>\n";
  6770. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6771. if ($count_files != 0) {
  6772. $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";
  6773. $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";
  6774. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6775. }
  6776. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6777. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6778. $html .= "</form>\n";
  6779. print $code_javascript_ilm;
  6780. print $html;
  6781. } // function view_files_ilm($extension)
  6782. } // class ilm_manager
  6783. /// Class to insert of icons
  6784. class iassign_icons {
  6785. static function insert ($icon) {
  6786. global $CFG;
  6787. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6788. return $string;
  6789. }
  6790. }
  6791. /// Class with util functions for plugin manage
  6792. class iassign_utils {
  6793. /// Function to return the filename extension
  6794. // @param string The $filename as an string
  6795. // @return string Return an string (last group after '.')
  6796. static function filename_extension ($filename) {
  6797. if ($filename == null || $filename == '') {
  6798. return null;
  6799. }
  6800. $itens = explode('.', $filename);
  6801. $num = count($itens);
  6802. if ($num < 2) {
  6803. return null;
  6804. }
  6805. return $itens[$num - 1];
  6806. }
  6807. /// Use the PHP class/package ZipArchive to create a Zip file
  6808. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6809. // 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
  6810. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6811. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6812. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6813. $zip = new zip_archive(); //2
  6814. $res = $zip->open($full_path_zip_filename);
  6815. $total_vet = count($vet_student_filename);
  6816. for ($ii=0; $ii<$total_vet; $ii++) {
  6817. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6818. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6819. }
  6820. $ret = $zip->close();
  6821. iassign_utils::download_file($full_path_zip_filename);
  6822. $filenameZip = $zip->filename;
  6823. return array($ret, $zip);
  6824. }
  6825. static function download_file ($zip_filename) {
  6826. header("Pragma: public");
  6827. header("Expires: 0");
  6828. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6829. header("Cache-Control: private", false);
  6830. header("Content-Type: application/zip");
  6831. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6832. header("Content-Transfer-Encoding: binary");
  6833. header("Content-Length: " . @filesize($zip_filename));
  6834. set_time_limit(0);
  6835. @readfile("$zip_filename") || die("File not found.");
  6836. unlink($zip_filename);
  6837. }
  6838. /// Function for format filename remove special caracters
  6839. // @param string $text String for clean
  6840. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6841. // @return string Return an string in clean format
  6842. static function format_filename ($text) {
  6843. if ($text != '.') {
  6844. //D $text = htmlspecialchars(urldecode($text));
  6845. //D echo "locallib.php: format_filename: $text<br/>";
  6846. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6847. $text = json_decode($text)->{current_language()};
  6848. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6849. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  6850. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6851. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6852. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  6853. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6854. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6855. // E.g. text = "exerc_midpoint.course.geo"
  6856. // 0123456789012345678901234
  6857. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6858. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6859. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6860. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6861. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6862. //$ext = strrpos($text, ".");
  6863. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6864. //$text = str_replace($array1, $array2, $text);
  6865. }
  6866. return $text;
  6867. }
  6868. /// Function to filter characters to the file name to iLM content
  6869. // @param string $text String for clean
  6870. // @param string $ext String ot the extension of the iLM
  6871. // @return string Return an string in clean format
  6872. static function filter_filename_extension ($filename, $ext) {
  6873. if ($filename != '.') {
  6874. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6875. $arrTo = array("_","","","","","","","","","","","","");
  6876. $filename = str_replace($arrFrom, $arrTo, $filename);
  6877. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6878. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6879. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6880. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6881. $index_lastposition = strlen($filenameF);
  6882. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6883. $text = str_replace(".", "_", $text); // erase all other "."
  6884. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6885. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6886. }
  6887. else
  6888. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6889. return $filenameF;
  6890. }
  6891. /// Function for format pathname remove special caracters
  6892. // @param string $text String for clean
  6893. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6894. // @return string Return an string in clean format
  6895. static function format_pathname ($text, $is_lowercase = true) {
  6896. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6897. $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", "-", "_", "", "", "");
  6898. $text = str_replace($array1, $array2, $text);
  6899. if ($is_lowercase)
  6900. $text = strtolower($text);
  6901. return $text;
  6902. }
  6903. /// Function for format file name from iLM original name
  6904. // @param string $text String to build the file neam
  6905. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6906. // @return string Return an string in clean format
  6907. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6908. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6909. $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", "-", "_", "", "", "");
  6910. $index_firstposition_blank = strpos($ilm_name, " ");
  6911. if ($index_firstposition_blank) { // truncate the name!
  6912. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6913. }
  6914. $index_firstposition_dots = strpos($ilm_name, ":");
  6915. if ($index_firstposition_dots) { // truncate the name!
  6916. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6917. }
  6918. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6919. if ($is_lowercase)
  6920. $namefiltered = strtolower($namefiltered);
  6921. return $namefiltered;
  6922. }
  6923. /// Function for insert version in the filename
  6924. // @param string $filename Name of file
  6925. // @return string Return the filename with version
  6926. static function version_filename ($filename) {
  6927. $array_filename = explode('.', $filename);
  6928. if (count($array_filename) > 1)
  6929. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6930. else
  6931. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6932. return $filename;
  6933. }
  6934. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6935. static function remove_code_message ($string) {
  6936. $array = explode("&lt;ia_uc&gt;", $string);
  6937. return $array[0];
  6938. }
  6939. }
  6940. // class iassign_utils
  6941. /// Class with language functions for plugin manage
  6942. class iassign_language {
  6943. /// Function for return text in language or get default language (en)
  6944. // @param string $lang Code of language
  6945. // @param string $description JSON text content all languages
  6946. // @return string Return an string in the language selected
  6947. static function get_description_lang ($lang, $descriptions) {
  6948. $description_lang = "";
  6949. $description = json_decode($descriptions);
  6950. if ($description == null) {
  6951. $description_lang = $descriptions;
  6952. }
  6953. else {
  6954. if (isset($description->{$lang}))
  6955. $description_lang = $description->{$lang};
  6956. else
  6957. if (isset($description->en)) //MOOC2014
  6958. $description_lang = $description->en;
  6959. else //MOOC2014
  6960. $description_lang = "en"; //MOOC2014
  6961. }
  6962. return $description_lang;
  6963. }
  6964. /// Function for return all language supported by iLM
  6965. // @param string $descriptions JSON text content all languages
  6966. // @return string Return as string with all languages
  6967. static function get_all_lang ($descriptions) {
  6968. $langs = "";
  6969. $description = json_decode($descriptions);
  6970. if ($description) {
  6971. foreach ($description as $key => $value) {
  6972. $langs .= $key . " ; ";
  6973. }
  6974. $langs = substr($langs, 0, strlen($langs) - 3);
  6975. }
  6976. return $langs;
  6977. }
  6978. /// Function for convert json in xml //MOOC2014
  6979. // @param string $json JSON text
  6980. // @return string Return as string with xml tags
  6981. static function json_to_xml ($json) {
  6982. $xml = "";
  6983. $json = json_decode($json);
  6984. foreach ($json as $key => $value) {
  6985. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6986. }
  6987. return $xml;
  6988. }
  6989. }
  6990. // class iassign_language
  6991. /// Class with log functions for plugin manage.
  6992. class iassign_log {
  6993. /// Function for insert log event
  6994. // @param string $action Code action of event
  6995. // @param string $information Text for describe action of event
  6996. // @param int $cmid Id of context module
  6997. // @param int $ilmid Id of iLM
  6998. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6999. global $COURSE, $CFG, $USER, $DB;
  7000. $newentry = new stdClass();
  7001. $newentry->time = time();
  7002. $newentry->userid = $USER->id;
  7003. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7004. $newentry->course = $COURSE->id;
  7005. $newentry->cmid = $cmid;
  7006. $newentry->ilmid = $ilmid;
  7007. $newentry->action = $action;
  7008. $newentry->info = $information;
  7009. $newentry->language = current_language();
  7010. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7011. if (ini_get("browscap") && function_exists('get_browse')) {
  7012. $browser = get_browse(null, true);
  7013. $newentry->javascript = $browser['javascript'];
  7014. $newentry->java = $browser['javaapplets'];
  7015. }
  7016. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7017. print_error('error_add_log', 'iassign');
  7018. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7019. } // class iassign_log