locallib.php 394 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506
  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. // Create $CFG->dataroot/temp/iassign_files
  392. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  393. if (!file_exists($tempfilespath)) {
  394. mkdir($tempfilespath, 0777, true);
  395. }
  396. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  397. if (!file_exists($iassignfilespath)) {
  398. mkdir($iassignfilespath, 0777, true);
  399. }
  400. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  401. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  402. if (!file_exists($diretorio)) {
  403. echo 'Não foi possível criar o diretório para preparar o arquivo com as submissões. Possivelmente o caminho está bloqueado para escrita.';
  404. exit;
  405. }
  406. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  407. $zip = new zip_archive(); // create ZIP
  408. if (!$zip->open($zip_filename)) {
  409. echo 'Não foi possível criar o arquivo zip com as submissões dos alunos, pois o diretório no servidor está bloqueado para escrita: ' . $diretorio;
  410. exit;
  411. }
  412. ;
  413. foreach ($exercises_list as $exercise) {
  414. $dir_ex = iassign_utils::format_filename($exercise->name);
  415. $zip->add_directory($dir_ex);
  416. $extension_ilm = '';
  417. foreach ($ilm_list as $ilm) {
  418. if ($exercise->iassign_ilmid == $ilm->id) {
  419. $extension_ilm = $ilm->extension;
  420. break;
  421. }
  422. }
  423. foreach ($students_list as $student) {
  424. $individual_dir =
  425. $dir_ex . DIRECTORY_SEPARATOR .
  426. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  427. $zip->add_directory($individual_dir);
  428. $i = 1;
  429. foreach($list as $item) {
  430. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  431. $date = new DateTime();
  432. $date->setTimestamp($item->timecreated);
  433. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  434. $zip->add_file_from_string($new_file, $item->answer);
  435. $temp_json = [];
  436. $temp_json[] = intval($item->id);
  437. $temp_json[] = $new_file;
  438. $temp_json[] = strlen($new_file);
  439. $temp_json[] = intval($item->timecreated);
  440. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  441. $temp_json[] = doubleval($item->grade);
  442. $temp_json[] = intval($item->userid);
  443. $temp_json[] = intval($exercise->id);
  444. $json_obj->submissions[] = $temp_json;
  445. }
  446. }
  447. }
  448. }
  449. $csv_str = "";
  450. foreach($json_obj->submissions as $sub) {
  451. $csv_str .= $this->csvstr($sub) . "\n";
  452. }
  453. $zip->add_file_from_string('index.csv', $csv_str);
  454. $zip->close();
  455. iassign_utils::download_file($zip_filename);
  456. exit;
  457. }
  458. function csvstr(array $fields) : string {
  459. $f = fopen('php://memory', 'r+');
  460. if (fputcsv($f, $fields) === false) {
  461. return false;
  462. }
  463. rewind($f);
  464. $csv_line = stream_get_contents($f);
  465. return rtrim($csv_line);
  466. }
  467. /// Download submissions from table iassign_allsubmissions
  468. function download_submissions () {
  469. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  470. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  471. exit;
  472. $type = optional_param('type', NULL, PARAM_TEXT);
  473. $item = optional_param('item', NULL, PARAM_TEXT);
  474. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  475. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  476. $sub_list = [];
  477. if ($type == 'individual') {
  478. $sub_list[] = $DB->get_record(
  479. 'iassign_allsubmissions', array('id' => $item));
  480. } elseif ($type == 'student') {
  481. $sub_list = $DB->get_records(
  482. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  483. } elseif ($type == 'exercise') {
  484. $sub_list = $DB->get_records(
  485. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  486. } elseif ($type == 'block') {
  487. $exercises_in_block = $DB->get_records(
  488. 'iassign_statement', array('iassignid' => $iassign_id));
  489. foreach ($exercises_in_block as $exercise) {
  490. $temp = $DB->get_records(
  491. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  492. $sub_list = array_merge($sub_list, $temp);
  493. }
  494. }
  495. $this->download_submissions_help($sub_list);
  496. }
  497. /// Delete submissions in table iassign_allsubmissions
  498. function delete_submissions () {
  499. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  500. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  501. exit;
  502. $type = optional_param('type', NULL, PARAM_TEXT);
  503. $item = optional_param('item', NULL, PARAM_TEXT);
  504. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  505. if ($type == 'individual') {
  506. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  507. } elseif ($type == 'student') {
  508. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  509. } elseif ($type == 'exercise') {
  510. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  511. }
  512. }
  513. function get_individual_submission () {
  514. global $DB, $USER;
  515. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  516. exit;
  517. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  518. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  519. print $submission->answer;
  520. }
  521. /// Open individual submission
  522. function open_individual_submission () {
  523. global $DB, $USER, $CFG;
  524. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  525. exit;
  526. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  527. $id = $this->cm->id;
  528. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  529. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  530. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  531. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  532. $all_submissions = $DB->get_records('iassign_allsubmissions',
  533. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  534. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  535. $previous = null;
  536. $next = null;
  537. $i = 0;
  538. $found = false;
  539. foreach($all_submissions as $individual) {
  540. if (!$found && $individual->id != $submissionid) {
  541. $previous = $individual;
  542. }
  543. if ($found) {
  544. $next = $individual;
  545. break;
  546. }
  547. if ($individual->id === $submissionid) {
  548. $found = true;
  549. }
  550. $i ++;
  551. }
  552. print '<center>';
  553. print '<table cellpading=5 cellspacing=5 style="padding-bottom: 2rem;font-size: 1.1em;"><tr><td>' . get_string('exercise', 'iassign') . ':</td><td>' . $atual_statement->name . '</td></tr>';
  554. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>';
  555. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>';
  556. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>';
  557. print '</table>';
  558. if ($previous) {
  559. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  560. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  561. } else {
  562. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  563. }
  564. print ' (' . $i . '/' . count($all_submissions) . ')';
  565. if ($next) {
  566. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  567. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  568. } else {
  569. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  570. }
  571. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  572. print
  573. //array("type" => "editor_new", "notSEND" => "true")
  574. ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  575. print '</center>';
  576. }
  577. /// Manage all submissions in exercises to table iassign_allsubmissions
  578. function all_submissions () {
  579. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  580. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  581. exit;
  582. print $OUTPUT->header();
  583. $id = $this->cm->id;
  584. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  585. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  586. print '
  587. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  588. <div class="modal-dialog modal-dialog-centered" role="document">
  589. <div class="modal-content">
  590. <div class="modal-header">
  591. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  592. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  593. <span aria-hidden="true">&times;</span>
  594. </button>
  595. </div>
  596. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  597. <div class="modal-footer">
  598. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  599. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  600. </div>
  601. </div>
  602. </div>
  603. </div>'; // "
  604. print '
  605. <script>
  606. var sub_type;
  607. var sub_item;
  608. var sub_el;
  609. var sub_exercise;
  610. function delete_submission (type, item, el, exercise = 0) {
  611. sub_type = type;
  612. sub_item = item;
  613. sub_exercise = exercise;
  614. sub_el = el.closest("tr");
  615. if (!sub_el) sub_el = el.closest("a");
  616. $("#modalConfirm").modal();
  617. }
  618. function confirm_delete () {
  619. var url = "'.$enderecoPOST.'&action=delete_submissions";
  620. var xhttp = new XMLHttpRequest();
  621. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  622. xhttp.send();
  623. $("#modalConfirm").modal("hide");
  624. if ($(sub_el).attr("href"))
  625. $($(sub_el).attr("href")).remove();
  626. if (sub_el) sub_el.remove();
  627. }
  628. function download_submission(type, item, exercise = 0, iassign = 0) {
  629. var url = "'.$enderecoPOST.'&action=download_submissions";
  630. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  631. document.location = url;
  632. }
  633. function open_submission(item) {
  634. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  635. var poupup = window.open(url, "popup", "width=900,height=900");
  636. }
  637. </script>' . chr(13); // '
  638. // Get list of exercises in the instance:
  639. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  640. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  641. print '<h2 class="m-b-2">' . get_string('all_submissions_manager', 'iassign') . '';
  642. 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>';
  643. // Get list of enrolled students:
  644. $params_temp = array('shortname' => 'student');
  645. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  646. $context = context_course::instance($this->course->id);
  647. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  648. $students_list = $DB->get_records_sql(
  649. "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);
  650. print '<div>';
  651. foreach ($exercises_list as $exercise) {
  652. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  653. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  654. print '
  655. <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> '
  656. . $exercise->name
  657. . ' - ' . $iassign_ilm->name
  658. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  659. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  660. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  661. . $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> '
  662. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  663. . '</a>';
  664. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  665. foreach ($students_list as $student) {
  666. $total = 0;
  667. $student_submissions = [];
  668. foreach ($submissions_list as $submission) {
  669. if ($submission->userid == $student->userid) {
  670. $student_submissions[] = $submission;
  671. $total ++;
  672. }
  673. }
  674. 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");\'>
  675. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  676. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  677. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  678. . '<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> '
  679. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  680. . ' </a>';
  681. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  682. print '<table class="table table-striped table-hover"><thead>
  683. <tr>
  684. <th scope="col">#</th>
  685. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  686. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  687. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  688. </tr>
  689. </thead><tbody>'; // "
  690. $i = 1;
  691. foreach ($student_submissions as $individual) {
  692. $date = new DateTime();
  693. $date->setTimestamp($individual->timecreated);
  694. print '<tr>';
  695. print '<td>'.$i++.'</td>';
  696. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  697. print '<td>'.$individual->grade.'</td>';
  698. print '<td>
  699. <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>
  700. <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>
  701. <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>';
  702. print " </tr>\n";
  703. }
  704. print '</tbody></table>';
  705. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  706. print '</div>';
  707. }
  708. print '</div>';
  709. }
  710. print '</div>';
  711. print $OUTPUT->footer();
  712. } // function all_submissions()
  713. /// This method runs activities auto evaluation in teacher area
  714. function auto_evaluate () {
  715. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  716. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  717. exit;
  718. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  719. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  720. // Get list of exercises in the instance:
  721. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  722. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  723. // Get list of enrolled students:
  724. $params_temp = array('shortname' => 'student');
  725. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  726. $context = context_course::instance($this->course->id);
  727. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  728. $students_list = $DB->get_records_sql(
  729. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  730. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  731. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  732. print $OUTPUT->header();
  733. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  734. print '<ul style="list-style-type: none; margin: 1em;">';
  735. foreach ($exercises_list as $exercise) {
  736. $matches = [];
  737. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  738. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  739. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  740. if ($matches[0][0]) {
  741. 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>';
  742. } else {
  743. 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>';
  744. }
  745. } else {
  746. if ($matches[0][0]) {
  747. 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>';
  748. } else {
  749. 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>';
  750. }
  751. }
  752. }
  753. print '</ul>
  754. <center>
  755. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  756. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  757. <div id="evaluate_message" style="color: red"></div>
  758. <div id="evaluate_alerts"></div>
  759. <div>
  760. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  761. <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>
  762. </div>
  763. </center>'; // close "
  764. print ' </div>' + "\n";
  765. print ' <script>';
  766. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  767. print ' var submissions = [';
  768. // Get list of student id have submit for each exercise:
  769. foreach ($exercises_list as $exercise) {
  770. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  771. print '
  772. {
  773. "exerciseid": "' . $exercise->id . '",
  774. "grade": ' . $exercise->grade . ',
  775. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  776. "submited": ['; // "
  777. $params_temp = array('iassign_statementid' => $exercise->id);
  778. $submited = $DB->get_records_sql( // Get userid and his grade
  779. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  780. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  781. foreach ($submited as $ss) {
  782. print($ss->userid . ',');
  783. }
  784. print '],';
  785. print '"allgrades": [';
  786. foreach ($submited as $ss) {
  787. print( $ss->grade . ',');
  788. }
  789. print ']
  790. },'; // close "
  791. } // foreach ($exercises_list as $exercise)
  792. print " ];\n";
  793. print '
  794. var total_submissions = 0;
  795. var selected_exercises;
  796. var count_steps;
  797. var value_by_step;
  798. var stoped = false;
  799. var time_interval = 5000;
  800. var var_interval;
  801. function add_hover_th (id_th, id_li) { //AJAX
  802. $("#" + id_th).hover(function() {
  803. $("#" + id_li).css("background-color", "#d9d8d8");
  804. $(this).css("background-color", "#d9d8d8");
  805. }, function() {
  806. $("#" + id_li).css("background-color", "");
  807. $(this).css("background-color", "");
  808. });
  809. }
  810. function start_evaluation () {
  811. stoped = false;
  812. //AJAX
  813. $("#progress_bar").css("display", "none");
  814. $("#evaluate_message").text("");
  815. $("#evaluate_alerts").text("");
  816. $(".added-col").remove();
  817. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  818. selected_exercises = [];
  819. var c = 0;
  820. for (var i = 0; i < exercises.length; i++) {
  821. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  822. selected_exercises[c++] = exercises[i];
  823. }
  824. }
  825. if (selected_exercises.length == 0) {
  826. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  827. return;
  828. } else {
  829. $("input:checkbox").attr("disabled", true); //AJAX
  830. for (var i = 0; i < selected_exercises.length; i++) {
  831. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  832. //AJAX
  833. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  834. $("#table-results tbody tr").each(function(e) {
  835. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  836. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  837. });
  838. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  839. }
  840. //AJAX
  841. $("#button_start").prop("disabled", true);
  842. $("#button_stop").prop("disabled", false);
  843. $("#progress_bar").css("display", "block");
  844. }
  845. total_submissions = selected_exercises.length * students.length;
  846. count_steps = 0;
  847. value_by_step = 100/total_submissions;
  848. actual_exercise = 0;
  849. actual_student = 0;
  850. actual_submission = 0;
  851. get_original_propositions();
  852. var_interval = setInterval(verifyBreak, time_interval);
  853. } // function start_evaluation()
  854. var actual_exercise;
  855. var actual_student;
  856. var actual_submission;
  857. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  858. function run_individual_evaluation () {
  859. if (stoped) return;
  860. // Verify if student really sent his answer
  861. var found = false;
  862. for (var j = 0; j < submissions.length; j++) {
  863. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  864. for (var k = 0; k < submissions[j].submited.length; k++) {
  865. if (students[actual_student] == submissions[j].submited[k]) {
  866. found = true;
  867. break;
  868. }
  869. }
  870. break;
  871. }
  872. }
  873. if (found == false) {
  874. postResultAutoEval();
  875. } else {
  876. // If it was sent, search it...
  877. var final_url = "";
  878. 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];
  879. for (var j = 0; j < submissions.length; j++) {
  880. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  881. final_url = submissions[j].ilm;
  882. break;
  883. }
  884. }
  885. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  886. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  887. window.frames["ifrm"].location=final_url;
  888. }
  889. } // function run_individual_evaluation()
  890. var break_student = -1;
  891. var break_exercise = -1;
  892. function verifyBreak () {
  893. if (actual_student == break_student && actual_exercise == break_exercise) {
  894. postResultAutoEval(-6);
  895. break_student = -1;
  896. break_exercise = -1;
  897. return;
  898. } else {
  899. break_student = actual_student;
  900. break_exercise = actual_exercise;
  901. }
  902. }
  903. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  904. function getStudentAnswerURL () {
  905. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  906. }
  907. // This function is called by the iLM!!!
  908. function getAutoEvalOriginalData () {
  909. return original_propositions[actual_exercise];
  910. }
  911. function updateProgressBar () {
  912. if (stoped) return;
  913. var temp = (count_steps * value_by_step)|0;
  914. count_steps ++;
  915. temp = temp > 100 ? 100 : temp;
  916. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  917. if (temp >= 100) {
  918. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  919. $("#button_start").prop("disabled", false);
  920. $("#button_stop").prop("disabled", true);
  921. $("input:checkbox").attr("disabled", false);
  922. clearInterval(var_interval);
  923. }
  924. }
  925. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  926. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  927. function postResultAutoEval (grade = null) {
  928. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  929. if (grade == null) {
  930. $("#"+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>\');
  931. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  932. } else {
  933. // Verify if the re-evaluation grade is the of that one registered:
  934. var actual_value = 0;
  935. var actual_student_grade = 0;
  936. for (var k = 0; k < submissions.length; k++) {
  937. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  938. actual_value = submissions[k].grade;
  939. for (var h = 0; h < submissions[k].submited.length; h++) {
  940. if (submissions[k].submited[h] == students[actual_student]) {
  941. actual_student_grade = submissions[k].allgrades[h];
  942. break;
  943. }
  944. }
  945. break;
  946. }
  947. }
  948. // @FeedbackConvention
  949. if (grade < 0) {
  950. switch (grade) {
  951. case -1:
  952. // Test-cases are empty:
  953. $("#"+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>\');
  954. var mm = actual_exercise;
  955. $("#"+id_t).find(".details-button").click(function(e) {
  956. $(".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>\');
  957. });
  958. break;
  959. case -2:
  960. // Test-cases were manually altered by the student (fraud!):
  961. $("#"+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>\');
  962. var mm = actual_exercise;
  963. $("#"+id_t).find(".details-button").click(function(e) {
  964. $(".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>");
  965. });
  966. //AJAX
  967. $.ajax({
  968. dataType: "html",
  969. 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",
  970. success: function(d) {} });
  971. break;
  972. case -5:
  973. // Execution failed:
  974. $("#"+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>\');
  975. var mm = actual_exercise;
  976. //AJAX
  977. $("#"+id_t).find(".details-button").click(function(e) {
  978. $(".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>\');
  979. });
  980. break;
  981. case -6: // iLM not answering was detected in "verifyBreak()"
  982. // The iLM are not answering:
  983. //AJAX
  984. $("#"+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>\');
  985. $("#"+id_t).find(".details-button").click(function(e) {
  986. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  987. });
  988. break;
  989. }
  990. //AJAX
  991. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  992. } else {
  993. console.log((grade), (actual_student_grade));
  994. if ((grade) == (actual_student_grade)) {
  995. $("#"+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>\');
  996. } else { // Notas diferem:
  997. $("#"+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>\');
  998. var mm = actual_exercise;
  999. //AJAX
  1000. $("#"+id_t).find(".details-button").click(function(e) {
  1001. $(".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>\');
  1002. });
  1003. //AJAX
  1004. // Send to the endpoint the post_auto_eval_result to verify:
  1005. $.ajax({
  1006. dataType: "html",
  1007. 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),
  1008. success: function(d) {}
  1009. });
  1010. }
  1011. //AJAX
  1012. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1013. }
  1014. }
  1015. updateProgressBar();
  1016. // Does it must continue in the same exercise or stop?
  1017. if (actual_student < students.length) {
  1018. actual_student ++;
  1019. run_individual_evaluation();
  1020. } else {
  1021. actual_student = 0;
  1022. // Does it go to next exercise or is it finished?
  1023. if (actual_exercise < selected_exercises.length) {
  1024. actual_exercise++;
  1025. run_individual_evaluation();
  1026. } else {
  1027. //AJAX
  1028. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1029. }
  1030. }
  1031. }
  1032. var original_propositions;
  1033. function get_original_propositions () {
  1034. original_propositions = [];
  1035. var count = 0;
  1036. for (var i = 0; i < exercises.length; i++) {
  1037. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1038. //AJAX
  1039. $.ajax({
  1040. dataType: "html",
  1041. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1042. success: function(d) { // variable "d" has the iLM content
  1043. original_propositions[count] = d; // exercise original content
  1044. count ++;
  1045. if (count == selected_exercises.length) {
  1046. run_individual_evaluation();
  1047. }
  1048. }
  1049. });
  1050. }
  1051. }
  1052. }
  1053. function stop_evaluation () {
  1054. stoped = true;
  1055. //AJAX
  1056. $("#button_start").prop("disabled", false);
  1057. $("#button_stop").prop("disabled", true);
  1058. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1059. $("input:checkbox").attr("disabled", false);
  1060. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1061. clearInterval(var_interval);
  1062. }
  1063. var exercises = [ '; // '
  1064. foreach ($exercises_list as $exercise) {
  1065. print $exercise->id . ',';
  1066. }
  1067. print ' ];';
  1068. print ' var students = [ ';
  1069. foreach ($students_list as $student) {
  1070. print $student->userid . ',';
  1071. }
  1072. print '];';
  1073. print ' var ilms = [';
  1074. foreach ($exercises_list as $exercise) {
  1075. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1076. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1077. }
  1078. print ']';
  1079. print '</script>';
  1080. print '
  1081. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1082. <div class="modal-dialog modal-dialog-centered" role="document">
  1083. <div class="modal-content">
  1084. <div class="modal-header">
  1085. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1086. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1087. <span aria-hidden="true">&times;</span>
  1088. </button>
  1089. </div>
  1090. <div class="modal-body">
  1091. ...
  1092. </div>
  1093. <div class="modal-footer">
  1094. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1095. </div>
  1096. </div>
  1097. </div>
  1098. </div>'; //
  1099. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1100. print '<table id="table-results" class="table table-hover m-t-1">
  1101. <thead>
  1102. <tr id="cols-exercises">
  1103. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1104. </tr>
  1105. </thead>
  1106. <tbody>'; // "
  1107. foreach ($students_list as $student) {
  1108. $user = $DB->get_record('user', array('id' => $student->userid));
  1109. $avatar = new user_picture($user);
  1110. $avatar->courseid = $COURSE->id;
  1111. $avatar->link = true;
  1112. print ' <tr data-student="' . $student->userid . '">
  1113. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1114. </tr>' . "\n"; // "
  1115. }
  1116. print " </tbody>
  1117. </table>\n";
  1118. print $OUTPUT->footer();
  1119. } // function auto_evaluate()
  1120. /// This method moves an iAssign activity
  1121. function move_activity () {
  1122. global $USER, $CFG, $DB, $COURSE;
  1123. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1124. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1125. $update_entry_new_iassign = new stdClass();
  1126. $update_entry_new_iassign->id = $iassign_id;
  1127. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1128. // Update the iassign_statement
  1129. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1130. // Update file context
  1131. $c_i = context_module::instance($this->cm->id);
  1132. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1133. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1134. $path_module = context_course::instance($COURSE->id);
  1135. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1136. if ($context_file) {
  1137. $id_context = $context_file->id;
  1138. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1139. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1140. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1141. foreach ($files as $value) {
  1142. if ($value->get_filename() != ".") {
  1143. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1144. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1145. $updateentry = new stdClass();
  1146. $updateentry->id = $iassign_id;
  1147. $updateentry->filesid = $newfile->get_itemid();
  1148. $DB->update_record("iassign_statement", $updateentry);
  1149. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1150. break;
  1151. }
  1152. }
  1153. }
  1154. $this->return_home_course('moved_activity');
  1155. exit;
  1156. }
  1157. /// This method duplicates an iAssign activity
  1158. function duplicate_activity () {
  1159. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1160. $id = $this->cm->id;
  1161. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1162. $context = context_module::instance($this->cm->id);
  1163. $contextuser = context_user::instance($USER->id);
  1164. // Get the the iAssign acitivity to be duplicated
  1165. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1166. // Remove the current id of activity
  1167. $iassign_statement->id=0;
  1168. // Get the information about current author, and add this information in author_modified field
  1169. $author = $DB->get_record("user", array('id' => $USER->id));
  1170. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1171. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1172. // Store the activity in the table
  1173. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1174. // Duplicate activity file
  1175. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1176. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1177. foreach ($files as $value) {
  1178. if ($value->get_filename() != ".") {
  1179. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1180. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1181. $updateentry = new stdClass();
  1182. $updateentry->id = $id_;
  1183. $updateentry->filesid = $newfile->get_itemid();
  1184. // Update the duplicated iLM iAssign with new file id
  1185. $DB->update_record("iassign_statement", $updateentry);
  1186. }
  1187. }
  1188. }
  1189. // log event --------------------------------------------------------------------------------------
  1190. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1191. $this->return_home_course('duplicated_activity');
  1192. exit;
  1193. }
  1194. // / This method gets the content from comment and register it
  1195. function add_comment () {
  1196. global $USER, $DB;
  1197. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1198. $comment = false;
  1199. if ($submission_comment)
  1200. $comment = $this->write_comment_submission();
  1201. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1202. if (!$id_submission) {
  1203. $iassign_submission =
  1204. $DB->get_record("iassign_submission",
  1205. array(
  1206. "iassign_statementid" => $this->activity->get_activity()->id,
  1207. "userid" => $USER->id
  1208. )
  1209. );
  1210. if ($iassign_submission) {
  1211. $id_submission = $iassign_submission->id;
  1212. }
  1213. }
  1214. $content = $this->search_comment_submission($id_submission);
  1215. ob_end_clean();
  1216. header("Connection: close\r\n");
  1217. header("Content-Encoding: none\r\n");
  1218. header('Content-Type: text/html');
  1219. ob_start();
  1220. echo $this->search_comment_submission($id_submission);
  1221. $size = ob_get_length();
  1222. header("Content-Length: $size");
  1223. ob_end_flush();
  1224. flush();
  1225. ob_end_clean();
  1226. // Send email to users:
  1227. $iassign_submission =
  1228. $DB->get_record("iassign_submission",
  1229. array(
  1230. "id" => $id_submission
  1231. )
  1232. );
  1233. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1234. }
  1235. /// This method alerts envolved to new comment sent
  1236. function send_alert_new_comment ($comment, $student_id = -1) {
  1237. global $USER, $DB, $COURSE, $SITE;
  1238. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign');
  1239. $url_curso;
  1240. $url_submissao;
  1241. $text = "<p style='margin-top: 1rem;'>";
  1242. $text .= "<a href=\""
  1243. . new moodle_url('/course/view.php', array('id' => $COURSE->id))
  1244. . "\">" . $COURSE->shortname . "</a> "
  1245. . " &#8811; ";
  1246. $modinfo = get_fast_modinfo($COURSE);
  1247. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1248. if ($modinfo->get_section_info($i)
  1249. && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1250. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1251. $text .= "<a href=\""
  1252. . $url_curso . "#section-" . $modinfo->get_section_info($i)->section . "\">" . get_section_name($COURSE, $modinfo->get_section_info($i)->section)
  1253. . "</a> &#8811; ";
  1254. break;
  1255. }
  1256. }
  1257. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1258. $text .= "<a href=\""
  1259. . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id))
  1260. . "\">"
  1261. . $iassign->name
  1262. . "</a>";
  1263. $text .= " &#8811; ";
  1264. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1265. array(
  1266. 'id' => $this->cm->id,
  1267. 'action' => 'viewsubmission',
  1268. 'iassign_current' => $this->activity->get_activity()->id,
  1269. 'userid_iassign' => $USER->id));
  1270. $text .= "<a href=\""
  1271. . $url_submissao
  1272. . "\">"
  1273. . $this->activity->get_activity()->name
  1274. . "</a>";
  1275. $text .= "</p>";
  1276. $text .= "<div style='margin-left: .5rem;'>";
  1277. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>";
  1278. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>";
  1279. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>";
  1280. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>";
  1281. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': '
  1282. . "<a href=\"" . new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">"
  1283. . $USER->firstname . " " . $USER->lastname
  1284. . "</a>";
  1285. $text .= " - " . userdate(time());
  1286. $text .= "</div><div style='margin: 2rem;'>";
  1287. $text .= $comment;
  1288. $text .= "</div><div>";
  1289. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | ";
  1290. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>";
  1291. $text .= "</div>";
  1292. // Who has to receive?
  1293. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1294. $userfrom = \core_user::get_noreply_user();
  1295. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1296. // other teachers receive also: (excepts the sender)
  1297. foreach ($teachers as $teacher) {
  1298. if ($teacher->id != $USER->id)
  1299. email_to_user(
  1300. $teacher,
  1301. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1302. $subject,
  1303. "",
  1304. $text,
  1305. '',
  1306. '',
  1307. false,
  1308. $userfrom->email,
  1309. 'Não responda a esta mensagem'
  1310. );
  1311. }
  1312. // and student:
  1313. $student = $DB->get_record('user', array('id' => $student_id));
  1314. email_to_user(
  1315. $student,
  1316. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1317. $subject,
  1318. "",
  1319. str_replace("viewsubmission", "view", $text),
  1320. '',
  1321. '',
  1322. false,
  1323. $userfrom->email,
  1324. 'Não responda a esta mensagem'
  1325. );
  1326. } else { // a student has sent the comment:
  1327. foreach ($teachers as $teacher) {
  1328. email_to_user(
  1329. $teacher,
  1330. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1331. $subject,
  1332. "",
  1333. $text,
  1334. '',
  1335. '',
  1336. false,
  1337. $userfrom->email,
  1338. 'Não responda a esta mensagem'
  1339. );
  1340. }
  1341. }
  1342. }
  1343. /// This method gets the content from the iLM and register it
  1344. // It could be the "exercise template" (teacher) or an answer (student)
  1345. function get_answer () {
  1346. global $USER, $CFG, $DB, $OUTPUT;
  1347. $id = $this->cm->id;
  1348. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1349. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1350. if ($submission_ajax == 1) ob_start();
  1351. $comment = false;
  1352. if ($submission_comment)
  1353. $comment = $this->write_comment_submission();
  1354. // receives data of iLM using the current activity
  1355. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1356. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1357. // receives data of submission of current activity
  1358. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1359. // receives post and get
  1360. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1361. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1362. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1363. $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)
  1364. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1365. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1366. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1367. $msg = '';
  1368. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1369. $newentry = new stdClass();
  1370. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1371. $newentry->userid = $this->userid_iassign;
  1372. $newentry->timecreated = time();
  1373. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1374. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1375. $DB->insert_record("iassign_allsubmissions", $newentry);
  1376. }
  1377. // Feedback
  1378. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1379. $str_action = "view"; // repeat
  1380. if (strtolower($iassign_ilm->name) == "igeom") {
  1381. }
  1382. $title = get_string('evaluate_iassign', 'iassign');
  1383. print $OUTPUT->header();
  1384. print $OUTPUT->box_start();
  1385. // Action = { view ; repeat ; viewsubmission }
  1386. // * '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")
  1387. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1388. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1389. $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;
  1390. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1391. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1392. print '<table width=100% >';
  1393. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1394. //TODO alterar aqui???
  1395. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1396. // empty_answer_post = No solution was posted.
  1397. if ($comment)
  1398. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1399. else
  1400. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1401. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1402. } else {
  1403. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1404. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1405. // Correct answer!!
  1406. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1407. $this->write_solution = 1; //
  1408. $status = 3;
  1409. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1410. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1411. // log record
  1412. $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;
  1413. // Trigger module viewed event.
  1414. $event = \mod_iassign\event\submission_created::create(array(
  1415. 'objectid' => $this->iassign->id,
  1416. 'context' => $this->context,
  1417. 'other' => $info
  1418. ));
  1419. $event->add_record_snapshot('course', $this->course);
  1420. $event->trigger();
  1421. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1422. // Wrong answer...: get_answer_incorrect
  1423. $status = 2;
  1424. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1425. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1426. // log record
  1427. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1428. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1429. // Trigger module viewed event.
  1430. $event = \mod_iassign\event\submission_created::create(array(
  1431. 'objectid' => $this->iassign->id,
  1432. 'context' => $this->context,
  1433. 'other' => $info
  1434. ));
  1435. $event->add_record_snapshot('course', $this->course);
  1436. $event->trigger();
  1437. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1438. // Presents to the learner the result of the automatic evaluate?
  1439. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1440. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1441. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1442. print '<tr>';
  1443. // log record
  1444. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1445. // Trigger module viewed event.
  1446. $event = \mod_iassign\event\submission_created::create(array(
  1447. 'objectid' => $this->iassign->id,
  1448. 'context' => $this->context,
  1449. 'other' => $info
  1450. ));
  1451. $event->add_record_snapshot('course', $this->course);
  1452. $event->trigger();
  1453. } else { // yes!!!
  1454. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1455. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1456. print '<tr>';
  1457. print $msg;
  1458. }
  1459. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1460. $status = 1;
  1461. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1462. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1463. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1464. print '<tr>';
  1465. // log record
  1466. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1467. $event = \mod_iassign\event\submission_created::create(array(
  1468. 'objectid' => $this->iassign->id,
  1469. 'context' => $this->context,
  1470. 'other' => $info
  1471. ));
  1472. $event->add_record_snapshot('course', $this->course);
  1473. $event->trigger();
  1474. } // if ($iassign_ilm->evaluate == 1)
  1475. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1476. print '</tr></table>';
  1477. print $OUTPUT->box_end();
  1478. // add or update evaluate
  1479. if ($this->write_solution == 1) {
  1480. $timenow = time();
  1481. // new record
  1482. if (!$iassign_submission) {
  1483. $newentry = new stdClass();
  1484. $newentry->userid = $this->userid_iassign;
  1485. // $newentry->userid = $USER->id;
  1486. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1487. $newentry->timecreated = $timenow;
  1488. $newentry->timemodified = $timenow;
  1489. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1490. $newentry->grade = round($grade_student, 2);
  1491. $newentry->status = $status;
  1492. $newentry->experiment = 1;
  1493. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1494. print_error('error_insert', 'iassign');
  1495. } else {
  1496. // Trigger module viewed event.
  1497. $event = \mod_iassign\event\submission_created::create(array(
  1498. 'objectid' => $this->iassign->id,
  1499. 'context' => $this->context
  1500. ));
  1501. $event->add_record_snapshot('course', $this->course);
  1502. $event->trigger();
  1503. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1504. }
  1505. } elseif ($iassign_submission->status != 3) {
  1506. $newentry = new stdClass();
  1507. $newentry->id = $iassign_submission->id;
  1508. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1509. $newentry->userid = $iassign_submission->userid;
  1510. $newentry->timecreated = $iassign_submission->timecreated;
  1511. $newentry->timemodified = $timenow;
  1512. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1513. $newentry->grade = round($grade_student, 2);
  1514. $newentry->status = $status;
  1515. $newentry->experiment = $iassign_submission->experiment + 1;
  1516. if (!$DB->update_record("iassign_submission", $newentry)) {
  1517. print_error('error_update', 'iassign');
  1518. //D depurar...
  1519. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1520. //D $fp = fopen("teste1.txt","w");
  1521. //D fwrite($fp,$stringAux);
  1522. } else {
  1523. // Trigger module viewed event.
  1524. $event = \mod_iassign\event\submission_updated::create(array(
  1525. 'objectid' => $this->iassign->id,
  1526. 'context' => $this->context
  1527. ));
  1528. $event->add_record_snapshot('course', $this->course);
  1529. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1530. }
  1531. } else {
  1532. if ($return_get_answer == 1) {
  1533. $newentry = new stdClass();
  1534. $newentry->id = $iassign_submission->id;
  1535. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1536. $newentry->userid = $iassign_submission->userid;
  1537. $newentry->timecreated = $iassign_submission->timecreated;
  1538. $newentry->timemodified = $timenow;
  1539. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1540. $newentry->grade = round($grade_student, 2);
  1541. $newentry->status = $status;
  1542. $newentry->experiment = $iassign_submission->experiment + 1;
  1543. if (!$DB->update_record("iassign_submission", $newentry))
  1544. print_error('error_update', 'iassign');
  1545. else {
  1546. $event = \mod_iassign\event\submission_updated::create(array(
  1547. 'objectid' => $this->iassign->id,
  1548. 'context' => $this->context
  1549. ));
  1550. $event->add_record_snapshot('course', $this->course);
  1551. $event->trigger();
  1552. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1553. print $OUTPUT->box_start();
  1554. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1555. print $OUTPUT->box_end();
  1556. }
  1557. } elseif ($return_get_answer == 2) {
  1558. print $OUTPUT->box_start();
  1559. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1560. print $OUTPUT->box_end();
  1561. } else {
  1562. print $OUTPUT->box_start();
  1563. print "
  1564. <script type='text/javascript'>
  1565. //<![CDATA[
  1566. function overwrite () {
  1567. document.formEnvio.return_get_answer.value = 1;
  1568. document.formEnvio.submit();
  1569. }
  1570. function nooverwrite () {
  1571. document.formEnvio.return_get_answer.value = 2;
  1572. document.formEnvio.submit();
  1573. }
  1574. //]]>
  1575. </script>";
  1576. $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;
  1577. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1578. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1579. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1580. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1581. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1582. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1583. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1584. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1585. <input type='hidden' name='return_get_answer'/> ";
  1586. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1587. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1588. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1589. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1590. print " </form>";
  1591. print $OUTPUT->box_end();
  1592. }
  1593. }
  1594. } // if ($this->write_solution == 1)
  1595. print $OUTPUT->footer();
  1596. if ($submission_ajax == 1) {
  1597. ob_end_clean();
  1598. print 'OK';
  1599. }
  1600. die();
  1601. } // function get_answer()
  1602. /// Export in file the answer of student.
  1603. function export_file_answer () {
  1604. global $DB;
  1605. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1606. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1607. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1608. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1609. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1610. $extensions = explode(",", $iassign_ilm->extension);
  1611. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1612. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1613. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1614. header("Pragma: public");
  1615. header("Expires: 0");
  1616. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1617. header("Cache-Control: private", false);
  1618. header("Content-Type: document/unknown");
  1619. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1620. set_time_limit(0);
  1621. print($iassign_submission->answer);
  1622. exit;
  1623. } // function export_file_answer()
  1624. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1625. // @calledby $this->export_package_answer()
  1626. //TODO Precisa terminar! //TODO_HTML
  1627. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1628. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1629. <head>
  1630. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1631. $str_html .= " </head>
  1632. <body>\n";
  1633. $tam = sizeof($array_iassign_name);
  1634. for ($ii=0; $ii<$tam; $ii++) {
  1635. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1636. }
  1637. $str_html .= "
  1638. </body>\n</html>";
  1639. return $str_html;
  1640. }
  1641. /// Export an package (zip) with all answer of students
  1642. // @calledby $this->action()
  1643. function export_package_answer () {
  1644. global $DB, $CFG, $OUTPUT;
  1645. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1646. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1647. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1648. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1649. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1650. $userid = optional_param('userid', NULL, PARAM_INT);
  1651. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1652. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1653. //TODO_HTML echo "username=$username<br/>"; exit;
  1654. $current_date = date('Y_m_d_H');
  1655. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1656. // If temporary directory under Moodle data does not exists => create it
  1657. if (!is_dir($diretorio)) {
  1658. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1659. // created directory with permissions to be seen by everyone
  1660. }
  1661. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1662. if (!is_writable($diretorio)) { // send a highlighted message!
  1663. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1664. exit; // just in case
  1665. }
  1666. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1667. $zip = new zip_archive(); // create ZIP
  1668. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1669. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1670. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1671. $vet_student_filename = array();
  1672. $vet_student_content = array();
  1673. foreach ($iassign_statements as $iassign_statement) {
  1674. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1675. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1676. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1677. $extensions = explode(",", $iassign_ilm->extension);
  1678. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1679. if ($iassign_submission) {
  1680. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1681. $student_content = $iassign_submission->answer;
  1682. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1683. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1684. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1685. if ($resp) {
  1686. $vet_student_filename[] = $student_filename;
  1687. $vet_student_content[] = $student_content;
  1688. }
  1689. else { // send a highlighted message!
  1690. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1691. exit; // just in case
  1692. }
  1693. }
  1694. }
  1695. $zip->close(); // close the ZIP file
  1696. if (count($vet_student_filename)>0) {
  1697. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1698. $result_tf = $vet_result[0];
  1699. $filenameZip = $vet_result[1]->filename;
  1700. }
  1701. iassign_utils::download_file($zip_filename); // download the ZIP file
  1702. exit;
  1703. } // function export_package_answer()
  1704. /// Editing status of interactive activities
  1705. function edit_status () {
  1706. global $USER, $DB, $OUTPUT;
  1707. $newentry = new stdClass();
  1708. $newentry->id = $this->iassign_submission_current;
  1709. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1710. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1711. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1712. $newentry->status = $iassign_submission->status;
  1713. $newentry->teacher = $USER->id;
  1714. if (!$DB->update_record('iassign_submission', $newentry))
  1715. print_error('error_update', 'iassign');
  1716. else {
  1717. // Trigger module viewed event.
  1718. $event = \mod_iassign\event\submission_updated::create(array(
  1719. 'objectid' => $this->iassign->id,
  1720. 'context' => $this->context
  1721. ));
  1722. $event->add_record_snapshot('course', $this->course);
  1723. $event->trigger();
  1724. $this->action = 'viewsubmission';
  1725. $this->view_iassign_current();
  1726. } // if (!$DB->update_record('iassign_submission', $newentry))
  1727. } // function edit_status()
  1728. /// Editing grade of interactive activities
  1729. function edit_grade () {
  1730. global $USER, $DB, $OUTPUT;
  1731. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1732. if ($newgrade && $newgrade >= 0) {
  1733. $newentry = new stdClass();
  1734. $newentry->id = $this->iassign_submission_current;
  1735. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1736. $newentry->teacher = $USER->id;
  1737. if (!$DB->update_record('iassign_submission', $newentry))
  1738. print_error('error_update', 'iassign');
  1739. else {
  1740. // Trigger module viewed event.
  1741. $event = \mod_iassign\event\submission_updated::create(array(
  1742. 'objectid' => $this->iassign->id,
  1743. 'context' => $this->context
  1744. ));
  1745. $event->add_record_snapshot('course', $this->course);
  1746. $event->trigger();
  1747. }
  1748. } // if ($newgrade >= 0)
  1749. $this->action = 'viewsubmission';
  1750. $this->view_iassign_current();
  1751. }
  1752. /// Add or Edit interactive activities
  1753. // Get here when editing form and and submitted form data
  1754. // @calledby $this->action()
  1755. function add_edit_iassign () {
  1756. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1757. require_once('iassign_form.php');
  1758. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1759. $iassignid = $this->iassign->id;
  1760. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1761. $param->action = $this->action; // hidden
  1762. $param->id = $id; // hidden
  1763. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1764. $COURSE->cm = $id;
  1765. $COURSE->iassignid = $iassignid;
  1766. $COURSE->iassign_file_id = NULL;
  1767. $context = context_module::instance($this->cm->id);
  1768. $contextuser = context_user::instance($USER->id);
  1769. $component = 'mod_iassign';
  1770. $filearea = 'exercise';
  1771. if (!empty($this->iassign_current))
  1772. $COURSE->iassign_id = $this->iassign_current;
  1773. else
  1774. $COURSE->iassign_id = 0;
  1775. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1776. if ($this->action == 'add') {
  1777. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1778. $params_temp = array('iassignid' => $iassignid);
  1779. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1780. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1781. $total_of_activities = count($iassign_statement);
  1782. $param->iassignid = $iassignid;
  1783. $param->name = "";
  1784. $param->oldname = "";
  1785. $param->type_iassign = 3;
  1786. $param->proposition = "";
  1787. $author = $DB->get_record("user", array("id" => $USER->id));
  1788. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1789. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1790. $param->author = $param->author_name;
  1791. $param->author_modified = $param->author_modified_name;
  1792. $COURSE->iassign_list = array();
  1793. $param->iassign_list = array();
  1794. if ($iassign_statement) {
  1795. foreach ($iassign_statement as $iassign) {
  1796. $iassignid = $iassign->id;
  1797. $param->iassign_list[$iassignid] = 0;
  1798. $COURSE->iassign_list[$iassignid] = new stdClass();
  1799. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1800. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1801. $COURSE->iassign_list[$iassignid]->enable = 1;
  1802. } // foreach ($iassign_statement as $iassign)
  1803. }
  1804. $param->iassign_ilmid = 0;
  1805. $param->file = 0;
  1806. $param->fileold = 0;
  1807. $param->filename = "";
  1808. $param->grade = $iassign_data->grade;
  1809. $param->timemodified = time();
  1810. $param->timecreated = time();
  1811. $param->timeavailable = $iassign_data->timeavailable;
  1812. $param->timedue = $iassign_data->timedue;
  1813. $param->preventlate = $iassign_data->preventlate;
  1814. $param->test = $iassign_data->test;
  1815. $param->special_param1 = 0;
  1816. $param->visible = 1;
  1817. $param->max_experiment = $iassign_data->max_experiment;
  1818. $param->dependency = 0;
  1819. $param->automatic_evaluate = 1;
  1820. $param->show_answer = 1;
  1821. } // if ($this->action == 'add')
  1822. elseif ($this->action == 'edit') {
  1823. $COURSE->iassign_list = array();
  1824. $this_activity = $this->activity->get_activity();
  1825. if ($this_activity != null) { // first enter here: fill form data
  1826. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1827. $param->iassign_id = $iassign_statement_current->id; // oculto
  1828. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1829. $param->name = $iassign_statement_current->name;
  1830. $param->oldname = $iassign_statement_current->name;
  1831. $param->type_iassign = $iassign_statement_current->type_iassign;
  1832. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1833. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1834. $param->author_name = $iassign_statement_current->author_name; // oculto
  1835. $param->author = $iassign_statement_current->author_name;
  1836. $author = $DB->get_record("user", array('id' => $USER->id));
  1837. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1838. $param->author_modified = $param->author_modified_name;
  1839. $dependency = explode(';', $iassign_statement_current->dependency);
  1840. $param->iassign_list = array();
  1841. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1842. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1843. $array_dependency = array();
  1844. $subdependency = "";
  1845. $sub_subdependency = "";
  1846. // Dependents on this exercise
  1847. if ($iassign_statement_dependency) {
  1848. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1849. // to whom this exercise depends
  1850. foreach ($inter as $tmp)
  1851. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1852. $list_dependency = $subdependency . $sub_subdependency;
  1853. $array_dependency = explode(";", $list_dependency);
  1854. }
  1855. // Get all activities in the same iAssigment block:
  1856. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  1857. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1858. $total_of_activities = count($all_others_iassign_statement) + 1;
  1859. $inter = array();
  1860. if ($all_others_iassign_statement) {
  1861. foreach ($all_others_iassign_statement as $iassign)
  1862. if (in_array($iassign->id, $dependency))
  1863. $inter[] = $iassign->id;
  1864. }
  1865. if ($all_others_iassign_statement) {
  1866. foreach ($all_others_iassign_statement as $iassign) {
  1867. $iassignid = $iassign->id;
  1868. $COURSE->iassign_list[$iassignid] = new stdClass();
  1869. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1870. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1871. if (in_array($iassignid, $dependency))
  1872. $param->iassign_list[$iassignid] = 1;
  1873. else
  1874. $param->iassign_list[$iassignid] = 0;
  1875. if (in_array($iassignid, $array_dependency))
  1876. $COURSE->iassign_list[$iassignid]->enable = 0;
  1877. else
  1878. $COURSE->iassign_list[$iassignid]->enable = 1;
  1879. } // foreach ($all_others_iassign_statement as $iassign)
  1880. } // if ($all_others_iassign_statement)
  1881. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  1882. $param->fileold = 0;
  1883. $param->filesid = 0;
  1884. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1885. $param->filename = '';
  1886. $param->grade = $iassign_statement_current->grade;
  1887. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  1888. $param->timeavailable = $iassign_statement_current->timeavailable;
  1889. $param->timedue = $iassign_statement_current->timedue;
  1890. $param->preventlate = $iassign_statement_current->preventlate;
  1891. $param->test = $iassign_statement_current->test;
  1892. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  1893. $param->position = $iassign_statement_current->position; // hidden
  1894. $param->visible = $iassign_statement_current->visible;
  1895. $param->max_experiment = $iassign_statement_current->max_experiment;
  1896. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1897. $param->show_answer = $iassign_statement_current->show_answer;
  1898. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1899. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  1900. if ($files) {
  1901. foreach ($files as $file) {
  1902. if ($file->get_filename() != '.') {
  1903. $param->filename = $file->get_filename();
  1904. $param->file = $file->get_id();
  1905. $param->fileold = $file->get_id();
  1906. $COURSE->iassign_file_id = $file->get_id();
  1907. }
  1908. }
  1909. }
  1910. //TODO //MOOC2014 -- inicio
  1911. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1912. //D if ($iassign_ilm_configs) {
  1913. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1914. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1915. //D } //MOOC2014 -- fim
  1916. } // if ($this_activity != null)
  1917. } // elseif ($this->action == 'edit')
  1918. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1919. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1920. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1921. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1922. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1923. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1924. $param->position = $total_of_activities;
  1925. // Create form and associate its data
  1926. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  1927. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  1928. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  1929. if (isset($param->iassign_ilmid)) {
  1930. // array is additional atributes to 'form'
  1931. // '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)"
  1932. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  1933. }
  1934. else {
  1935. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  1936. }
  1937. $mform->set_data($param); // define data in the form
  1938. if ($mform->is_cancelled()) {
  1939. $this->return_home_course('iassign_cancel');
  1940. exit;
  1941. }
  1942. else { // else if ($mform->is_cancelled())
  1943. $result = $mform->get_data();
  1944. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1945. if ($result) {
  1946. $result->context = $context;
  1947. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1948. $result->grade = 0;
  1949. if ($result->type_iassign == 1) {
  1950. $result->automatic_evaluate = 0;
  1951. $result->show_answer = 0;
  1952. }
  1953. elseif ($result->automatic_evaluate == 0)
  1954. $result->show_answer = 0;
  1955. // $_POST['iassign_list']
  1956. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1957. if ($result->iassign_list) {
  1958. foreach ($result->iassign_list as $key => $value)
  1959. $result->dependency .= $key . ';';
  1960. }
  1961. else
  1962. $result->dependency = 0;
  1963. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1964. //TODO Then get it directly from the form data $_POST!
  1965. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1966. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1967. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1968. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1969. if ($this->action == 'add') {
  1970. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1971. if ($iassign_statement_name) {
  1972. $this->return_home_course('error_iassign_name');
  1973. die();
  1974. }
  1975. // Really insert the new iActivity in table '*_iassign_statement'
  1976. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1977. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1978. // Trigger module viewed event.
  1979. $event = \mod_iassign\event\iassign_created::create(array(
  1980. 'objectid' => $iassignid,
  1981. 'context' => $context
  1982. ));
  1983. $event->add_record_snapshot('course', $this->course);
  1984. $event->trigger();
  1985. $this->return_home_course('iassign_add');
  1986. } // if ($this->action == 'add')
  1987. elseif ($this->action == 'edit') {
  1988. $iassignid = $this->activity->update_iassign($result);
  1989. $this->activity->update_calendar($iassignid, $result->oldname);
  1990. // Trigger module viewed event.
  1991. $event = \mod_iassign\event\iassign_updated::create(array(
  1992. 'objectid' => $iassignid,
  1993. 'context' => $context
  1994. ));
  1995. $event->add_record_snapshot('course', $this->course);
  1996. $event->trigger();
  1997. $this->return_home_course('iassign_update');
  1998. } // elseif ($this->action == 'edit')
  1999. die();
  2000. } // if ($result)
  2001. } // else if ($mform->is_cancelled())
  2002. print $OUTPUT->header();
  2003. $mform->display();
  2004. print $OUTPUT->footer();
  2005. die();
  2006. } // function add_edit_iassign()
  2007. /// Search for dependencies
  2008. function search_dependency ($search_iassing_id, $iassign_statement) {
  2009. global $DB, $OUTPUT;
  2010. $dependency = "";
  2011. if ($iassign_statement)
  2012. foreach ($iassign_statement as $iassign) {
  2013. $inter_dependency = explode(';', $iassign->dependency);
  2014. if (in_array($search_iassing_id, $inter_dependency)) {
  2015. $dependency .= $iassign->id . ";";
  2016. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2017. } // if (in_array($search_iassing_id, $inter_dependency))
  2018. } // foreach ($iassign_statement as $iassign)
  2019. return $dependency;
  2020. }
  2021. /// Search for "sub"dependency
  2022. function search_sub_dependency ($search_iassing_id) {
  2023. global $DB, $OUTPUT;
  2024. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2025. $dependency = "";
  2026. if ($iassign_statement) {
  2027. $inter_dependency = explode(';', $iassign_statement->dependency);
  2028. foreach ($inter_dependency as $tmp) {
  2029. if ($tmp != 0)
  2030. $dependency .= $tmp . ";";
  2031. $dependency .= $this->search_sub_dependency($tmp);
  2032. } // foreach ($inter_dependency as $tmp)
  2033. } // if ($iassign_statement)
  2034. return $dependency;
  2035. }
  2036. // Warning message
  2037. static function warning_message_iassign ($strcode) {
  2038. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2039. }
  2040. /// Update grade of iAssign
  2041. // Called always any iAssign activity is created
  2042. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2043. static function update_grade_iassign ($iassignid) {
  2044. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2045. require_once($CFG->libdir . '/gradelib.php');
  2046. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2047. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2048. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2049. // Each iAssign item is associated with one item on the "gradebook"
  2050. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2051. //$sum_grade = 0;
  2052. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2053. //foreach($grade as $tmp) {
  2054. // $sum_grade += $tmp->grade;
  2055. // }
  2056. //1 Solution 1
  2057. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2058. //1 $sum_grade = 0; //1
  2059. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2060. //2 Solution 2
  2061. $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
  2062. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2063. if (key($array_sum_grade))
  2064. $sum_grade = key($array_sum_grade); //2
  2065. else
  2066. $sum_grade = 0; //2
  2067. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2068. $grades = NULL;
  2069. $params_temp = array('itemname' => $grade_iassign->name);
  2070. $params_temp['iteminstance'] = $iassignid;
  2071. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2072. //2016 if ($sum_grade != 0) {
  2073. $params_temp['grademax'] = $sum_grade;
  2074. $params_temp['rawgrademax'] = $sum_grade;
  2075. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2076. $params_temp['grademin'] = 0;
  2077. // @calls /lib/gradelib.php: call to grade_item->insert()
  2078. //TODO: is there any error here in Moodle version 3.0?
  2079. //TODO: Incorrect property 'grademax' found when inserting grade object
  2080. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2081. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2082. }
  2083. /// Update grade of student
  2084. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2085. global $CFG, $DB, $OUTPUT;
  2086. require_once($CFG->libdir . '/gradelib.php');
  2087. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2088. // Review all the student submission for this iAssign activity
  2089. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2090. $total_grade = 0;
  2091. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2092. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2093. if ($iassign_submission)
  2094. $total_grade += $iassign_submission->grade;
  2095. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2096. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2097. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2098. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2099. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2100. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2101. $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
  2102. if (key($array_sum_grade))
  2103. $sum_grade = key($array_sum_grade); //2
  2104. else
  2105. $sum_grade = 0; //2
  2106. $grades['userid'] = $userid;
  2107. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2108. $params_temp = array('itemname' => $grade_iassign->name);
  2109. $params_temp['iteminstance'] = $iassignid;
  2110. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2111. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2112. $params_temp['grademax'] = $sum_grade;
  2113. $params_temp['rawgrademax'] = $sum_grade;
  2114. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2115. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2116. }
  2117. /// Display caption of icons
  2118. function view_legend_icons () {
  2119. global $USER, $CFG, $DB, $OUTPUT;
  2120. $id = $this->cm->id;
  2121. if ($this->action == 'print')
  2122. print '<table border=1 width=100%><tr>';
  2123. else
  2124. print '<table width=100%><tr>';
  2125. print '<td >';
  2126. if ($this->action != 'print')
  2127. print $OUTPUT->help_icon('legend', 'iassign');
  2128. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2129. // $imagetext = '');
  2130. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  2131. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  2132. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  2133. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  2134. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  2135. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  2136. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2137. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  2138. print '</td>' . "\n";
  2139. if ($this->action != 'print') {
  2140. $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>";
  2141. $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>";
  2142. $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>";
  2143. $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>";
  2144. $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>";
  2145. print '<td width=10% align="right">' . $link_stats . '</td>' . "\n";
  2146. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2147. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  2148. print '<td width=16% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  2149. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2150. } // if ($this->action != 'print')
  2151. print '</tr></table>' . "\n";
  2152. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2153. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  2154. $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>";
  2155. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  2156. print '</tr></table>' . "\n";
  2157. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2158. else
  2159. print '</td></tr></table>' . "\n";
  2160. } // function view_legend_icons()
  2161. /// Display activity current
  2162. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2163. function view_iassign_current () {
  2164. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2165. $id = $this->cm->id;
  2166. $iassignid = $this->iassign->id;
  2167. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2168. $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
  2169. // 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 ...
  2170. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2171. if (!$iassign_statement_activity_item) {
  2172. print $OUTPUT->header();
  2173. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2174. print $OUTPUT->footer();
  2175. exit;
  2176. }
  2177. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2178. $ilm_name = '';
  2179. if ($ilm->ilm)
  2180. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2181. // 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
  2182. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2183. // log record
  2184. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2185. //Trigger module viewed event.
  2186. $event = \mod_iassign\event\submission_viewed::create(array(
  2187. 'objectid' => $iassign->id,
  2188. 'context' => $this->context,
  2189. 'other' => $info
  2190. ));
  2191. $event->add_record_snapshot('course', $this->course);
  2192. $event->trigger();
  2193. // Search of iLM data used in the current activity
  2194. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2195. // Add actual activity to navbar:
  2196. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2197. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2198. print $OUTPUT->header();
  2199. if ($this->action == 'viewsubmission') {
  2200. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2201. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2202. else
  2203. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2204. } else {
  2205. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2206. }
  2207. if ($iassign_submission)
  2208. $this->update_comment($iassign_submission->id);
  2209. $file = $iassign_statement_activity_item->filesid;
  2210. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2211. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2212. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2213. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2214. $this->bottonPost = 0; // hide submit button
  2215. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2216. $this->view_iassign = false; // disable visualization of activity
  2217. $repeat = "";
  2218. $last_iassign = "";
  2219. $student_answer = "";
  2220. $comment = "";
  2221. // *** Teacher access (view learner's submission)
  2222. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2223. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2224. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2225. // ---> access teacher for test
  2226. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2227. $this->bottonPost = 1;
  2228. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2229. $this->activity->view_dates();
  2230. $USER->iassignEdit = $this->bottonPost;
  2231. $this->activity->show_info_iassign();
  2232. if ($iassign_submission) {
  2233. //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;
  2234. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2235. } else {
  2236. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2237. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2238. }
  2239. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2240. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2241. // Prepare tags to present the iLM
  2242. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2243. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2244. // *** (end) Teacher access (view the activity)
  2245. // *** Teacher access (view learner's submission to the activity)
  2246. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2247. // It is teacher or 'nonediting teacher' that can evaluate
  2248. // ----> area teacher evaluate
  2249. $row = optional_param('row', 0, PARAM_INT);
  2250. $column = optional_param('column', 0, PARAM_INT);
  2251. $link_next = iassign_icons::insert('right_disable');
  2252. $link_previous = iassign_icons::insert('left_disable');
  2253. $link_up = iassign_icons::insert('up_disable');
  2254. $link_down = iassign_icons::insert('down_disable');
  2255. // next_activity
  2256. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2257. $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);
  2258. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2259. }
  2260. // previous_activity
  2261. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2262. $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);
  2263. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2264. }
  2265. // previous_student
  2266. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2267. $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);
  2268. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2269. }
  2270. // next_student
  2271. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2272. $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);
  2273. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2274. }
  2275. if ($iassign_submission) {
  2276. $student_answer = $iassign_submission->answer;
  2277. }
  2278. $last_iassign = get_string('last_iassign', 'iassign');
  2279. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2280. // Messages related to due date (and user role)
  2281. $this->activity->view_dates();
  2282. print $OUTPUT->box_start();
  2283. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2284. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2285. print $OUTPUT->user_picture($user_data);
  2286. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2287. print '</td>' . "\n";
  2288. print '<td width=20% align=right>' . "\n";
  2289. print '<table width=50 cellpadding="0">';
  2290. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2291. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2292. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2293. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2294. print '</table>' . "\n";
  2295. print '</td></tr></table>' . "\n";
  2296. print $OUTPUT->box_end();
  2297. print $OUTPUT->box_start();
  2298. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2299. print '<td width=60% valign="top">' . "\n";
  2300. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2301. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2302. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2303. $resp = get_string('yes');
  2304. else
  2305. $resp = get_string('no');
  2306. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2307. if ($iassign_statement_activity_item->show_answer == 1)
  2308. $resp = get_string('yes');
  2309. else
  2310. $resp = get_string('no');
  2311. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2312. print '</td>';
  2313. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2314. print '<td width=40% valign="top" align="left">';
  2315. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2316. // check status of solution sent by the student
  2317. if ($iassign_submission) {
  2318. switch ($iassign_submission->status) {
  2319. case 3 :
  2320. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2321. break;
  2322. case 2 :
  2323. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2324. break;
  2325. case 1 :
  2326. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2327. break;
  2328. default :
  2329. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2330. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2331. } // switch ($iassign_submission->status)
  2332. }
  2333. else { // if ($iassign_submission)
  2334. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2335. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2336. }
  2337. // update_status
  2338. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2339. $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);
  2340. print " <script type='text/javascript'>
  2341. //<![CDATA[
  2342. function overwriteStatus (newstatus) {
  2343. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2344. document.formEditStatus.return_status.value=newstatus;
  2345. document.formEditStatus.submit();
  2346. }
  2347. else
  2348. document.formEditStatus.return_status.value=-1;
  2349. }
  2350. //]]>
  2351. </script>";
  2352. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2353. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2354. 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";
  2355. print " <input type='hidden' name='return_status'>\n";
  2356. print "</form>\n";
  2357. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2358. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2359. $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);
  2360. print "
  2361. <script type='text/javascript'>
  2362. //<![CDATA[
  2363. function overwriteGrade (newgrade,maxgrade) {
  2364. if (newgrade<0 || newgrade>maxgrade) {
  2365. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2366. document.formEditGrade.return_grade.value=-1;
  2367. document.formEditGrade.submit();
  2368. }
  2369. else {
  2370. document.formEditGrade.return_grade.value=newgrade;
  2371. document.formEditGrade.submit();
  2372. }
  2373. }
  2374. //]]>
  2375. </script>";
  2376. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2377. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2378. print " <input type='text' name='grade' size='6'>";
  2379. print " <input type='hidden' name='return_grade'> ";
  2380. 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";
  2381. print "</form>";
  2382. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2383. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2384. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2385. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2386. if ($teacher)
  2387. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2388. } // if ($iassign_submission->experiment > 0)
  2389. print '</td>';
  2390. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2391. print '</tr></table>';
  2392. print $OUTPUT->box_end();
  2393. $USER->iassignEdit = $this->bottonPost;
  2394. print activity::toggle_columns_script();
  2395. if ($iassign_submission && $allow_resubmission) {
  2396. // Put the iLM to
  2397. print $OUTPUT->box_start();
  2398. print '<p><strong>' . $last_iassign . '</strong></p>';
  2399. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2400. $enderecoPOST = "";
  2401. // Prepare tags to present the iLM
  2402. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2403. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2404. print $OUTPUT->box_end();
  2405. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2406. // ATTENTION: exception used by iGeom (exercise with "script")
  2407. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2408. if (substr($ilm_name, 0, 5)=="igeom") {
  2409. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2410. $loadTeacherActivity = true;
  2411. }
  2412. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2413. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2414. print activity::toggle_columns_script();
  2415. // Prepare tags to present the iLM
  2416. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2417. }
  2418. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2419. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2420. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2421. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2422. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2423. // *** (end) Teacher access (view learner's submission to the activity)
  2424. // *** Student access (view the activity)
  2425. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2426. // It could be the learner (he could send or resend the activity)
  2427. // ---> access student
  2428. $time_now = time();
  2429. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2430. // activity of type example - not submit button for submission
  2431. $this->view_iassign = true;
  2432. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2433. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2434. // activity of type test - iLM automatic evaluator - submit button for submission
  2435. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2436. $this->bottonPost = 1;
  2437. $this->view_iassign = true;
  2438. } else
  2439. $this->view_iassign = false;
  2440. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2441. // activity of type exercise (learner can send his answer, if yet open...)
  2442. $this->view_iassign = true;
  2443. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2444. $this->view_iassign = false;
  2445. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2446. $this->bottonPost = 1; // allow the submit button
  2447. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2448. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2449. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2450. if (!$iassign_submission) {
  2451. $str_iassign_submission_id = '';
  2452. $str_iassign_submission_answer = '';
  2453. }
  2454. else {
  2455. $str_iassign_submission_id = $iassign_submission->id;
  2456. $str_iassign_submission_answer = $iassign_submission->answer;
  2457. }
  2458. if ($this->action != 'repeat') {
  2459. $repeat = "<a href='view.php?action=repeat&id="
  2460. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2461. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2462. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2463. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2464. }
  2465. $this->bottonPost = 1;
  2466. $this->write_solution = 1; // can register his submission
  2467. $student_answer = $str_iassign_submission_answer;
  2468. }
  2469. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2470. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2471. $last_iassign = get_string('last_iassign', 'iassign');
  2472. if ($iassign_submission) {
  2473. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2474. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2475. $student_answer = $iassign_submission->answer;
  2476. } else {
  2477. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2478. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2479. }
  2480. }
  2481. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2482. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2483. $this->bottonPost = 1;
  2484. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2485. } else {
  2486. $last_iassign = get_string('last_iassign', 'iassign');
  2487. if ($iassign_submission) {
  2488. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2489. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2490. $student_answer = $iassign_submission->answer;
  2491. } else {
  2492. // Symbol of "redo activity"
  2493. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2494. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2495. }
  2496. }
  2497. } // elseif ($iassign_statement_activity_item->test == 1)
  2498. elseif ($iassign_statement_activity_item->test == 0)
  2499. $this->view_iassign = false;
  2500. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2501. if ($iassign_submission)
  2502. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2503. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2504. else
  2505. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2506. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2507. $this->activity->view_dates();
  2508. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2509. print $OUTPUT->box_start();
  2510. print '<table width=100% border=0 valign="top">' . "\n";
  2511. print '<tr><td width=60% valign="top">' . "\n";
  2512. $flag_dependency = true;
  2513. if ($iassign_statement_activity_item->type_iassign == 3) {
  2514. if ($iassign_statement_activity_item->dependency == 0) {
  2515. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2516. } else {
  2517. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2518. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2519. foreach ($dependencys as $dependency) {
  2520. if ($dependency) {
  2521. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2522. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2523. if ($dependencysubmissions) {
  2524. if ($dependencysubmissions->status == 3)
  2525. $icon = iassign_icons::insert('correct');
  2526. elseif ($dependencysubmissions->status == 2) {
  2527. $icon = iassign_icons::insert('incorrect');
  2528. $flag_dependency = false;
  2529. } elseif ($dependencysubmissions->status == 1) {
  2530. $icon = iassign_icons::insert('post');
  2531. $flag_dependency = false;
  2532. } elseif ($dependencysubmissions->status == 0) {
  2533. $icon = iassign_icons::insert('not_post');
  2534. $flag_dependency = false;
  2535. }
  2536. } else {
  2537. $icon = iassign_icons::insert('not_post');
  2538. $flag_dependency = false;
  2539. } // if ($dependencysubmissions)
  2540. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2541. } // if ($dependency)
  2542. } // foreach ($dependencys as $dependency)
  2543. } // if ($iassign_statement_activity_item->dependency == 0)
  2544. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2545. if ($flag_dependency == false) {
  2546. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2547. $this->view_iassign = false;
  2548. print '</tr></table>' . "\n";
  2549. }
  2550. else {
  2551. $this->view_iassign = true;
  2552. print '</td>' . "\n";
  2553. } // if ($flag_dependency == false)
  2554. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2555. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2556. // receiver=1 - message to teacher
  2557. // receiver=2 - message to student
  2558. if ($iassign_submission) {
  2559. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2560. if ($verify_message)
  2561. $comment = iassign_icons::insert('comment_unread');
  2562. }
  2563. print '<td width=40% valign="top" align="left">';
  2564. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2565. if ($iassign_statement_activity_item->show_answer == 1) {
  2566. // check status of solution sent by the student
  2567. if ($iassign_submission) {
  2568. switch ($iassign_submission->status) {
  2569. case 3 :
  2570. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2571. break;
  2572. case 2 :
  2573. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2574. break;
  2575. case 1 :
  2576. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2577. break;
  2578. default :
  2579. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2580. $repeat = "";
  2581. $last_iassign = "";
  2582. } // switch ($iassign_submission->status)
  2583. } else {
  2584. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2585. $repeat = "";
  2586. $last_iassign = "";
  2587. }
  2588. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2589. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2590. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2591. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2592. if ($iassign_statement_activity_item->max_experiment == 0)
  2593. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2594. else {
  2595. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2596. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2597. $repeat = "";
  2598. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2599. $this->bottonPost = 0;
  2600. $this->write_solution = 0;
  2601. }
  2602. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2603. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2604. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2605. if ($teacher)
  2606. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2607. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2608. } // if ($iassign_statement_activity_item->show_answer==1)
  2609. else {
  2610. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2611. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2612. $repeat = "";
  2613. $last_iassign = "";
  2614. } elseif ($iassign_submission->status == 1) {
  2615. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2616. }
  2617. }
  2618. print '</td>';
  2619. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2620. print '</tr></table>' . "\n";
  2621. // Presents the iLM
  2622. print '<table width=100% border=0 valign="top">' . "\n";
  2623. print '<td width=80% align="left">';
  2624. 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\".
  2625. print '<td width=20% align="rigth">';
  2626. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2627. print $repeat; // symbol of "redo activity"
  2628. print '</td></tr></table>' . "\n";
  2629. //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)'
  2630. print activity::toggle_columns_script();
  2631. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2632. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2633. $output = '';
  2634. if (!$iassign_ilm) {
  2635. $iassign_ilm = new stdClass();
  2636. $iassign_ilm->file_jar = "";
  2637. }
  2638. $output .= $OUTPUT->box_start();
  2639. $USER->iassignEdit = $this->bottonPost;
  2640. // ---
  2641. // Presents the iLM
  2642. // Prepare tags to present the iLM
  2643. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2644. $student_answer = ""; //?
  2645. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2646. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2647. $student_answer = "";
  2648. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2649. } else {
  2650. // When student is redoing his activity
  2651. // ATTENTION: exception used by iGeom (exercise with "script")
  2652. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2653. if (substr($ilm_name, 0, 5)=="igeom") {
  2654. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2655. $loadTeacherActivity = true;
  2656. }
  2657. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2658. }
  2659. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2660. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2661. //1 $history_comment = '';
  2662. //1 if ($iassign_submission) {
  2663. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2664. //1 }
  2665. //1 if (!empty($history_comment)) {
  2666. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2667. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2668. //1 $output .= $history_comment;
  2669. //1 $output .= "</table>\n";
  2670. //1 }
  2671. //1 $output .= "</form></center>\n";
  2672. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2673. //1 }
  2674. $output .= $OUTPUT->box_end();
  2675. print $output;
  2676. } // if ($this->view_iassign)
  2677. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2678. } // if ($this->view_iassign)
  2679. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2680. else
  2681. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2682. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2683. print '<table width=100% border=0 valign="top">' . "\n";
  2684. print '<tr><td width=60% valign="top">' . "\n";
  2685. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2686. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2687. print '</tr></table>' . "\n";
  2688. $student_answer = "";
  2689. $enderecoPOST = "";
  2690. // Prepare tags to present the iLM
  2691. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2692. print $output;
  2693. }
  2694. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2695. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2696. 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
  2697. // Put a block with area to sent/answer comments
  2698. $output = '';
  2699. $history_comment = '';
  2700. $row = optional_param('row', 0, PARAM_INT);
  2701. $column = optional_param('column', 0, PARAM_INT);
  2702. if ($iassign_submission) {
  2703. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2704. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2705. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2706. }
  2707. else {
  2708. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2709. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2710. }
  2711. $output .= $OUTPUT->box_start();
  2712. //if (!empty($history_comment)) {
  2713. $output .= "<a id='comments'></a>";
  2714. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2715. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2716. $output .= "</table>";
  2717. print " <script type='text/javascript'>
  2718. //<![CDATA[
  2719. function submit_comment(url) {
  2720. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2721. var formData = new FormData();
  2722. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2723. var request = new XMLHttpRequest();
  2724. request.open('POST', url);
  2725. document.getElementById('comments_history').innerHTML = '';
  2726. request.onload = function (e) {
  2727. if (request.readyState === 4) {
  2728. if (request.status === 200) {
  2729. document.getElementById('comments_history').innerHTML = request.responseText;
  2730. document.getElementById('check-message-success').style.visibility = 'visible';
  2731. setTimeout(function(){
  2732. document.getElementById('check-message-success').style.visibility = 'hidden';
  2733. }, 3000);
  2734. }
  2735. }
  2736. };
  2737. document.formEnvioComment.submission_comment.value = '';
  2738. request.send(formData);
  2739. }
  2740. //]]>
  2741. </script>";
  2742. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2743. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2744. $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";
  2745. $output .= "</form> </center>\n";
  2746. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2747. // }
  2748. $output .= $OUTPUT->box_end();
  2749. print $output;
  2750. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2751. // final block 'studant'
  2752. print $OUTPUT->footer();
  2753. die();
  2754. } // function view_iassign_current()
  2755. /// Export the data from performance report into CSV file format
  2756. function export_csv () {
  2757. global $USER, $CFG, $DB, $OUTPUT;
  2758. $str = "";
  2759. $fields = "student_id, student_name";
  2760. // Finding all iassign activities for the iassign:
  2761. $id = $this->cm->id;
  2762. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2763. $c = 1;
  2764. foreach ($iassign_list as $iassign) {
  2765. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2766. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2767. $c ++;
  2768. }
  2769. // Finding enrolled students:
  2770. $params_temp = array('shortname' => 'student');
  2771. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2772. $context = context_course::instance($this->course->id);
  2773. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2774. $students = $DB->get_records_sql(
  2775. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2776. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2777. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2778. foreach ($students as $student) {
  2779. $str .= $student->userid . ',';
  2780. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2781. foreach ($iassign_list as $iassign) {
  2782. $str .= ',' . $iassign->id . ',';
  2783. $str .= '"' . $iassign->name . '",';
  2784. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2785. if ($student_submissions) {
  2786. $str .= $student_submissions->experiment . ',';
  2787. $str .= $student_submissions->grade . ',';
  2788. switch ($student_submissions->status) {
  2789. case 3:
  2790. $str .= '"correct",';
  2791. break;
  2792. case 2:
  2793. $str .= '"incorrect",';
  2794. break;
  2795. case 1:
  2796. $str .= '"post",';
  2797. break;
  2798. case 0:
  2799. $str .= '"not_post",';
  2800. break;
  2801. }
  2802. }
  2803. else {
  2804. $str .= ',,"not_post",';
  2805. }
  2806. $str .= $iassign->iassign_ilmid . ',';
  2807. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2808. $str .= '"' . $ilm_activity->name . '"';
  2809. }
  2810. $str .= "\n";
  2811. }
  2812. $str = $fields . "\n" . $str;
  2813. header("Content-type: text/csv");
  2814. header("Content-disposition: attachment; filename=report.csv");
  2815. header("Pragma: no-cache");
  2816. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2817. header('Content-Length: ' . strlen($str));
  2818. header('Connection: close');
  2819. print $str;
  2820. flush();
  2821. } // function export_csv()
  2822. /// Display report of performance
  2823. function report () {
  2824. global $USER, $CFG, $DB, $OUTPUT;
  2825. $id = $this->cm->id;
  2826. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2827. if ($this->action != 'print') {
  2828. $title = get_string('report', 'iassign');
  2829. print $OUTPUT->header();
  2830. } // if ($this->action != 'print')
  2831. print $OUTPUT->box_start();
  2832. $this->view_legend_icons();
  2833. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2834. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2835. print $OUTPUT->box_end();
  2836. if ($this->action == 'print')
  2837. print '<table border=1 width="100%">' . "\n";
  2838. else
  2839. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped" width="100%">' . "\n";
  2840. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2841. // $num = array();
  2842. $i = 1;
  2843. $num = array();
  2844. $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;";
  2845. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2846. $test_exercise = "";
  2847. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2848. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2849. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2850. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2851. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2852. $num[$i] = new stdClass();
  2853. $num[$i]->name = $iassign->name;
  2854. $num[$i]->id = $i;
  2855. $num[$i]->iassignid = $iassign->id;
  2856. print ' <tr >' . "\n";
  2857. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2858. print "<td class=\"cell c0 actvity\">";
  2859. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2860. print ' </tr>' . "\n";
  2861. $i++;
  2862. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2863. } // foreach ($iassign_list as $iassign)
  2864. $num_exerc = $i; // total of exercises
  2865. print "</table>";
  2866. print "<p></p>";
  2867. if ($this->action == 'print')
  2868. print '<table border=1 width="100%">' . "\n";
  2869. else // ./theme/boost/style/moodle.css: .generaltable
  2870. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  2871. $context = context_course::instance($this->course->id);
  2872. if ($num_exerc > 1) {
  2873. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2874. $params_temp = array('shortname' => 'student');
  2875. $role = $DB->get_record_sql(
  2876. "SELECT s.id, s.shortname FROM {role} s " .
  2877. " WHERE s.shortname = :shortname", $params_temp);
  2878. // $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");
  2879. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2880. $students = $DB->get_records_sql(
  2881. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2882. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2883. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2884. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2885. $width = 90/$num_exerc;
  2886. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  2887. $sum_iassign_correct[$j] = 0;
  2888. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2889. }
  2890. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2891. $sum_iassign = $j - 1;
  2892. print '</tr>' . "\n";
  2893. $total = 0;
  2894. $sum_student = 0;
  2895. $comment = iassign_icons::insert('comment_read');
  2896. $sum_comment = 0;
  2897. $sum_correct_iassign = array();
  2898. $sum_correct_student = array();
  2899. $USER->matrix_iassign = array();
  2900. if ($students) {
  2901. $w = 0;
  2902. foreach ($students as $tmp) { // count students
  2903. $users_array[$w] = $tmp;
  2904. $w++;
  2905. }
  2906. for ($x=0; $x<$w; $x++) { // for all students
  2907. print '<tr>' . "\n";
  2908. $sum_student ++;
  2909. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2910. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  2911. $total_student = 0;
  2912. $tentativas = 0;
  2913. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  2914. $sum_comment = $sum_verify_message = 0;
  2915. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2916. if ($student_submissions) {
  2917. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2918. $tentativas = $student_submissions->experiment;
  2919. // Get student comments
  2920. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2921. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  2922. $student_submissions_comment = $DB->get_record_sql(
  2923. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2924. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  2925. if ($student_submissions_comment) // student has comment
  2926. foreach ($student_submissions_comment as $tmp)
  2927. $sum_comment = $tmp;
  2928. // informations to previous activities
  2929. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  2930. else $iassign_previous = $num[$j - 1]->iassignid;
  2931. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2932. else $user_previous = $users_array[$x - 1]->userid;
  2933. // next
  2934. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2935. else $iassign_next = "-1";
  2936. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2937. else $user_next = "-1";
  2938. $position = "&row= $x&column=$j";
  2939. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2940. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2941. $url .= $position;
  2942. // receiver=1 - message to teacher
  2943. // receiver=2 - message to student
  2944. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2945. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2946. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2947. $verify_message = $DB->get_record_sql(
  2948. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2949. "WHERE iassign_submissionid = :iassign_submissionid " .
  2950. " AND return_status= :return_status " .
  2951. " AND receiver= :receiver", $params_temp);
  2952. if ($verify_message)
  2953. foreach ($verify_message as $tmp)
  2954. $sum_verify_message = $tmp;
  2955. if ($sum_verify_message > 0)
  2956. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  2957. else
  2958. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  2959. if ($student_submissions->status == 3) {
  2960. $sum_iassign_correct[$j] ++;
  2961. $total_student ++;
  2962. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  2963. }
  2964. elseif ($student_submissions->status == 2) {
  2965. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  2966. }
  2967. elseif ($student_submissions->status == 1) {
  2968. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2969. }
  2970. elseif ($student_submissions->status == 0) {
  2971. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2972. }
  2973. if ($this->action != 'print') {
  2974. if ($tentativas > 0)
  2975. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2976. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2977. . $feedback
  2978. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2979. . $tentativas
  2980. . '</span> </button>'
  2981. . '</a>' . "\n";
  2982. else
  2983. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2984. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2985. . $feedback
  2986. .'</button>'
  2987. . '</a>' . "\n";
  2988. if ($sum_comment > 0 && $sum_verify_message > 0)
  2989. print '<a href="' . $url . '"> '
  2990. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2991. . $comment
  2992. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2993. . $sum_verify_message . '/' . $sum_comment
  2994. . '</span> </button>'
  2995. . '</a>';
  2996. else if ($sum_comment > 0)
  2997. print '<a href="' . $url . '"> '
  2998. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  2999. . $comment
  3000. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3001. . $sum_comment
  3002. . '</span> </button>'
  3003. . '</a>';
  3004. print '</td>' . "\n";
  3005. }
  3006. if ($this->action == 'print')
  3007. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3008. } // if ($student_submissions)
  3009. else { // if ($student_submissions)
  3010. // Student does not have any submission
  3011. // informations to browse previous activities
  3012. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3013. else $iassign_previous = $num[$j - 1]->iassignid;
  3014. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3015. else $user_previous = $users_array[$x - 1]->userid;
  3016. // next
  3017. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3018. else $iassign_next = "-1";
  3019. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3020. else $user_next = "-1";
  3021. $position = "&row= $x&column=$j";
  3022. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3023. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3024. $url .= $position;
  3025. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3026. if ($this->action == 'print')
  3027. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3028. else {
  3029. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3030. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3031. . $feedback
  3032. .'</button>'
  3033. . '</a>' . "\n";
  3034. // print '<td> &nbsp;</td>';
  3035. if ($sum_comment > 0)
  3036. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3037. // else print '<td> &nbsp;</td>';
  3038. print '</td>';
  3039. }
  3040. } // else if ($student_submissions)
  3041. $USER->matrix_iassign[$x][$j] = new stdClass();
  3042. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3043. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3044. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3045. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3046. if ($student_submissions)
  3047. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3048. else
  3049. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3050. //print '</td>' . "\n";
  3051. } // for ($j=1; $j<$num_exerc; $j++)
  3052. $total = $total + $total_student;
  3053. $porcentagem = ($total_student / ($j - 1)) * 100;
  3054. if ($tentativas != 0 && $tentativas != null) {
  3055. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3056. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3057. }
  3058. else {
  3059. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3060. }
  3061. print '</tr>' . "\n";
  3062. $sum_correct_student[$sum_student] = new stdClass();
  3063. $sum_correct_student[$sum_student]->name = $name;
  3064. $sum_correct_student[$sum_student]->sum = $total_student;
  3065. } // for ($x = 0; $x < $w; $x ++)
  3066. for ($i = 1; $i < $j; $i ++) {
  3067. if (is_null($sum_iassign_correct[$i]))
  3068. $sum_iassign_correct[$i] = 0;
  3069. $sum_correct_iassign[$i] = new stdClass();
  3070. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3071. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3072. }
  3073. // print '</tr></table>' . "\n";
  3074. }
  3075. } // if ($i>1)
  3076. else {
  3077. print_string('no_activity', 'iassign');
  3078. }
  3079. print "</table>\n";
  3080. if ($this->action != 'print')
  3081. print $OUTPUT->footer();
  3082. die();
  3083. } // function report()
  3084. /// Display graphics of performance
  3085. function stats () {
  3086. global $USER, $CFG, $DB, $OUTPUT;
  3087. $id = $this->cm->id;
  3088. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3089. if ($this->action != 'printstats')
  3090. $title = get_string('graphic', 'iassign');
  3091. $num = array();
  3092. $sum_correct_iassign = array();
  3093. $sum_correct_student = array();
  3094. $sum_student = 0;
  3095. $i = 1;
  3096. foreach ($iassign_list as $iassign) {
  3097. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3098. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3099. $sum_iassign_correct[$i] = 0;
  3100. $num[$i] = new stdClass();
  3101. $num[$i]->name = $iassign->name;
  3102. $num[$i]->id = $i;
  3103. $num[$i]->iassignid = $iassign->id;
  3104. $i ++;
  3105. } // if ($iassign->type_iassign == 3)
  3106. } // foreach ($iassign_list as $iassign)
  3107. $sum_iassign = $i - 1;
  3108. $context = context_course::instance($this->course->id);
  3109. if ($i > 1) {
  3110. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3111. $params_temp = array('shortname' => 'student');
  3112. $role = $DB->get_record_sql(
  3113. "SELECT s.id, s.shortname FROM {role} s " .
  3114. " WHERE s.shortname = :shortname", $params_temp);
  3115. // $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");
  3116. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3117. $students = $DB->get_records_sql(
  3118. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3119. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3120. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3121. $total = 0;
  3122. $sum_student = 0;
  3123. $j = 0;
  3124. $sum_correct_iassign = array();
  3125. $sum_correct_student = array();
  3126. $sum_experiment = array();
  3127. if ($students) {
  3128. foreach ($students as $users) {
  3129. $sum_student ++;
  3130. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3131. // rows
  3132. $total_student = 0;
  3133. for ($j = 1; $j < $i; $j ++) {
  3134. $total_experiment = 0;
  3135. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3136. if ($student_submissions) {
  3137. if ($student_submissions->status == 3) {
  3138. $sum_iassign_correct[$j] ++;
  3139. $total_student ++;
  3140. } // if ($student_submissions->status == 3)
  3141. $total_experiment += $student_submissions->experiment;
  3142. }
  3143. $sum_experiment[$j] = $total_experiment;
  3144. } // for ($j=1; $j<$i; $j++)
  3145. $total = $total + $total_student;
  3146. $sum_correct_student[$sum_student] = new stdClass();
  3147. $sum_correct_student[$sum_student]->name = $name;
  3148. $sum_correct_student[$sum_student]->sum = $total_student;
  3149. } // foreach ($students as $users)
  3150. }
  3151. for ($i = 1; $i < $j; $i ++) {
  3152. if (is_null($sum_iassign_correct[$i]))
  3153. $sum_iassign_correct[$i] = 0;
  3154. $sum_correct_iassign[$i] = new stdClass();
  3155. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3156. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3157. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3158. } // for ($i = 1; $i < $j; $i++)
  3159. } // if ($i > 1)
  3160. if ($this->action != 'printstats') {
  3161. $title = get_string('graphic', 'iassign');
  3162. print $OUTPUT->header();
  3163. $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>";
  3164. $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>";
  3165. print '<table width=100%><tr>';
  3166. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3167. print '<td width=15% align="right">' . $link_report . '</td>';
  3168. print '</td></tr></table>' . "\n";
  3169. print "<br><br>";
  3170. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3171. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3172. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3173. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3174. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3175. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3176. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3177. print '</tr>' . "\n";
  3178. $sum_correct = 0;
  3179. if ($sum_correct_iassign) {
  3180. foreach ($sum_correct_iassign as $iassign) {
  3181. if (is_null($iassign->experiment))
  3182. $iassign->experiment = 0;
  3183. $bar = "";
  3184. $sum = $iassign->sum;
  3185. $percent = ($sum / $sum_student) * 100;
  3186. $text = number_format($percent, 1) . '%';
  3187. $sum_correct += $sum;
  3188. if ($sum > 0) {
  3189. for ($i = 1; $i < $percent * 2; $i ++)
  3190. $bar .= iassign_icons::insert('hbar_blue');
  3191. $bar .= iassign_icons::insert('hbar_blue_r');
  3192. } // if ($sum > 0)
  3193. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3194. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3195. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3196. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3197. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3198. print '</tr>' . "\n";
  3199. } // foreach ($sum_correct_iassign as $iassign)
  3200. }
  3201. print "</table>";
  3202. print "<br><br>";
  3203. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3204. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3205. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3206. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3207. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3208. print '</tr>' . "\n";
  3209. $sum_correct = 0;
  3210. foreach ($sum_correct_student as $student) {
  3211. $bar = "";
  3212. $sum = $student->sum;
  3213. $percent = ($sum / $sum_iassign) * 100;
  3214. $text = number_format($percent, 1) . '%';
  3215. $sum_correct += $sum;
  3216. if ($sum > 0) {
  3217. for ($i = 1; $i < $percent * 2; $i ++)
  3218. $bar .= iassign_icons::insert('hbar_blue');
  3219. $bar .= iassign_icons::insert('hbar_blue_r');
  3220. } // if ($sum > 0)
  3221. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3222. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3223. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3224. print '</tr>' . "\n";
  3225. } // foreach ($sum_correct_student as $student)
  3226. print "</table>\n";
  3227. print "<br><br>\n";
  3228. $var = 0;
  3229. $cv = 0;
  3230. $dv = 0;
  3231. $avg = 0;
  3232. if ($sum_correct_student) {
  3233. $avg = $sum_correct / $sum_student;
  3234. if ($avg > 0) {
  3235. foreach ($sum_correct_student as $student)
  3236. $var += pow($student->sum - $avg, 2);
  3237. $var = $var / $sum_student;
  3238. $dv = sqrt($var);
  3239. $cv = ($dv / $avg) * 100;
  3240. }
  3241. }
  3242. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3243. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3244. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3245. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3246. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3247. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3248. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3249. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3250. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3251. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3252. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3253. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3254. print "</table>\n";
  3255. print $OUTPUT->footer();
  3256. } else {
  3257. print "<STYLE TYPE='text/css'>
  3258. <!--
  3259. .boldtable {
  3260. font-family:sans-serif;
  3261. font-size:10pt;
  3262. }
  3263. -->
  3264. </STYLE>\n";
  3265. print '<table border=1 width=100%>' . "\n";
  3266. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3267. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3268. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3269. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3270. print '</tr>' . "\n";
  3271. $sum_correct = 0;
  3272. foreach ($sum_correct_iassign as $iassign) {
  3273. $bar = "";
  3274. $sum = $iassign->sum;
  3275. $percent = ($sum / $sum_student) * 100;
  3276. $text = number_format($percent, 1) . '%';
  3277. $sum_correct += $sum;
  3278. if ($sum > 0) {
  3279. for ($i = 1; $i < $percent * 2; $i ++)
  3280. $bar .= iassign_icons::insert('hbar_blue');
  3281. $bar .= iassign_icons::insert('hbar_blue_r');
  3282. } // if ($sum > 0)
  3283. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3284. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3285. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3286. print '</tr>' . "\n";
  3287. } // foreach ($sum_correct_iassign as $iassign)
  3288. print "</table>";
  3289. print "<br><br>";
  3290. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3291. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3292. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3293. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3294. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3295. print '</tr>' . "\n";
  3296. $sum_correct = 0;
  3297. foreach ($sum_correct_student as $student) {
  3298. $bar = "";
  3299. $sum = $student->sum;
  3300. $percent = ($sum / $sum_iassign) * 100;
  3301. $text = number_format($percent, 1) . '%';
  3302. $sum_correct += $sum;
  3303. if ($sum > 0) {
  3304. for ($i = 1; $i < $percent * 2; $i ++)
  3305. $bar .= iassign_icons::insert('hbar_blue');
  3306. $bar .= iassign_icons::insert('hbar_blue_r');
  3307. } // if ($sum > 0)
  3308. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3309. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3310. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3311. print '</tr>' . "\n";
  3312. } // foreach ($sum_correct_student as $student)
  3313. print "</table>\n";
  3314. print "<br/><br/>\n";
  3315. $var = 0;
  3316. $cv = 0;
  3317. $dv = 0;
  3318. $avg = 0;
  3319. if ($sum_correct_student) {
  3320. $avg = $sum_correct / $sum_student;
  3321. if ($avg > 0) {
  3322. foreach ($sum_correct_student as $student)
  3323. $var += pow($student->sum - $avg, 2);
  3324. $var = $var / $sum_student;
  3325. $dv = sqrt($var);
  3326. $cv = ($dv / $avg) * 100;
  3327. }
  3328. }
  3329. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3330. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3331. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3332. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3333. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3334. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3335. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3336. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3337. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3338. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3339. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3340. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3341. print "</table>\n";
  3342. } // if ($this->action != 'printstats')
  3343. die();
  3344. }
  3345. /// Display graphics of performance for students
  3346. function stats_students () {
  3347. global $USER, $CFG, $DB, $OUTPUT;
  3348. $id = $this->cm->id;
  3349. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3350. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3351. $title = get_string('results', 'iassign');
  3352. $sum_correct = 0;
  3353. $sum_incorrect = 0;
  3354. $sum_post = 0;
  3355. $sum_nopost = 0;
  3356. $sum_iassign = count($iassign_statement_list);
  3357. $bar_nopost = "";
  3358. $bar_correct = "";
  3359. $bar_incorrect = "";
  3360. $bar_post = "";
  3361. $text_nopost = "";
  3362. $text_correct = "";
  3363. $text_incorrect = "";
  3364. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3365. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3366. if ($iassign_submission) {
  3367. if ($iassign_submission->status == 3)
  3368. $sum_correct ++;
  3369. elseif ($iassign_submission->status == 2)
  3370. $sum_incorrect ++;
  3371. elseif ($iassign_submission->status == 1)
  3372. $sum_post ++;
  3373. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3374. $sum_nopost ++;
  3375. } // if ($iassign_submission)
  3376. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3377. if ($sum_iassign > 0) {
  3378. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3379. $text_correct = number_format($percent_correct, 1) . '%';
  3380. }
  3381. if ($sum_correct > 0) {
  3382. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3383. $bar_correct .= iassign_icons::insert('hbar_green');
  3384. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3385. } // if ($sum_correct > 0)
  3386. if ($sum_iassign > 0) {
  3387. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3388. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3389. }
  3390. if ($sum_incorrect > 0) {
  3391. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3392. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3393. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3394. } // if ($sum_incorrect > 0)
  3395. if ($sum_iassign > 0) {
  3396. $percent_post = ($sum_post / $sum_iassign) * 100;
  3397. $text_post = number_format($percent_post, 1) . '%';
  3398. }
  3399. if ($sum_post > 0) {
  3400. for ($i = 1; $i < $percent_post * 2; $i ++)
  3401. $bar_post .= iassign_icons::insert('hbar_blue');
  3402. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3403. } // if ($sum_post > 0)
  3404. if ($sum_iassign > 0) {
  3405. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3406. $text_nopost = number_format($percent_nopost, 1) . '%';
  3407. }
  3408. if ($sum_nopost > 0) {
  3409. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3410. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3411. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3412. } // if ($sum_nopost > 0)
  3413. print $OUTPUT->header();
  3414. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3415. print '<table width=100%><tr>';
  3416. print '<td align="right">' . $link_return . '</td>' . "\n";
  3417. print '</td></tr></table>' . "\n";
  3418. print "<br/><br/>\n";
  3419. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  3420. print '<tr><th colspan=3 class="header c1">' . "\n";
  3421. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3422. // $imagetext = '');
  3423. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3424. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3425. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3426. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3427. print '</tr>' . "\n";
  3428. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3429. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3430. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3431. print '</tr>' . "\n";
  3432. if ($sum_post) {
  3433. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3434. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3435. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3436. print '</tr>' . "\n";
  3437. } // if ($sum_post)
  3438. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3439. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3440. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3441. print '</tr>' . "\n";
  3442. print "</table>";
  3443. print "<br><br>";
  3444. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3445. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3446. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3447. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3448. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3449. $sum_grade = 0;
  3450. $sum_grade_student = 0;
  3451. $avg = 0;
  3452. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3453. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3454. if (!$iassign_submission) {
  3455. $iassign_submission = new stdClass();
  3456. $iassign_submission->grade = 0;
  3457. }
  3458. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3459. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3460. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3461. print '</tr>' . "\n";
  3462. $sum_grade += $iassign_statement_activity_item->grade;
  3463. $sum_grade_student += $iassign_submission->grade;
  3464. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3465. if ($sum_grade > 0)
  3466. $avg = $sum_grade_student / $sum_grade * 100;
  3467. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3468. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3469. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3470. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3471. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3472. print "</table>";
  3473. print $OUTPUT->footer();
  3474. die();
  3475. } // function stats_students()
  3476. /// Display page of iAssign's activity
  3477. function view_iassigns () {
  3478. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3479. $id = $this->cm->id;
  3480. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3481. $notice = optional_param('notice', '', PARAM_TEXT);
  3482. if (strpos($notice, 'error'))
  3483. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3484. else if ($notice != '')
  3485. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3486. print $OUTPUT->box_start();
  3487. print '<table width=100% border=0><tr>' . "\n";
  3488. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3489. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  3490. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  3491. $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>";
  3492. $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>";
  3493. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3494. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3495. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3496. // Has capability to see "report": teacher or up
  3497. print '<td width=10% align="left">' . "\n";
  3498. print $link_help;
  3499. print '</td>' . "\n";
  3500. print '<td width=10% align="left">' . "\n";
  3501. print $link_report;
  3502. print '</td>' . "\n";
  3503. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3504. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3505. print '<td width=15% align="left">' . "\n";
  3506. print $link_add;
  3507. print "</td>\n";
  3508. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3509. //print '</tr></table>' . "\n";
  3510. print '<div style="float: right;">';
  3511. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3512. if ($iassign_list) {
  3513. print '<td align="right">' . "\n";
  3514. // $USER->iassignEdit == 0 view 'Turn editing off'
  3515. // $USER->iassignEdit == 1 view 'Turn editing on'
  3516. if (!isset($USER->iassignEdit))
  3517. $USER->iassignEdit = 0;
  3518. if ($USER->iassignEdit == 0) {
  3519. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3520. $botton = 1;
  3521. } // if ($USER->iassignEdit == 0)
  3522. elseif ($USER->iassignEdit == 1) {
  3523. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3524. $botton = 0;
  3525. } // elseif ($USER->iassignEdit == 1)
  3526. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3527. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3528. print " <input type=submit value='$bottonEdit_message'/>\n";
  3529. print "</form>\n";
  3530. print "</td>\n";
  3531. } // if ($iassign_list)
  3532. }
  3533. print '</tr></table>' . "\n";
  3534. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3535. // $this->view_legend_icons();
  3536. print $OUTPUT->box_end();
  3537. $iassign_array_exercise = array();
  3538. $i_exercise = 0;
  3539. $iassign_array_test = array();
  3540. $i_test = 0;
  3541. $iassign_array_example = array();
  3542. $i_example = 0;
  3543. $iassign_array_general = array();
  3544. $i_general = 0;
  3545. if ($iassign_list) {
  3546. if ($this->iassign->activity_group == 0) {
  3547. foreach ($iassign_list as $iassign) {
  3548. $iassign_array_general[$i_general] = $iassign;
  3549. $i_general ++;
  3550. }
  3551. } // if ($this->iassign->activity_group == 0)
  3552. else {
  3553. foreach ($iassign_list as $iassign) {
  3554. if ($iassign->type_iassign == 3) {
  3555. $iassign_array_exercise[$i_exercise] = $iassign;
  3556. $i_exercise ++;
  3557. } // if ($iassign->type_iassign == 3)
  3558. if ($iassign->type_iassign == 2) {
  3559. $iassign_array_test[$i_test] = $iassign;
  3560. $i_test ++;
  3561. } // if ($iassign->type_iassign == 2)
  3562. if ($iassign->type_iassign == 1) {
  3563. $iassign_array_example[$i_example] = $iassign;
  3564. $i_example ++;
  3565. } // if ($iassign->type_iassign == 1)
  3566. }
  3567. }
  3568. if ($iassign_array_exercise) {
  3569. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3570. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3571. }
  3572. if ($iassign_array_test) {
  3573. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3574. $this->show_iassign($title, $iassign_array_test, $i_test);
  3575. }
  3576. if ($iassign_array_example) {
  3577. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3578. $this->show_iassign($title, $iassign_array_example, $i_example);
  3579. }
  3580. if ($iassign_array_general) {
  3581. $title = "";
  3582. $this->show_iassign($title, $iassign_array_general, $i_general);
  3583. }
  3584. } else { // if ($iassign_list)
  3585. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3586. }
  3587. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3588. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3589. print $OUTPUT->box_start();
  3590. print '<table width=100% border=0><tr>' . "\n";
  3591. print '<td width=10% align="left">' . "\n";
  3592. print $link_report;
  3593. print '</td>' . "\n";
  3594. print '</tr></table>' . "\n";
  3595. print $OUTPUT->box_end();
  3596. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3597. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3598. print $OUTPUT->box_start();
  3599. print '<table width=100% border=0><tr>' . "\n";
  3600. print '<td align="left">' . "\n";
  3601. print $link_add;
  3602. print '</td>' . "\n";
  3603. print '</tr></table>' . "\n";
  3604. print $OUTPUT->box_end();
  3605. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3606. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3607. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3608. $this->view_legend_icons();
  3609. } // function view_iassigns()
  3610. /// Display all iAssigns
  3611. function show_iassign ($title, $iassign_array, $i) {
  3612. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3613. $id = $this->cm->id;
  3614. print $OUTPUT->box_start();
  3615. print " <script type='text/javascript'>
  3616. //<![CDATA[
  3617. function validate_move () {
  3618. var radios = document.getElementsByName('iassign_destiny');
  3619. var formValid = false;
  3620. //alert('aqui validate_move()');
  3621. var i = 0;
  3622. while (!formValid && i < radios.length) {
  3623. if (radios[i].checked) formValid = true;
  3624. i++;
  3625. }
  3626. if (!formValid) {
  3627. document.getElementById('move_dest').classList.add('alert-danger');
  3628. }
  3629. return formValid;
  3630. }
  3631. var modal;
  3632. function load_move(id_ias) {
  3633. document.form_move_activity.iassign_current.value = id_ias;
  3634. modal.style.display = 'block';
  3635. var radios = document.getElementsByName('iassign_destiny');
  3636. var i = 0;
  3637. while (i < radios.length) {
  3638. radios[i].checked = false;
  3639. i++;
  3640. }
  3641. document.getElementById('move_dest').classList.remove('alert-danger');
  3642. }
  3643. function load_modal_elements() {
  3644. modal = document.getElementById('myModal');
  3645. var span = document.getElementById('close_modal');
  3646. span.onclick = function() {
  3647. modal.style.display = 'none';
  3648. }
  3649. window.onclick = function(event) {
  3650. if (event.target == modal) {
  3651. modal.style.display = 'none';
  3652. }
  3653. }
  3654. }
  3655. window.onload = load_modal_elements;
  3656. //]]>
  3657. </script>\n";
  3658. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3659. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3660. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3661. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3662. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3663. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3664. <input type='hidden' name='iassign_current' value='' />";
  3665. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3666. $section = $course_sections[0];
  3667. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3668. for ($k = 0; $k < count($ids_sections); $k++) {
  3669. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3670. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3671. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3672. if ($c_cm) {
  3673. if ($ccm->instance == $c_cm->instance) {
  3674. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3675. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3676. }
  3677. else {
  3678. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3679. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3680. }
  3681. }
  3682. }
  3683. $radio_buttons .= "</ul>";
  3684. }
  3685. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3686. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3687. </form>
  3688. </div></div> </div></div>\n";
  3689. print " <style>.modal {
  3690. display: none;
  3691. position: fixed;
  3692. z-index: 1;
  3693. left: 0;
  3694. top: 0;
  3695. width: 100%;
  3696. height: 100%;
  3697. overflow: scroll;
  3698. background-color: rgb(0,0,0);
  3699. background-color: rgba(0,0,0,0.4);
  3700. }
  3701. .modal-content {
  3702. background-color: #fefefe;
  3703. margin: 15% auto;
  3704. padding: 10px 10px;
  3705. border: 1px solid #888;
  3706. width: 50%;
  3707. }
  3708. #close_modal {
  3709. color: #aaa;
  3710. float: right;
  3711. font-size: 28px;
  3712. font-weight: bold;
  3713. margin-top: -15px;
  3714. margin-right: -3px;
  3715. }
  3716. #close_modal:hover,
  3717. #close_modal:focus {
  3718. color: black;
  3719. text-decoration: none;
  3720. cursor: pointer;
  3721. }
  3722. #modal_title {
  3723. min-height: 3rem;
  3724. color: initial;
  3725. background: initial;
  3726. font-size: 1.5rem;
  3727. line-height: 1.5;
  3728. padding: 15px;
  3729. border-bottom: 1px solid #e5e5e5;
  3730. }
  3731. .input_move {
  3732. width: 90%;
  3733. padding: 2px;
  3734. }
  3735. .input_move:hover {
  3736. background: #eff0ef;
  3737. }
  3738. </style>";
  3739. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3740. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3741. for ($j = 0; $j < $i; $j ++) {
  3742. $iassign_current = $iassign_array[$j]->id;
  3743. // receiver=1 - message to teacher
  3744. // receiver=2 - message to student
  3745. $sum_comment = 0;
  3746. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3747. foreach ($iassign_submissions as $iassign_submission) {
  3748. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3749. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3750. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  3751. if ($verify_message)
  3752. foreach ($verify_message as $tmp)
  3753. $sum_comment += $tmp;
  3754. } // foreach ($iassign_submissions as $iassign_submission)
  3755. if ($sum_comment == 0)
  3756. $comment_unread = "";
  3757. else {
  3758. $comment_unread_message = get_string('comment_unread', 'iassign');
  3759. if ($sum_comment == 1)
  3760. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3761. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3762. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3763. }
  3764. if ($j == $i - 1)
  3765. $iassign_down = $iassign_array[$j]->id;
  3766. else
  3767. $iassign_down = $iassign_array[$j + 1]->id;
  3768. if ($j > 0)
  3769. $iassign_up = $iassign_array[$j - 1]->id;
  3770. else
  3771. $iassign_up = $iassign_array[$j]->id;
  3772. if ($iassign_array[$j]->visible == 0)
  3773. $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>";
  3774. else
  3775. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3776. $links .= $comment_unread;
  3777. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3778. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3779. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3780. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3781. if ($j==0) // first activity
  3782. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3783. else
  3784. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3785. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3786. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3787. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3788. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3789. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3790. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3791. if (count($iassign_array) > 1) {
  3792. if ($j == 0)
  3793. $links .= $link_down;
  3794. elseif ($j == $i - 1)
  3795. $links .= $link_up;
  3796. else
  3797. $links .= $link_up . $link_down;
  3798. } // if (count($iassign_array) > 1)
  3799. $links .= $link_edit . $link_delete;
  3800. if ($iassign_array[$j]->visible == 0)
  3801. $links .= $link_visible_show;
  3802. else
  3803. $links .= $link_visible_hide;
  3804. $links .= $link_duplicate_activity . $link_move_activity;
  3805. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3806. print '<p>' . $links . '</p>' . "\n";
  3807. }
  3808. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3809. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3810. print '<table width=100% ><tr>' . "\n";
  3811. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3812. print '</tr></table>' . "\n";
  3813. for ($j = 0; $j < $i; $j ++) {
  3814. $icon_status = "";
  3815. $icon_comment = "";
  3816. if ($iassign_array[$j]->visible == 1) {
  3817. $iassign_current = $iassign_array[$j]->id;
  3818. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3819. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3820. $icon_status = "";
  3821. $icon_comment = "";
  3822. if ($iassign_submission) {
  3823. // receiver=1 - message to teacher
  3824. // receiver=2 - message to student
  3825. // $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");
  3826. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3827. $verify_message = $DB->get_record_sql(
  3828. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3829. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  3830. if ($verify_message)
  3831. foreach ($verify_message as $tmp)
  3832. $sum_comment = $tmp;
  3833. if ($sum_comment > 0) {
  3834. $comment_unread_message = get_string('comment_unread', 'iassign');
  3835. if ($sum_comment == 1)
  3836. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3837. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3838. }
  3839. // $icon_comment = iassign_icons::insert('comment_unread');
  3840. if ($iassign_array[$j]->type_iassign == 3) {
  3841. if ($iassign_array[$j]->show_answer == 1) {
  3842. if ($iassign_submission->status == 3)
  3843. $icon_status = iassign_icons::insert('correct');
  3844. elseif ($iassign_submission->status == 2)
  3845. $icon_status = iassign_icons::insert('incorrect');
  3846. elseif ($iassign_submission->status == 1)
  3847. $icon_status = iassign_icons::insert('post');
  3848. elseif ($iassign_submission->status == 0)
  3849. $icon_status = iassign_icons::insert('not_post');
  3850. } // if ($iassign_array[$j]->show_answer==1)
  3851. else {
  3852. if ($iassign_submission->status == 0)
  3853. $icon_status = iassign_icons::insert('not_post');
  3854. else
  3855. $icon_status = iassign_icons::insert('post');
  3856. }
  3857. } // if ($iassign_array[$j]->type_iassign == 3)
  3858. } // if ($iassign_submission)
  3859. elseif ($iassign_array[$j]->type_iassign == 3) {
  3860. $icon_status = iassign_icons::insert('not_post');
  3861. } // if ($iassign_array[$j]->type_iassign == 3)
  3862. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3863. } // if ($iassign_array[$j]->visible == 1)
  3864. } // for ($j = 0; $j < $i; $j++)
  3865. } else if (isguestuser()) {
  3866. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3867. print '<table width=100% ><tr>' . "\n";
  3868. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3869. print '</tr></table>' . "\n";
  3870. for ($j = 0; $j < $i; $j ++) {
  3871. $icon_status = "";
  3872. $icon_comment = "";
  3873. if ($iassign_array[$j]->visible == 1) {
  3874. $iassign_current = $iassign_array[$j]->id;
  3875. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3876. print '<p>' . $links . '</p>' . "\n";
  3877. } // if ($iassign_array[$j]->visible == 1)
  3878. }
  3879. }
  3880. print $OUTPUT->box_end();
  3881. } // function show_iassign($title, $iassign_array, $i)
  3882. /// Show message of return
  3883. function return_home_course ($message) {
  3884. //D global $DB, $OUTPUT;
  3885. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3886. //D echo $OUTPUT->box_start();
  3887. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3888. //D echo '<tr><td align="left"><strong>' . "\n";
  3889. //D print_string($message, 'iassign');
  3890. //D echo '</strong></td>' . "\n";
  3891. //D echo '<td width=20% align="right">' . "\n";
  3892. //D echo $link_return;
  3893. //D echo '</td></tr></table>' . "\n";
  3894. //D echo $OUTPUT->box_end();
  3895. //D // echo $OUTPUT->footer();
  3896. redirect(new moodle_url($this->return . '&notice=' . $message));
  3897. exit;
  3898. }
  3899. /// Search comment of activity
  3900. function search_comment_submission ($iassign_submissionid) {
  3901. global $USER, $DB, $OUTPUT, $COURSE;
  3902. // $context = context_course::instance($COURSE->id);
  3903. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3904. $colorEdit2 = "#d2e5fc";
  3905. $has_capability = 0;
  3906. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3907. $text = "";
  3908. if ($comments) {
  3909. $even = 1;
  3910. foreach ($comments as $tmp) {
  3911. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3912. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3913. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3914. // $text .= $tmp->comment . "</td></tr>";
  3915. //} else {
  3916. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3917. $avatar = new user_picture($user_data);
  3918. $avatar->courseid = $COURSE->id;
  3919. $avatar->link = true;
  3920. $user_picture = $OUTPUT->render($avatar);
  3921. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3922. if ($even) {
  3923. $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";
  3924. $even = 0;
  3925. } else {
  3926. $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";
  3927. $even = 1;
  3928. }
  3929. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3930. } // foreach ($comments as $tmp)
  3931. }
  3932. return $text;
  3933. }
  3934. /// Update comment of activity
  3935. function update_comment ($iassign_submissionid) {
  3936. global $USER, $DB, $OUTPUT;
  3937. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3938. $receiver = 1; // student message to teacher
  3939. else
  3940. $receiver = 2; // teacher message to student
  3941. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3942. if ($verify_message) {
  3943. foreach ($verify_message as $message) {
  3944. if ($message->receiver == $receiver) {
  3945. $newentry = new stdClass();
  3946. $newentry->id = $message->id;
  3947. $newentry->return_status = 1;
  3948. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3949. print_error('error_update', 'iassign');
  3950. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3951. } // if ($message->receiver == $receiver)
  3952. // Trigger module viewed event.
  3953. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3954. 'objectid' => $this->iassign->id,
  3955. 'context' => $this->context
  3956. ));
  3957. $event->add_record_snapshot('course', $this->course);
  3958. $event->trigger();
  3959. } // foreach ($verify_message as $message)
  3960. }
  3961. }
  3962. /// Record comment of activity
  3963. function write_comment_submission () {
  3964. global $USER, $CFG, $DB;
  3965. $id = $this->cm->id;
  3966. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3967. $row = optional_param('row', 0, PARAM_INT);
  3968. $column = optional_param('column', 0, PARAM_INT);
  3969. $sum_comment = 0;
  3970. $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);
  3971. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3972. $str1 = trim($submission_comment);
  3973. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3974. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3975. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3976. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3977. $receiver = 1; // student message to teacher
  3978. $this->action = 'view';
  3979. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3980. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3981. } else {
  3982. $receiver = 2; // teacher message to student
  3983. $this->action = 'viewsubmission';
  3984. //D $tousers = array(); //MOOC 2016
  3985. //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
  3986. }
  3987. //MOOC 2016: foi p/ 15 linhas acima:
  3988. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3989. // verificar se existe uma submissão para o exercício e aluno informados
  3990. if (!$iassign_submission) {
  3991. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3992. }
  3993. if (!$iassign_submission) {
  3994. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3995. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3996. $this->iassign_submission_current = $id_submission;
  3997. }
  3998. else {
  3999. $id_submission = $iassign_submission->id;
  4000. } // if (!$iassign_submission)
  4001. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4002. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4003. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4004. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4005. $comments = $DB->get_record_sql(
  4006. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4007. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4008. if ($comments)
  4009. foreach ($comments as $tmp)
  4010. $sum_comment = $tmp;
  4011. if ($sum_comment == 0) {
  4012. $newentry = new stdClass();
  4013. $newentry->iassign_submissionid = $id_submission;
  4014. $newentry->comment_authorid = $USER->id;
  4015. $newentry->timecreated = time();
  4016. $newentry->comment = $submission_comment;
  4017. $newentry->receiver = $receiver;
  4018. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4019. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  4020. //T $eventdata = new stdClass();
  4021. //T $eventdata->component = 'mod_iassign'; //your component name
  4022. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  4023. //T $eventdata->userfrom = $USER;
  4024. //T $eventdata->userto = $touser;
  4025. //T $eventdata->subject = "Teste de Subject";
  4026. //T $eventdata->fullmessage = "Teste de Mensagem...";
  4027. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  4028. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  4029. //T $eventdata->smallmessage = "Teste de Mensagem";
  4030. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  4031. //T // alteracao tulio faria
  4032. //T //message_send($eventdata);
  4033. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  4034. // Trigger module viewed event.
  4035. $event = \mod_iassign\event\submission_comment_created::create(array(
  4036. 'objectid' => $this->iassign->id,
  4037. 'context' => $this->context
  4038. ));
  4039. $event->add_record_snapshot('course', $this->course);
  4040. $event->trigger();
  4041. }
  4042. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4043. // if ($this->action=='viewsubmission') {
  4044. // echo $OUTPUT->header();
  4045. // $this->return_last('confirm_add_comment', $link_return);
  4046. // die;
  4047. // }
  4048. return true;
  4049. } // function write_comment_submission()
  4050. /// Writes a new submission
  4051. // The first student answer is under 'function get_answer()'
  4052. function new_submission ($iassignid, $id_user, $receiver) {
  4053. global $USER, $DB, $OUTPUT;
  4054. $newentry = new stdClass();
  4055. $newentry->iassign_statementid = $iassignid;
  4056. $newentry->userid = $id_user;
  4057. $newentry->timecreated = time();
  4058. $newentry->timemodified = time();
  4059. $newentry->answer = 0; // student only submit message
  4060. if ($receiver == 2) // teacher message to student (write id teacher)
  4061. $newentry->teacher = $USER->id;
  4062. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4063. return_home_course('error_insert_submissions');
  4064. else {
  4065. // Trigger module view event
  4066. $event = \mod_iassign\event\submission_created::create(array(
  4067. 'objectid' => $this->iassign->id,
  4068. 'context' => $this->context
  4069. ));
  4070. $event->add_record_snapshot('course', $this->course);
  4071. $event->trigger();
  4072. }
  4073. return $newentry->id;
  4074. }
  4075. /// Return to a specific address of page
  4076. function return_last ($message, $link_return) {
  4077. global $DB, $OUTPUT;
  4078. print $OUTPUT->box_start();
  4079. print '<table width=100% border=0 valign="top">' . "\n";
  4080. print '<tr><td align="left"><strong>' . "\n";
  4081. print_string($message, 'iassign');
  4082. print '</strong></td>' . "\n";
  4083. print '<td width=20% align="right">' . "\n";
  4084. print $link_return;
  4085. print '</td></tr></table>' . "\n";
  4086. print $OUTPUT->box_end();
  4087. print $OUTPUT->footer();
  4088. die();
  4089. } // function return_last($message, $link_return)
  4090. } // class iassign
  4091. /// Class for manage activities
  4092. class activity {
  4093. var $activity;
  4094. /// Constructor of class.
  4095. // @param int $id Id of activity
  4096. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4097. //D public function activity($id) { self::__construct($id); }
  4098. function __construct ($id) {
  4099. global $DB;
  4100. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4101. if (empty($this->activity))
  4102. $this->activity = null;
  4103. }
  4104. /// Get an activity
  4105. // @return NULL
  4106. function get_activity () {
  4107. if ($this->activity != null)
  4108. return $this->activity;
  4109. else
  4110. return null;
  4111. }
  4112. /// Delete interactive activities
  4113. function delete ($return) {
  4114. global $USER, $CFG, $DB, $OUTPUT;
  4115. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4116. $output = $OUTPUT->header();
  4117. $output .= $OUTPUT->box_start();
  4118. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4119. if ($iassign_submission_currents) {
  4120. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4121. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4122. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4123. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4124. $output .= $OUTPUT->box_end();
  4125. $output .= $OUTPUT->footer();
  4126. print $output;
  4127. die();
  4128. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4129. } // if ($iassign_submission_currents)
  4130. else
  4131. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  4132. $output .= '<table width=50% border=0>';
  4133. $output .= '<tr valign="top"><td>';
  4134. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  4135. $output .= '</td><td>';
  4136. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4137. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4138. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  4139. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4140. $output .= "</form>\n";
  4141. $output .= '</td><td>';
  4142. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4143. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4144. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4145. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4146. $output .= "</form>\n";
  4147. $output .= '</td></tr></table>' . "\n";
  4148. $output .= $OUTPUT->box_end();
  4149. $output .= $OUTPUT->footer();
  4150. print $output;
  4151. } // function delete($return)
  4152. /// Function for confirm the delete of activity
  4153. // @param String $return Url of return
  4154. // @param Object $iassign Object content an activity
  4155. function deleteyes ($return, $iassign) {
  4156. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4157. $msg = '';
  4158. if (!empty($this->activity->id)) {
  4159. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4160. if ($iassign_submission_currents) {
  4161. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4162. foreach ($iassign_submission_currents as $iassign_submission)
  4163. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4164. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4165. } // if ($iassign_submission_currents)
  4166. }
  4167. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4168. // Remove all files associated to this activity:
  4169. $fs = get_file_storage();
  4170. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4171. $this->delete_calendar($this->activity->id);
  4172. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4173. iassign::update_grade_iassign($this->activity->iassignid);
  4174. if ($delete_iassign_current) {
  4175. $iassign->return_home_course('confirm_delete_iassign');
  4176. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4177. } else {
  4178. $iassign->return_home_course('error_confirm_delete_iassign');
  4179. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4180. }
  4181. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4182. }
  4183. }
  4184. /// Changes position of activities (between those inside a group of interactive activities)
  4185. // @param $move_action = must be "up" or "down"
  4186. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4187. function move_iassign ($move_action, $target, $return) {
  4188. global $DB, $OUTPUT;
  4189. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4190. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4191. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4192. if ($move_action=="firstdown") {
  4193. $final_position_source = 2;
  4194. $final_position_target = 1;
  4195. }
  4196. else
  4197. if ($move_action=="down") {
  4198. $final_position_target = $this->activity->position;
  4199. $final_position_source = $final_position_target + 1;
  4200. }
  4201. else
  4202. if ($move_action=="up") {
  4203. $final_position_target = $this->activity->position;
  4204. $final_position_source = $final_position_target - 1;
  4205. }
  4206. else { // error:
  4207. print_error('error_update_move_iassign', 'iassign');
  4208. exit;
  4209. }
  4210. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4211. $newentry->id = $this->activity->id; // ID of the "source activity"
  4212. $newentry->position = $final_position_source;
  4213. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4214. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4215. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4216. print_error('error_update_move_iassign', 'iassign');
  4217. }
  4218. else { // first update performed successfully
  4219. $newentry->id = $iassign_target->id;
  4220. $newentry->position = $final_position_target;
  4221. if (!$DB->update_record('iassign_statement', $newentry))
  4222. print_error('error_update_move_iassign', 'iassign');
  4223. }
  4224. redirect($return);
  4225. }
  4226. /// Enable or disable the display of interactive activities
  4227. function visible_iassign ($return) {
  4228. global $DB;
  4229. $newentry = new stdClass();
  4230. $newentry->id = $this->activity->id;
  4231. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4232. if (!$DB->update_record('iassign_statement', $newentry))
  4233. print_error('error_update_visible_iassign', 'iassign');
  4234. redirect($return);
  4235. }
  4236. /// Add news interactive activities (register in table 'iassign_statement')
  4237. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4238. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4239. function new_iassign ($param) {
  4240. global $DB;
  4241. $newentry = new stdClass();
  4242. $newentry->iassignid = $param->iassignid;
  4243. $newentry->name = $param->name;
  4244. $newentry->type_iassign = $param->type_iassign;
  4245. $newentry->store_all_submissions = $param->store_all_submissions;
  4246. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4247. $proposition = $param->proposition;
  4248. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4249. else $proposition_text = $proposition;
  4250. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4251. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4252. //TODO Then get it directly from the form data $_POST!
  4253. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4254. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4255. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4256. $newentry->author_name = $param->author_name;
  4257. $newentry->author_modified_name = $param->author_modified_name;
  4258. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4259. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4260. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4261. $newentry->grade = $param->grade;
  4262. $newentry->timemodified = time();
  4263. $newentry->timecreated = time();
  4264. if ($param->type_iassign == 1) {
  4265. $newentry->timedue = 0;
  4266. $newentry->timeavailable = 0;
  4267. } // if ($param->type_iassign == 1)
  4268. else {
  4269. $newentry->timedue = $param->timedue;
  4270. $newentry->timeavailable = $param->timeavailable;
  4271. }
  4272. $newentry->preventlate = $param->preventlate;
  4273. $newentry->test = $param->test;
  4274. $newentry->special_param1 = $param->special_param1;
  4275. $newentry->visible = $param->visible;
  4276. $newentry->position = $param->position;
  4277. $newentry->max_experiment = $param->max_experiment;
  4278. $newentry->dependency = $param->dependency;
  4279. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4280. $newentry->show_answer = $param->show_answer;
  4281. $id = $DB->insert_record("iassign_statement", $newentry);
  4282. if ($id) {
  4283. $component = 'mod_iassign';
  4284. $filearea = 'exercise';
  4285. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4286. $file = $fs->get_file_by_id($param->file);
  4287. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4288. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4289. //$itemid = $id;
  4290. // File already inserted in other context!
  4291. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4292. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4293. $updateentry = new stdClass();
  4294. $updateentry->id = $id;
  4295. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4296. $updateentry->filesid = $newfile->get_itemid();
  4297. if (!$DB->update_record("iassign_statement", $updateentry))
  4298. print_error('error_add', 'iassign');
  4299. if ($param->type_iassign == 3)
  4300. iassign::update_grade_iassign($param->iassignid);
  4301. //TODO iLM_HTML5 :: //MOOC2014
  4302. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4303. //D if ($iassign_ilm_configs) {
  4304. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4305. //D if ($iassign_ilm_config->param_type != 'static') {
  4306. //D $newentry = new stdClass();
  4307. //D $newentry->iassign_statementid = $id;
  4308. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4309. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4310. //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});
  4311. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4312. //D print_error('error_add_param', 'iassign');
  4313. //D }
  4314. //D }
  4315. //D }
  4316. // log event --------------------------------------------------------------------------------------
  4317. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4318. // log event --------------------------------------------------------------------------------------
  4319. return $id;
  4320. }
  4321. else
  4322. print_error('error_add', 'iassign');
  4323. } // function new_iassign($param)
  4324. /// Add the calendar entries for this iassign
  4325. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4326. // @return bool
  4327. static function add_calendar ($iassignid) {
  4328. global $DB, $CFG;
  4329. require_once($CFG->dirroot . '/calendar/lib.php');
  4330. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4331. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4332. $event = new stdClass();
  4333. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4334. $event->description = $iassign_statement_activity_item->name;
  4335. $event->courseid = $iassign->course;
  4336. $event->groupid = 0;
  4337. $event->userid = 0;
  4338. $event->modulename = 'iassign';
  4339. $event->instance = $iassign->id;
  4340. $event->eventtype = 'due';
  4341. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4342. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4343. calendar_event::create($event);
  4344. }
  4345. /// Update the calendar entries for this iassign
  4346. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4347. // @return bool
  4348. function update_calendar ($iassignid, $olddescription) {
  4349. global $DB, $CFG;
  4350. require_once($CFG->dirroot . '/calendar/lib.php');
  4351. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4352. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4353. $event = new stdClass();
  4354. $event->id = 0;
  4355. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4356. if ($events) {
  4357. foreach ($events as $value) {
  4358. if ($value->description == $olddescription) {
  4359. $event->id = $value->id;
  4360. }
  4361. }
  4362. }
  4363. if ($event->id != 0) {
  4364. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4365. $event->description = $iassign_statement_activity_item->name;
  4366. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4367. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4368. $calendarevent = calendar_event::load($event->id);
  4369. $calendarevent->update($event);
  4370. } else
  4371. $this->add_calendar($iassignid);
  4372. }
  4373. /// Update the calendar entries for this iassign
  4374. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4375. // @return bool
  4376. function delete_calendar ($iassignid) {
  4377. global $DB, $CFG;
  4378. require_once($CFG->dirroot . '/calendar/lib.php');
  4379. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4380. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4381. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4382. if ($events) {
  4383. foreach ($events as $value) {
  4384. if ($value->description == $iassign_statement_activity_item->name) {
  4385. $DB->delete_records('event', array('id' => $value->id));
  4386. }
  4387. }
  4388. }
  4389. }
  4390. /// Update interactive activities
  4391. function update_iassign ($param) {
  4392. global $DB;
  4393. $component = 'mod_iassign';
  4394. $filearea = 'exercise';
  4395. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4396. $file = $fs->get_file_by_id($param->file);
  4397. $fileold = $fs->get_file_by_id($param->fileold);
  4398. if ($param->file != $param->fileold) {
  4399. if ($fileold) {
  4400. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4401. foreach ($fileoldarea as $value) {
  4402. $value->delete();
  4403. }
  4404. }
  4405. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4406. $itemid = $file->get_itemid() + $param->iassign_id;
  4407. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4408. $param->file = $newfile->get_itemid();
  4409. } else
  4410. $param->file = $file->get_itemid();
  4411. } else {
  4412. $param->file = $file->get_itemid();
  4413. }
  4414. $newentry = new stdClass();
  4415. $newentry->id = $param->iassign_id;
  4416. $newentry->name = $param->name;
  4417. $newentry->type_iassign = $param->type_iassign;
  4418. $newentry->store_all_submissions = $param->store_all_submissions;
  4419. //2019 $newentry->proposition = $param->proposition;
  4420. $proposition = $param->proposition;
  4421. if (is_array($proposition))
  4422. $proposition_text = $proposition['text'];
  4423. else
  4424. $proposition_text = $proposition;
  4425. $newentry->proposition = $proposition_text;
  4426. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4427. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4428. $newentry->grade = $param->grade;
  4429. $newentry->author_modified_name = $param->author_modified_name;
  4430. $newentry->timemodified = time();
  4431. if ($param->type_iassign == 1) {
  4432. $newentry->timedue = 0;
  4433. $newentry->timeavailable = 0;
  4434. } // if ($param->type_iassign == 1)
  4435. else {
  4436. $newentry->timedue = $param->timedue;
  4437. $newentry->timeavailable = $param->timeavailable;
  4438. }
  4439. $newentry->preventlate = $param->preventlate;
  4440. $newentry->test = $param->test;
  4441. if (isset($param->special_param1))
  4442. $newentry->special_param1 = $param->special_param1;
  4443. else
  4444. $newentry->special_param1 = NULL;
  4445. $newentry->visible = $param->visible;
  4446. $newentry->max_experiment = $param->max_experiment;
  4447. $newentry->dependency = $param->dependency;
  4448. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4449. $newentry->show_answer = $param->show_answer;
  4450. if (!$DB->update_record("iassign_statement", $newentry))
  4451. print_error('error_update', 'iassign');
  4452. if ($param->type_iassign == 3) {
  4453. iassign::update_grade_iassign($param->iassignid);
  4454. }
  4455. //$id = $newentry->id; // MOOC 2016 --- inicio
  4456. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4457. //if ($iassign_activity_item_configs) {
  4458. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4459. // $newentry = new stdClass();
  4460. // $newentry->id = $iassign_activity_item_config->id;
  4461. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4462. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4463. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4464. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4465. // print_error('error_edit_param', 'iassign');
  4466. // }
  4467. // } // MOOC 2016 --- final
  4468. // log event --------------------------------------------------------------------------------------
  4469. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4470. // log event --------------------------------------------------------------------------------------
  4471. return $newentry->id;
  4472. // if ($param->type_iassign==3)
  4473. // $this->update_grade_iassign($param->iassignid);
  4474. } // function update_iassign($param)
  4475. /// Show information of activity
  4476. function show_info_iassign () {
  4477. global $DB, $OUTPUT;
  4478. $output = '';
  4479. if ($this->activity->type_iassign == 3) {
  4480. if ($this->activity->dependency == 0) {
  4481. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4482. } else {
  4483. $dependencys = explode(';', $this->activity->dependency);
  4484. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4485. foreach ($dependencys as $dependency) {
  4486. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4487. if ($dependencyiassign)
  4488. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4489. } // foreach ($dependencys as $dependency)
  4490. } // if ($iassign_statement_activity_item->dependency == 0)
  4491. if ($this->activity->max_experiment == 0)
  4492. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4493. else
  4494. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4495. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4496. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4497. $output .= $this->toggle_columns_script();
  4498. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4499. print $OUTPUT->box($output);
  4500. } // function show_info_iassign()
  4501. /// Provide script to toggle columns
  4502. static function toggle_columns_script () {
  4503. $output = "";
  4504. $output .= '<script>
  4505. function toLeft () {
  4506. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4507. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4508. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4509. document.getElementById("columnsbutton").style.color = "#1da075";
  4510. }
  4511. function toDefault () {
  4512. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4513. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4514. document.getElementById("fullscreen").style.marginTop = "0";
  4515. document.getElementById("columnsbutton").style.color = "#343a40";
  4516. }
  4517. var activate = false;
  4518. function toggleColumns () {
  4519. if (activate) {
  4520. activate = false;
  4521. toDefault();
  4522. } else {
  4523. activate = true;
  4524. toLeft();
  4525. }
  4526. }
  4527. </script>';
  4528. $output .= '<span style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>';
  4529. return $output;
  4530. }
  4531. /// Shows date of opening and closing activities
  4532. function view_dates () {
  4533. global $USER, $CFG, $DB, $OUTPUT;
  4534. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4535. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4536. $status_iassign = "";
  4537. $status_iassign1 = "";
  4538. $status_iassign2 = "";
  4539. if ($this->activity->type_iassign == 1) // activity of type example
  4540. $type_iassign = get_string('example_iassign', 'iassign');
  4541. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4542. $type_iassign = get_string('test_iassign', 'iassign');
  4543. if ($this->activity->timeavailable > time()) {
  4544. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4545. } elseif ($this->activity->timedue < time()) {
  4546. $status_iassign = get_string('last_timedue', 'iassign');
  4547. }
  4548. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4549. $type_iassign = get_string('exercise_iassign', 'iassign');
  4550. if ($this->activity->timeavailable > time()) {
  4551. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4552. } elseif ($this->activity->timedue < time()) { // after delivery
  4553. $status_iassign = get_string('last_timedue', 'iassign');
  4554. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4555. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4556. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4557. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4558. if ($this->activity->test == 1) // allowed to test after of deadline
  4559. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4560. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4561. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4562. } // elseif ($iassign_statement_activity_item->test == 0)
  4563. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4564. } // elseif ($iassign_statement_activity_item->timedue < time())
  4565. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4566. $output = '<table width=100% >' . "\n";
  4567. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4568. $output .= '<tr>' . "\n";
  4569. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4570. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4571. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4572. // leo $output .= '<td width=80%>' . $type_iassign;
  4573. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4574. // $output .= '</td>' . "\n";
  4575. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4576. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4577. $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>";
  4578. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4579. } else {
  4580. $link_next = "";
  4581. $link_previous = "";
  4582. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4583. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4584. // previous_activity
  4585. if ($iassign_previous) {
  4586. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4587. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4588. } // next_activity
  4589. if ($iassign_next) {
  4590. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4591. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4592. }
  4593. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4594. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4595. $output .= '</tr></table>' . "\n";
  4596. $output .= '<table width=100% >' . "\n";
  4597. if ($this->activity->type_iassign > 1) {
  4598. if ($this->activity->timeavailable)
  4599. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4600. if ($this->activity->timedue)
  4601. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4602. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4603. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4604. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4605. $output .= '</table>' . "\n";
  4606. print $OUTPUT->box($output);
  4607. } // function view_dates()
  4608. } // class activity
  4609. /// Class to manage Interactive Learning Module (iLM)
  4610. class ilm {
  4611. var $ilm;
  4612. /// Constructor of class
  4613. // @param int $id Id of iLM
  4614. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4615. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4616. function __construct ($id) {
  4617. global $DB;
  4618. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4619. if (empty($this->ilm))
  4620. $this->ilm = null;
  4621. }
  4622. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4623. // @calledby view_iassign_current()
  4624. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4625. global $USER, $CFG, $DB;
  4626. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4627. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4628. $typec = strtolower($iassign_ilm->type);
  4629. require_once 'ilm_handlers/' . $typec . '.php';
  4630. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4631. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4632. return $retorno;
  4633. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4634. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4635. // @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);
  4636. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4637. // @param Object $file File in use in activity
  4638. // @return int Return the id of log
  4639. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4640. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4641. $newentry = new stdClass();
  4642. $newentry->iassign_statementid = $iassign_activity_itemid;
  4643. $newentry->userid = $USER->id;
  4644. $newentry->filesid = $content_or_id_from_ilm_security;
  4645. $newentry->timecreated = time();
  4646. $newentry->view = 1;
  4647. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4648. if (!$id_iLM_security) {
  4649. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4650. } // from (!$DB->insert_record("iassign_security", $newentry))
  4651. return $id_iLM_security;
  4652. }
  4653. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4654. // @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);
  4655. // @param int $userid
  4656. // @param int $iassign_activity_itemid Id of iassign statement
  4657. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4658. global $DB;
  4659. // 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")
  4660. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4661. }
  4662. } // class ilm
  4663. /// Class to manage settings of iLM.
  4664. class ilm_settings {
  4665. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4666. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4667. // @param int $ilm_id Id of iLM
  4668. // @param array $options An array with options for create dynamic tag html APPLET
  4669. // @return string Return with a tag html APPLET created
  4670. static function build_ilm_tags ($ilm_id, $options = array()) {
  4671. global $DB;
  4672. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4673. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4674. $typec = strtolower($iassign_ilm->type);
  4675. require_once 'ilm_handlers/' . $typec . '.php';
  4676. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4677. return $retorno;
  4678. } // static function build_ilm_tags($ilm_id, $options = array())
  4679. /// Function for get modified date of iLM file
  4680. // @param string $file_jar String with Ids of iLM files
  4681. // @return string Return with the filenames and modified date
  4682. static function applet_filetime ($file_jar) {
  4683. $filetime = "";
  4684. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4685. $files_jar = explode(",", $file_jar);
  4686. foreach ($files_jar as $one_file) {
  4687. $file = $fs->get_file_by_id($one_file);
  4688. if ($file)
  4689. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4690. }
  4691. return $filetime;
  4692. }
  4693. /// Function for verify an default applet
  4694. // @param String $file_jar String containing an list de ids of applet files
  4695. // @return boolean Return true or fale if applet is default
  4696. static function applet_default ($file_jar) {
  4697. $is_default = true;
  4698. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4699. $files_jar = explode(",", $file_jar);
  4700. foreach ($files_jar as $one_file) {
  4701. $file = $fs->get_file_by_id($one_file);
  4702. if ($file)
  4703. $is_default &= ($file->get_itemid() == 0);
  4704. }
  4705. return $is_default;
  4706. }
  4707. /// Function for get form variables for add, edit, or copy iLM
  4708. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4709. // @see settings_form.php
  4710. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4711. // @param int $ilm_id Id of iLM
  4712. // @param string $action String with the action
  4713. // @return object Return an object with forms variables
  4714. static function add_edit_copy_ilm ($ilm_id, $action) {
  4715. global $USER, $DB, $CFG;
  4716. require_once('settings_form.php'); // put the form
  4717. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4718. $param = new stdClass();
  4719. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  4720. $param->action = $action;
  4721. $param->ilm_id = $ilm_id;
  4722. $CFG->action_ilm = $action;
  4723. $CFG->ilm_id = $ilm_id;
  4724. if ($action == 'add') {
  4725. $param->title = get_string('add_ilm', 'iassign');
  4726. $param->name = "";
  4727. $param->version = "";
  4728. $param->url = "";
  4729. $param->description = "";
  4730. $param->extension = "";
  4731. $param->author = $USER->id;
  4732. $param->file_jar = "";
  4733. $param->file_jar_static = "";
  4734. $param->file_class = "";
  4735. $param->width = 800;
  4736. $param->height = 600;
  4737. $param->enable = 0; // 0 - hide / 1 - show
  4738. $param->timecreated = time();
  4739. $param->timemodified = time();
  4740. $param->evaluate = 0;
  4741. $param->parent = 0;
  4742. }
  4743. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4744. if ($iassign_ilm) {
  4745. $description = json_decode($iassign_ilm->description);
  4746. $param->title = get_string('edit_ilm', 'iassign');
  4747. $param->id = $iassign_ilm->id;
  4748. $param->name_ilm = $iassign_ilm->name;
  4749. $param->name = $iassign_ilm->name;
  4750. $param->version = $iassign_ilm->version;
  4751. $param->ilm_type = $iassign_ilm->type;
  4752. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4753. $param->url = $iassign_ilm->url; // iLM official URL
  4754. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  4755. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4756. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4757. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4758. if (!isset($description->{current_language()})) {
  4759. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4760. else
  4761. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4762. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4763. }
  4764. else
  4765. $param->description = $description->{current_language()};
  4766. $param->description_lang = $iassign_ilm->description;
  4767. $param->extension = $iassign_ilm->extension;
  4768. $param->author = $iassign_ilm->author;
  4769. $param->file_jar = $iassign_ilm->file_jar;
  4770. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4771. $param->file_class = $iassign_ilm->file_class;
  4772. $param->width = $iassign_ilm->width;
  4773. $param->height = $iassign_ilm->height;
  4774. $param->enable = $iassign_ilm->enable;
  4775. $param->timecreated = $iassign_ilm->timecreated;
  4776. $param->timemodified = time();
  4777. $param->evaluate = $iassign_ilm->evaluate;
  4778. $param->parent = $iassign_ilm->parent;
  4779. }
  4780. }
  4781. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4782. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4783. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4784. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4785. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4786. // echo "Sem dados<br/>"; exit;
  4787. return;
  4788. }
  4789. $description = json_decode($iassign_ilm->description);
  4790. if ($iassign_ilm) {
  4791. if ($iassign_ilm->parent == 0)
  4792. $iassign_ilm->parent = $ilm_id;
  4793. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4794. $param->title = get_string('new_version_ilm', 'iassign');
  4795. $param->name_ilm = $iassign_ilm->name;
  4796. $param->name = $iassign_ilm->name;
  4797. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4798. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4799. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4800. $param->ilm_type = $iassign_ilm->type;
  4801. $param->url = $iassign_ilm->url;
  4802. $param->description = $description->{current_language()};
  4803. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4804. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4805. $param->extension = $iassign_ilm->extension;
  4806. $param->author = $USER->id;
  4807. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4808. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4809. $param->file_jar_static = '';
  4810. $param->file_class = $iassign_ilm->file_class;
  4811. $param->width = $iassign_ilm->width;
  4812. $param->height = $iassign_ilm->height;
  4813. $param->enable = 0;
  4814. $param->timecreated = time();
  4815. $param->timemodified = time();
  4816. $param->evaluate = $iassign_ilm->evaluate;
  4817. $param->parent = $iassign_ilm->parent;
  4818. }
  4819. }
  4820. elseif ($action == 'copy') {
  4821. $description = json_decode($iassign_ilm->description);
  4822. if ($iassign_ilm) {
  4823. if ($iassign_ilm->parent == 0)
  4824. $iassign_ilm->parent = $ilm_id;
  4825. $param->title = get_string('copy_ilm', 'iassign');
  4826. $param->id = $iassign_ilm->id;
  4827. $param->name_ilm = $iassign_ilm->name;
  4828. $param->name = $iassign_ilm->name;
  4829. $param->version = "";
  4830. $param->ilm_type = $iassign_ilm->type;
  4831. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4832. $param->url = $iassign_ilm->url;
  4833. $param->description = $description->{current_language()};
  4834. $param->description_lang = $iassign_ilm->description;
  4835. $param->extension = $iassign_ilm->extension;
  4836. $param->author = $USER->id;
  4837. $param->file_jar = '';
  4838. $param->file_jar_static = '';
  4839. $param->file_class = $iassign_ilm->file_class;
  4840. $param->width = $iassign_ilm->width;
  4841. $param->height = $iassign_ilm->height;
  4842. $param->enable = 0;
  4843. $param->timecreated = time();
  4844. $param->timemodified = time();
  4845. $param->evaluate = $iassign_ilm->evaluate;
  4846. $param->parent = $iassign_ilm->parent;
  4847. }
  4848. }
  4849. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  4850. //D var_dump(debug_backtrace());
  4851. //D print_r(debug_backtrace());
  4852. return $param;
  4853. } // static function add_edit_copy_ilm($ilm_id, $action)
  4854. /// Function for save iLM file in moodledata
  4855. // @param int $itemid Itemid of file save in draft (upload file)
  4856. // @param int $ilm_id Id of iLM
  4857. // @return string Return an string with ids of iLM files
  4858. static function new_file_ilm ($itemid, $iassign_ilm) {
  4859. global $CFG, $USER, $DB;
  4860. $return = null;
  4861. $file_jar = array();
  4862. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4863. $contextuser = context_user::instance($USER->id);
  4864. $contextsystem = context_system::instance();
  4865. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4866. if ($files_ilm) {
  4867. foreach ($files_ilm as $value) {
  4868. // CHECK IF file is HTML type
  4869. if ($iassign_ilm->type == 1) {
  4870. // Check if the file extension is ZIP
  4871. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4872. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4873. if ((strtolower($ext) == 'zip')) {
  4874. // Coping...:
  4875. $destination = 'ilm_debug/' . $value->get_filename();
  4876. $value->copy_content_to($destination);
  4877. // Extracting content...:
  4878. $zip = new ZipArchive();
  4879. $extracted = './ilm';
  4880. $dir = "";
  4881. if ($zip->open($destination) === TRUE) {
  4882. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4883. if (is_dir($dir)) {
  4884. $i = 1;
  4885. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4886. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4887. $i ++;
  4888. }
  4889. $name = $previous . "_" . $i;
  4890. $dir = './ilm/' . $name . "/";
  4891. $j = 0;
  4892. while ($item_name = $zip->getNameIndex($j)) {
  4893. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4894. $j++;
  4895. }
  4896. $zip->close();
  4897. }
  4898. $zip->open($destination);
  4899. $zip->extractTo($extracted);
  4900. $zip->close();
  4901. // After the extraction, remove it from DEBUG
  4902. unlink($destination);
  4903. } else { // Error trying to open destination...
  4904. // After the extraction error, also remove it from DEBUG
  4905. unlink($destination);
  4906. print_error('error_add_ilm_zip', 'iassign');
  4907. }
  4908. return $dir;
  4909. }
  4910. } // if ($iassign_ilm->type == 1)
  4911. if ($value->get_filename() != '.') {
  4912. $file_ilm = array(
  4913. 'userid' => $USER->id,
  4914. 'contextid' => $contextsystem->id,
  4915. 'component' => 'mod_iassign',
  4916. 'filearea' => 'ilm',
  4917. 'itemid' => rand(1, 999999999),
  4918. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4919. 'filename' => $value->get_filename());
  4920. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4921. array_push($file_jar, $file_ilm->get_id());
  4922. }
  4923. }
  4924. if (!empty($file_jar)) {
  4925. $return = implode(",", $file_jar);
  4926. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4927. foreach ($old_file_jar as $value) {
  4928. $file = $fs->get_file_by_id($value);
  4929. if ($file)
  4930. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4931. }
  4932. }
  4933. }
  4934. else // if ($files_ilm)
  4935. $return = $iassign_ilm->file_jar;
  4936. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4937. return $return;
  4938. } // static function new_file_ilm($itemid, $iassign_ilm)
  4939. /// Function for save in database an new iLM
  4940. // @param object $param An object with iLM params
  4941. static function new_ilm ($itemid) {
  4942. global $CFG, $USER, $OUTPUT;
  4943. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4944. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4945. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4946. }
  4947. $pathtemp = $CFG->dataroot . '/temp/';
  4948. $contextuser = context_user::instance($USER->id);
  4949. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4950. $zip = new zip_packer();
  4951. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4952. foreach ($files as $file) {
  4953. if (!$file->is_directory())
  4954. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4955. }
  4956. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4957. // Verifica se o pacote possui o XML
  4958. if (!$application_xml) {
  4959. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4960. return;
  4961. } else {
  4962. $missing = "";
  4963. if (!isset($application_xml->name)) {
  4964. $missing .= "name";
  4965. }
  4966. if (!isset($application_xml->version)) {
  4967. $missing .= ", version";
  4968. }
  4969. if (!isset($application_xml->type)) {
  4970. $missing .= ", type";
  4971. }
  4972. if (!isset($application_xml->extension)) {
  4973. $missing .= ", extension";
  4974. }
  4975. if (!isset($application_xml->file_jar)) {
  4976. $missing .= ", file_jar";
  4977. }
  4978. if (!isset($application_xml->file_class)) {
  4979. $missing .= ", file_class";
  4980. }
  4981. if (!isset($application_xml->width)) {
  4982. $missing .= ", width";
  4983. }
  4984. if (!isset($application_xml->height)) {
  4985. $missing .= ", height";
  4986. }
  4987. if (!isset($application_xml->evaluate)) {
  4988. $missing .= ", evaluate";
  4989. }
  4990. if (strlen($missing) > 2) {
  4991. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4992. return;
  4993. }
  4994. }
  4995. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4996. $typec = strtolower($application_xml->type);
  4997. require_once 'ilm_handlers/' . $typec . '.php';
  4998. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4999. return $retorno;
  5000. } // static function new_ilm($itemid)
  5001. /// Function for save in database an iLM edit
  5002. // @param object $param An object with iLM params
  5003. static function edit_ilm ($param, $itemid) {
  5004. // Descobrir o tipo de iLM:
  5005. global $DB, $USER, $CFG;
  5006. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5007. $pathtemp = $CFG->dataroot . '/temp/';
  5008. $contextuser = context_user::instance($USER->id);
  5009. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5010. $zip = new zip_packer();
  5011. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5012. $files_extract = null;
  5013. foreach ($files as $file) {
  5014. if (!$file->is_directory())
  5015. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5016. }
  5017. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5018. $typec = strtolower($iassign_t->type);
  5019. require_once 'ilm_handlers/' . $typec . '.php';
  5020. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5021. }
  5022. /// Function for register the new iLM (in database and in the directory)
  5023. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5024. // @param object $param An object with iLM params
  5025. static function copy_new_version_ilm ($param) {
  5026. global $DB, $CFG, $USER;
  5027. $itemid = $param->file;
  5028. $pathtemp = $CFG->dataroot . '/temp/';
  5029. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5030. //D echo "pathtemp=$pathtemp<br/>";
  5031. $contextuser = context_user::instance($USER->id);
  5032. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5033. $zip = new zip_packer();
  5034. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5035. $files_extract = null;
  5036. foreach ($files as $file) {
  5037. if (!$file->is_directory())
  5038. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5039. }
  5040. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5041. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5042. $typec = strtolower($iassign_t->type);
  5043. require_once 'ilm_handlers/' . $typec . '.php';
  5044. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5045. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5046. } // static function copy_new_version_ilm($param)
  5047. //VER::
  5048. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5049. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5050. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5051. /// Function for change visibility of iLM
  5052. // @param int $ilm_id Id of iLM
  5053. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5054. static function visible_ilm ($ilm_id, $status) {
  5055. global $DB;
  5056. if ($status == 0)
  5057. $visible = 1;
  5058. else
  5059. $visible = 0;
  5060. $newentry = new stdClass();
  5061. $newentry->id = $ilm_id;
  5062. $newentry->enable = $visible;
  5063. if (!$DB->update_record("iassign_ilm", $newentry))
  5064. error(get_string('error_edit_ilm', 'iassign'));
  5065. }
  5066. /// Function for confirm change default iLM
  5067. // @param int $ilm_id Id of iLM
  5068. // @param int $ilm_parent Id of parent iLM
  5069. // @return string Return with an string for create default page confirmation
  5070. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5071. global $OUTPUT, $DB;
  5072. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5073. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5074. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5075. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5076. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5077. return $return;
  5078. }
  5079. /// Function for change the default iLM
  5080. // @see settings_ilm.php
  5081. // @param int $ilm_id Id of iLM
  5082. // @return int Return Id of default iLM
  5083. static function default_ilm ($ilm_id) {
  5084. global $DB;
  5085. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5086. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5087. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5088. $iassign_ilm_default->id = $iassign_ilm->id;
  5089. $iassign_ilm_default->parent = 0;
  5090. $iassign_ilm->parent = $iassign_ilm_default->id;
  5091. $iassign_ilm->id = 0;
  5092. $iassign_ilm_default->enable = 1;
  5093. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5094. print_error('error_edit_ilm', 'iassign');
  5095. }
  5096. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5097. if (!$inserted) {
  5098. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5099. print_error($msg_error);
  5100. //xx print_error('error_add_ilm', 'iassign');
  5101. }
  5102. return $iassign_ilm_default->id;
  5103. } // static function default_ilm ($ilm_id)
  5104. /// Function for confirm delete iLM
  5105. // @param int $ilm_id Id of iLM
  5106. // @param int $ilm_parent Id of parent iLM
  5107. // @return string Return with an string for create delete page confirmation
  5108. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5109. global $OUTPUT, $DB;
  5110. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5111. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5112. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5113. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5114. }
  5115. /// Function for delete directory where the iLM is allocated.
  5116. // @param string $dirPath
  5117. // @throws InvalidArgumentException
  5118. public static function delete_dir ($dirPath) {
  5119. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5120. $dirPath .= '/';
  5121. }
  5122. $files = glob($dirPath . '*', GLOB_MARK);
  5123. foreach ($files as $file) {
  5124. if (is_dir($file)) {
  5125. ilm_settings::delete_dir($file);
  5126. } else {
  5127. unlink($file);
  5128. }
  5129. }
  5130. rmdir($dirPath);
  5131. }
  5132. /// Function for delete iLM
  5133. // @param int $ilm_id Id of iLM
  5134. // @return int Return Id of parent iLM
  5135. static function delete_ilm ($ilm_id) {
  5136. global $DB;
  5137. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5138. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5139. $typec = strtolower($iassign_ilm->type);
  5140. require_once 'ilm_handlers/' . $typec . '.php';
  5141. $retorno = $typec::delete_ilm($ilm_id);
  5142. return $retorno;
  5143. }
  5144. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5145. // @param int $ilm_id Id of iLM
  5146. static function export_ilm ($ilm_id) {
  5147. global $DB;
  5148. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5149. if (!$iassign_ilm) return; // security debug...
  5150. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5151. $typec = strtolower($iassign_ilm->type);
  5152. if (!$typec) $typec = "html5"; // security debug...
  5153. require_once 'ilm_handlers/' . $typec . '.php';
  5154. $typec::export_ilm($ilm_id);
  5155. } // static function export_ilm($ilm_id)
  5156. //TODO iLM_HTML5 :: //MOOC 2016
  5157. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5158. // @param int $ilm_id Id of iLM
  5159. static function export_update_ilm ($ilm_id) {
  5160. global $DB, $CFG;
  5161. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5162. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5163. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5164. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5165. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5166. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5167. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5168. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5169. $upgrade_descriptor .= '</upgrade>' . "\n";
  5170. file_put_contents($xml_filename, $upgrade_descriptor);
  5171. header("Pragma: public");
  5172. header("Expires: 0");
  5173. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5174. header("Cache-Control: private", false);
  5175. header('Content-Type: application/xml; charset=utf-8');
  5176. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5177. header("Content-Length: " . @filesize($xml_filename));
  5178. set_time_limit(0);
  5179. @readfile("$xml_filename") || die("File not found.");
  5180. unlink($xml_filename);
  5181. exit;
  5182. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5183. /// Function for save iLM from XML descriptor
  5184. // @param array $application_xml Data of XML descriptor
  5185. // @param array $files_extract Filenames of extract files
  5186. // @return array Return an array content id of JAR files
  5187. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5188. global $CFG, $USER;
  5189. // Tratamento diferenciado se for do tipo HTML5:
  5190. $source = "";
  5191. $diretorio = "";
  5192. if (strtolower($application_xml->type) == 'html5') {
  5193. $i = 0;
  5194. foreach ($files_extract as $key => $value) {
  5195. $file = $CFG->dataroot . '/temp/' . $key;
  5196. // Verifica se já existe a pasta no diretório dos iLM:
  5197. if ($i == 0) {
  5198. $source = $file;
  5199. if (file_exists("ilm/" . basename($file))) {
  5200. $j = 1;
  5201. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5202. $j ++;
  5203. }
  5204. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5205. // mkdir($diretorio, 0777, true);
  5206. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5207. }
  5208. else {
  5209. $diretorio = 'ilm/' . basename($file);
  5210. // mkdir($diretorio, 0777, true);
  5211. mkdir($diretorio, 0755, true);
  5212. }
  5213. break;
  5214. }
  5215. $i ++;
  5216. }
  5217. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5218. if ($item->isDir()) {
  5219. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5220. }
  5221. else {
  5222. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5223. }
  5224. }
  5225. ilm_settings::delete_dir($source);
  5226. return "./" . $diretorio;
  5227. }
  5228. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5229. $file_jar = array();
  5230. $files_ilm = explode(",", $application_xml->file_jar);
  5231. $contextsystem = context_system::instance();
  5232. foreach ($files_ilm as $value) {
  5233. $file_ilm = array(
  5234. 'userid' => $USER->id,
  5235. 'contextid' => $contextsystem->id,
  5236. 'component' => 'mod_iassign',
  5237. 'filearea' => 'ilm',
  5238. 'itemid' => rand(1, 999999999),
  5239. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5240. 'filename' => $value);
  5241. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5242. array_push($file_jar, $file_ilm->get_id());
  5243. }
  5244. foreach ($files_extract as $key => $value) {
  5245. $file = $CFG->dataroot . '/temp/' . $key;
  5246. if (file_exists($file))
  5247. unlink($file);
  5248. }
  5249. return $file_jar;
  5250. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5251. /// Function for import the iLM from an package
  5252. // @param int $itemid Itemid of zip file
  5253. static function import_ilm ($itemid) {
  5254. global $CFG, $USER, $OUTPUT;
  5255. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5256. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5257. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5258. }
  5259. $pathtemp = $CFG->dataroot . '/temp/';
  5260. $contextuser = context_user::instance($USER->id);
  5261. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5262. $zip = new zip_packer();
  5263. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5264. foreach ($files as $file) {
  5265. if (!$file->is_directory())
  5266. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5267. }
  5268. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5269. // Verifica se o pacote possui o XML
  5270. if (!$application_xml) {
  5271. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5272. return;
  5273. } else {
  5274. $missing = "";
  5275. if (!isset($application_xml->name)) {
  5276. $missing .= "name";
  5277. }
  5278. if (!isset($application_xml->version)) {
  5279. $missing .= ", version";
  5280. }
  5281. if (!isset($application_xml->type)) {
  5282. $missing .= ", type";
  5283. }
  5284. if (!isset($application_xml->extension)) {
  5285. $missing .= ", extension";
  5286. }
  5287. if (!isset($application_xml->file_jar)) {
  5288. $missing .= ", file_jar";
  5289. }
  5290. if (!isset($application_xml->file_class)) {
  5291. $missing .= ", file_class";
  5292. }
  5293. if (!isset($application_xml->width)) {
  5294. $missing .= ", width";
  5295. }
  5296. if (!isset($application_xml->height)) {
  5297. $missing .= ", height";
  5298. }
  5299. if (!isset($application_xml->evaluate)) {
  5300. $missing .= ", evaluate";
  5301. }
  5302. if (strlen($missing) > 2) {
  5303. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5304. return;
  5305. }
  5306. }
  5307. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5308. $typec = strtolower($application_xml->type);
  5309. require_once 'ilm_handlers/' . $typec . '.php';
  5310. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5311. } // static function import_ilm($itemid)
  5312. /// Function for list iLM defaults
  5313. // @return string Return an string with a table of iLM
  5314. static function list_ilm () {
  5315. global $DB, $OUTPUT;
  5316. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5317. $str = '';
  5318. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5319. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5320. if ($iassign_ilm) {
  5321. foreach ($iassign_ilm as $ilm) {
  5322. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5323. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5324. $str .= '<tr><td>';
  5325. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5326. $str .= '<tr>';
  5327. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5328. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5329. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5330. $str .= '</tr>';
  5331. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5332. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5333. $str .= '</table>';
  5334. $str .= '</td></tr>';
  5335. }
  5336. }
  5337. $str .= '</table>';
  5338. return $str;
  5339. }
  5340. /// Function for download and install an upgrade of an iLM
  5341. // @param int $ilm_id Id of iLM
  5342. static function upgrade_ilm ($ilm_id) {
  5343. global $DB, $CFG, $USER;
  5344. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5345. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5346. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5347. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5348. if (!$result)
  5349. print_error('error_upgrade_ilm', 'iassign');
  5350. else {
  5351. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5352. $extension = explode(".", $zip_filename);
  5353. if ($extension[count($extension) - 1] != 'ipz') {
  5354. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5355. die;
  5356. }
  5357. $zip = new zip_packer();
  5358. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5359. $contextuser = context_user::instance($USER->id);
  5360. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5361. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5362. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5363. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5364. if (file_exists($zip_filename))
  5365. unlink($zip_filename);
  5366. if (empty($file_jar)) {
  5367. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5368. print_error($msg_error);
  5369. //xx print_error('error_add_ilm', 'iassign');
  5370. }
  5371. else {
  5372. $newentry = new stdClass();
  5373. $newentry->name = (String) $application_xml->name;
  5374. $newentry->version = (String) $application_xml->version;
  5375. $newentry->url = (String) $application_xml->url;
  5376. $newentry->description = $description_str;
  5377. $newentry->extension = strtolower((String) $application_xml->extension);
  5378. $newentry->file_jar = implode(",", $file_jar);
  5379. $newentry->file_class = (String) $application_xml->file_class;
  5380. $newentry->width = (String) $application_xml->width;
  5381. $newentry->height = (String) $application_xml->height;
  5382. $newentry->enable = 0;
  5383. $newentry->timemodified = time();
  5384. $newentry->author = $USER->id;
  5385. $newentry->timecreated = time();
  5386. $newentry->evaluate = (String) $application_xml->evaluate;
  5387. $newentry->parent = $ilm_id;
  5388. }
  5389. }
  5390. return $iassign_ilm->id;
  5391. } // static function upgrade_ilm($ilm_id)
  5392. //MOOC2014 -- inicio
  5393. //TODO: REVIEW
  5394. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5395. // static function move_iassign($ilm_id)
  5396. //MOOC2014 -- final
  5397. /// Function for list iLM versions with all informations
  5398. // @return string Return an string with a table of iLM
  5399. static function view_ilm ($ilmid, $from) {
  5400. global $DB;
  5401. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5402. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5403. $typec = strtolower($iassign_ilm->type);
  5404. require_once 'ilm_handlers/' . $typec . '.php';
  5405. $retorno = $typec::view_ilm($ilmid, $from);
  5406. return $retorno;
  5407. }
  5408. /// Function for get form variables for add, edit, or copy iLM params
  5409. // @param int $ilm_param_id Id of iLM param
  5410. // @param string $action String with the action
  5411. // @return object Return an object with forms variables
  5412. static function add_edit_copy_param ($ilm_param_id, $action) {
  5413. global $DB;
  5414. require_once('params_form.php');
  5415. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5416. $param = new stdClass();
  5417. $param->action = $action;
  5418. $param->ilm_param_id = $ilm_param_id;
  5419. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5420. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5421. $type = $iassign_ilm_config->param_type;
  5422. if ($action == 'add') {
  5423. $param->title = get_string('add_ilm', 'iassign');
  5424. $param->iassign_ilmid = $ilm_param_id;
  5425. $param->param_name = "";
  5426. $param->param_value = "";
  5427. $param->description = "";
  5428. $param->visible = 1;
  5429. }
  5430. elseif ($action == 'edit') {
  5431. if ($iassign_ilm_config) {
  5432. $param->title = get_string('edit_ilm', 'iassign');
  5433. $param->id = $iassign_ilm_config->id;
  5434. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5435. $param->param_type = $type; //MOOC2014
  5436. $param->param_name = $iassign_ilm_config->param_name;
  5437. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5438. $param->param_value = $iassign_ilm_config->param_value;
  5439. else //MOOC2014
  5440. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5441. $param->param_value = $iassign_ilm_config->param_value;
  5442. $param->description = $iassign_ilm_config->description;
  5443. $param->visible = $iassign_ilm_config->visible;
  5444. }
  5445. }
  5446. elseif ($action == 'copy') {
  5447. if ($iassign_ilm_config) {
  5448. $param->title = get_string('copy_ilm', 'iassign');
  5449. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5450. $param->param_type = $type; //MOOC2014
  5451. $param->param_name = $iassign_ilm_config->param_name;
  5452. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5453. $param->param_value = $iassign_ilm_config->param_value;
  5454. else //MOOC2014
  5455. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5456. $param->description = $iassign_ilm_config->description;
  5457. $param->visible = $iassign_ilm_config->visible;
  5458. }
  5459. }
  5460. return $param;
  5461. } // static function add_edit_copy_param($ilm_param_id, $action)
  5462. /// Function for change visibility of iLM param
  5463. // @param int $ilm_param_id Id of iLM param
  5464. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5465. static function visible_param ($ilm_param_id, $status) {
  5466. global $DB, $CFG;
  5467. if ($status == 0)
  5468. $visible = 1;
  5469. else
  5470. $visible = 0;
  5471. $newentry = new stdClass();
  5472. $newentry->id = $ilm_param_id;
  5473. $newentry->visible = $visible;
  5474. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5475. error(get_string('error_edit_param', 'iassign'));
  5476. }
  5477. /// Function for save in database an new iLM param
  5478. // @param object $param An object with iLM params
  5479. static function add_param ($param) {
  5480. global $DB;
  5481. $newentry = new stdClass();
  5482. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5483. //MOOC2014 $newentry->param_name = $param->param_name;
  5484. $newentry->param_type = $param->param_type; //MOOC2014
  5485. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5486. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5487. $newentry->param_value = $param->param_value;
  5488. else //MOOC2014
  5489. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5490. $newentry->description = $param->description;
  5491. $newentry->visible = $param->visible;
  5492. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5493. if (!$newentry->id) {
  5494. print_error('error_add_param', 'iassign');
  5495. }
  5496. }
  5497. /// Function for save in database a iLM param edit
  5498. // @param object $param An object with iLM params
  5499. static function edit_param ($param) {
  5500. global $DB;
  5501. $updentry = new stdClass();
  5502. $updentry->id = $param->id;
  5503. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5504. $updentry->param_type = $param->param_type; //MOOC2014
  5505. // $updentry->param_name = $param->param_name;
  5506. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5507. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5508. $updentry->param_value = $param->param_value;
  5509. else //MOOC2014
  5510. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5511. $updentry->description = $param->description;
  5512. $updentry->visible = $param->visible;
  5513. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5514. error(get_string('error_edit_param', 'iassign'));
  5515. }
  5516. }
  5517. /// Function for save in database a iLM param copy
  5518. // @param object $param An object with iLM params
  5519. static function copy_param ($param) {
  5520. global $DB;
  5521. $newentry = new stdClass();
  5522. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5523. //$newentry->param_name = $param->param_name;
  5524. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5525. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5526. $newentry->param_value = $param->param_value;
  5527. else //MOOC2014
  5528. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5529. $newentry->description = $param->description;
  5530. $newentry->visible = $param->visible;
  5531. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5532. if (!$newentry->id) {
  5533. print_error('error_add_param', 'iassign');
  5534. }
  5535. }
  5536. /// Function for delete iLM param of database
  5537. // @param int $param_id Id of iLM param
  5538. static function delete_param ($param_id) {
  5539. global $DB;
  5540. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5541. print_error('error_delete_param', 'iassign');
  5542. }
  5543. }
  5544. } // class ilm_settings
  5545. /// Class for manage iLM files (editor).
  5546. class ilm_manager {
  5547. var $id; // course id
  5548. var $url;
  5549. var $from;
  5550. /// Constructor for the base ilm_manager class
  5551. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5552. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5553. function __construct ($id, $url, $from) {
  5554. $this->id = $id; // course id
  5555. $this->url = $url;
  5556. $this->from = $from;
  5557. }
  5558. /// Function to get iAssign content file in Moodle data (exercise)
  5559. // @calledby x function preview_ilm($iassign_ilm) :
  5560. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5561. function get_file_ilm () {
  5562. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5563. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5564. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5565. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5566. $md_file = $fs->get_file_by_id($fileid);
  5567. $ilm_content_file = $md_file->get_content();
  5568. return $ilm_content_file;
  5569. }
  5570. /// Function for creating a new file from the iLM online editor
  5571. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5572. function ilm_editor_new () {
  5573. global $CFG, $DB, $OUTPUT, $PAGE;
  5574. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5575. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5576. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5577. $context = context_course::instance($this->id);
  5578. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5579. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5580. if (!$iassign) {
  5581. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5582. die();
  5583. }
  5584. $temp = explode(",", $iassign->extension);
  5585. $extension = $temp[0]; // default extension for this iLM
  5586. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5587. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5588. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5589. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5590. if ($stringArchiveContent != NULL) {
  5591. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5592. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5593. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5594. $filename = optional_param('filename', NULL, PARAM_RAW);
  5595. //Leo $filename = iassign_utils::format_filename($filename); //
  5596. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5597. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5598. //2019/02 $arrayfilename = explode(".", $filename);
  5599. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5600. //2019/02 $count_dots = count($arrayfilename);
  5601. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5602. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5603. //2019/02 if ($last_name != $extension)
  5604. //2019/02 $filename = $filename . '.' . $extension;
  5605. //2019/02 }
  5606. //2019/02 else { // no extension...
  5607. //2019/02 $filename = $filename . '.' . $extension;
  5608. //2019/02 }
  5609. // Store the name of recent created file
  5610. $_SESSION['file_name'] = $filename;
  5611. //$this->write_file_iassign($string, $filename);
  5612. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5613. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5614. die();
  5615. }
  5616. else { // if ($stringArchiveContent != NULL)
  5617. // iLM On-line editor
  5618. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5619. $str_get_iLM = "window.frames.iLM";
  5620. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5621. }
  5622. else { // otherwise it is JAR named 'iLM'
  5623. $str_get_iLM = "document.iLM";
  5624. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5625. }
  5626. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5627. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5628. $files_array = '';
  5629. foreach ($files as $value) {
  5630. if ($value->get_filename() != ".")
  5631. $files_array .= "'" . $value->get_filename() . "',";
  5632. }
  5633. $files_array .= "''";
  5634. $file = null;
  5635. $ia_content = "";
  5636. $filename = "";
  5637. $error_files_exists = get_string('error_file_exists', 'iassign');
  5638. $output = "<script type='text/javascript'>
  5639. //<![CDATA[
  5640. //D alert('locallib.php: ilm_editor_new');
  5641. function submit_iLM_Answer () {
  5642. var docFormOnLineEditor = document.formEnvio;
  5643. var resposta_exerc = new Array(3);
  5644. var valor_resposta = new Array(3);
  5645. var sessao = new Array(3);
  5646. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5647. resposta_exerc[0] = doc_iLM.getAnswer();
  5648. valor_resposta[0] = doc_iLM.getEvaluation();
  5649. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5650. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5651. var files = new Array(" . $files_array . ");
  5652. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5653. if (docFormOnLineEditor.filename.value=='') {
  5654. // ERROR: the file name is empty
  5655. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5656. return false;
  5657. }
  5658. // }
  5659. for (i=0; i<files.length; i++) {
  5660. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5661. alert('" . $error_files_exists . "');
  5662. return false;
  5663. }
  5664. }
  5665. docFormOnLineEditor.submit();
  5666. return true;
  5667. }
  5668. //]]>
  5669. </script>\n";
  5670. $output .= "
  5671. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5672. $output .= $OUTPUT->box_start();
  5673. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5674. $output .= "
  5675. <table width='100%' cellpadding='20'>
  5676. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5677. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5678. </tr>
  5679. </table>\n";
  5680. $output .= $OUTPUT->box_end();
  5681. $output .= "<center>\n";
  5682. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5683. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5684. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5685. $output .= $output_ilm;
  5686. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5687. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5688. </center>
  5689. </form>\n";
  5690. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5691. $PAGE->navbar->add($title);
  5692. $PAGE->set_title($title);
  5693. $PAGE->set_heading($title); // insert title above the navigation bar
  5694. print $OUTPUT->header();
  5695. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5696. print $output;
  5697. print $OUTPUT->footer();
  5698. }
  5699. die();
  5700. } // function ilm_editor_new()
  5701. /// Function for editing an file in online editor
  5702. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5703. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5704. global $CFG, $DB, $OUTPUT, $PAGE;
  5705. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5706. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5707. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5708. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5709. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5710. // If iLM is not registered, error!
  5711. if (!$iassign) {
  5712. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5713. die;
  5714. }
  5715. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5716. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5717. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5718. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5719. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5720. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5721. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5722. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5723. if ($stringArchiveContent != NULL) {
  5724. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5725. die();
  5726. } else { // if ($stringArchiveContent != NULL)
  5727. $end_file = '';
  5728. if ($content_file) {
  5729. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5730. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5731. }
  5732. $temp = explode(",", $iassign->extension);
  5733. $extension = $temp[0]; // default extension for this iLM
  5734. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5735. $str_get_iLM = "window.frames.iLM";
  5736. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5737. } else { // otherwise it is JAR named 'iLM'
  5738. $str_get_iLM = "document.iLM";
  5739. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5740. }
  5741. $output = "<script type='text/javascript'>
  5742. //<![CDATA[
  5743. function submit_iLM_Answer () {
  5744. var docFormEditor = document.formEnvio;
  5745. var activityAnswer; // to get activity answer (text)
  5746. var activityValue; // to get activity answer value (float)
  5747. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5748. //activityAnswer = doc_iLM.getAnswer();
  5749. //activityValue = doc_iLM.getEvaluation();
  5750. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5751. activityValue = " . $str_get_iLM . ".getEvaluation();
  5752. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5753. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5754. docFormEditor.submit();
  5755. return true;
  5756. }
  5757. //]]>
  5758. </script>\n";
  5759. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5760. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5761. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5762. // return true;
  5763. // }
  5764. $output .= "
  5765. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5766. $output .= $OUTPUT->box_start();
  5767. $output .= "
  5768. <table width='100%' cellpadding='20'>
  5769. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5770. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5771. <input type='hidden' name='filename' value='$filename'/></td>
  5772. <td>
  5773. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5774. </tr>
  5775. </table>\n";
  5776. $output .= $OUTPUT->box_end();
  5777. $output .= " <center>\n";
  5778. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5779. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5780. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5781. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5782. </center>
  5783. </form>\n";
  5784. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5785. $PAGE->navbar->add($title);
  5786. $PAGE->set_title($title);
  5787. $PAGE->set_heading($title); // insert title above the navigation bar
  5788. print $OUTPUT->header();
  5789. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5790. print $output;
  5791. print $OUTPUT->footer();
  5792. } // else if ($stringArchiveContent != NULL)
  5793. die();
  5794. } // function ilm_editor_update()
  5795. /// Function for write iAssign file in Moodle data (exercise)
  5796. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5797. // @param string $stringArchiveContent Content of iassign file
  5798. // @param string $filename Filename of iassign file
  5799. function write_file_iassign ($stringArchiveContent, $filename) {
  5800. global $USER;
  5801. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5802. $context = context_course::instance($this->id);
  5803. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5804. $dirid = $this->get_dir_ilm('dirid');
  5805. $dir = $fs->get_file_by_id($dirid);
  5806. $fileinfo = array('contextid' => $context->id, // ID of course
  5807. 'component' => 'mod_iassign', // usually = table name
  5808. 'filearea' => 'activity', // usually = table name
  5809. 'itemid' => 0, // usually = ID of row in table
  5810. 'filepath' => '/', // any path beginning and ending whith '/'
  5811. 'userid' => $USER->id,
  5812. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5813. 'filename' => $filename); // any filename
  5814. // Create file containing text. '$stringArchiveContent'
  5815. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5816. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5817. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5818. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5819. // 'Activité interactive enregistrée avec succès sous le nom:';
  5820. // 'Atividade interativa gravada com sucesso sob o nome:'
  5821. $output = "
  5822. <script type='text/javascript'>
  5823. //<![CDATA[
  5824. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5825. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5826. //]]>
  5827. </script>";
  5828. print $output;
  5829. die();
  5830. }
  5831. /// Function for write iAssign file in Moodle data (exercise)
  5832. // @param string $stringArchiveContent Content of iassign file
  5833. // @param string $filename Filename of iassign file
  5834. // @param int $itemid Itemid of iassign file
  5835. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5836. global $OUTPUT, $USER;
  5837. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5838. $context = context_course::instance($this->id);
  5839. $dirid = $this->get_dir_ilm('dirid');
  5840. if ($stringArchiveContent != (-1)) {
  5841. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5842. $file = $fs->get_file_by_id($fileid);
  5843. if (!$file) {
  5844. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5845. die;
  5846. }
  5847. $fileinfo = array('contextid' => $context->id, // ID of context
  5848. 'component' => 'mod_iassign', // usually = table name
  5849. 'filearea' => 'activity', // usually = table name
  5850. 'itemid' => 0, // usually = ID of row in table
  5851. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5852. 'userid' => $USER->id,
  5853. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5854. 'license' => 'allrightsreserved', // allrightsreserved
  5855. 'timecreated' => $file->get_timecreated(),
  5856. 'filename' => $file->get_filename()); // any filename
  5857. $file->delete();
  5858. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5859. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5860. }
  5861. $output = "<script type='text/javascript'>
  5862. //<![CDATA[
  5863. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5864. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5865. //]]>
  5866. </script>";
  5867. print $output;
  5868. die();
  5869. }
  5870. /// Function for create an tag for iAssign filter
  5871. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5872. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5873. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5874. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5875. // @param int $fileid Id of file
  5876. // @return string Return an string with an tag of iassign filter
  5877. function tag_ilm ($fileid) {
  5878. global $DB;
  5879. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5880. $width = '600';
  5881. $height = '400';
  5882. $file = $fs->get_file_by_id($fileid);
  5883. $filetype = explode(".", $file->get_filename());
  5884. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5885. foreach ($iassign_ilm as $value) {
  5886. $extensions = explode(",", $value->extension);
  5887. if (in_array($filetype[1], $extensions)) {
  5888. $width = $value->width;
  5889. $height = $value->height;
  5890. }
  5891. }
  5892. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5893. }
  5894. /// Function for delete iAssign file in Moodle data (exercise)
  5895. function delete_file_ilm () {
  5896. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5897. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5898. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5899. $file = $fs->get_file_by_id($fileid);
  5900. if ($file)
  5901. $file->delete();
  5902. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5903. die();
  5904. }
  5905. /// Function for delete selected iAssign file in Moodle data (exercise)
  5906. function delete_selected_ilm () {
  5907. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5908. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5909. $context = context_course::instance($this->id);
  5910. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5911. $dirid = $this->get_dir_ilm('dirid');
  5912. foreach ($files_id as $file_id) {
  5913. $file = $fs->get_file_by_id($file_id);
  5914. if ($file) {
  5915. if (!$file->is_directory())
  5916. $file->delete();
  5917. else {
  5918. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5919. foreach ($files_delete as $value)
  5920. $value->delete();
  5921. $file->delete();
  5922. }
  5923. }
  5924. }
  5925. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5926. die();
  5927. }
  5928. /// Function for duplicate iAssign file from "online" edition
  5929. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5930. function duplicate_file_ilm () {
  5931. global $USER, $COURSE;
  5932. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5933. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5934. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5935. $filename = optional_param('filename', NULL, PARAM_RAW);
  5936. $file = $fs->get_file_by_id($fileid);
  5937. $context = context_course::instance($this->id);
  5938. $fileinfo = array(
  5939. 'contextid' => $context->id, // ID of context
  5940. 'component' => 'mod_iassign', // usually = table name
  5941. 'filearea' => 'activity', // usually = table name
  5942. 'itemid' => 0, // usually = ID of row in table
  5943. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5944. 'userid' => $USER->id,
  5945. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5946. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5947. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5948. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5949. die();
  5950. }
  5951. /// Function for rename iAssign file
  5952. function rename_file_ilm () {
  5953. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5954. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5955. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5956. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5957. $file = $fs->get_file_by_id($fileid);
  5958. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5959. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5960. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5961. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5962. die();
  5963. }
  5964. /// Function for get iassign file for iassign form
  5965. function add_ilm () {
  5966. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5967. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5968. $output = "
  5969. <script type='text/javascript'>
  5970. //<![CDATA[
  5971. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5972. iassign_file_link.innerHTML = '$filename';
  5973. window.opener.document.forms['mform1'].file.value='$fileid';
  5974. window.opener.document.forms['mform1'].filename.value='$filename';
  5975. window.close();
  5976. //]]>
  5977. </script>";
  5978. print $output;
  5979. die();
  5980. }
  5981. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5982. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5983. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5984. function preview_ilm ($courseid, $iassign_ilm) {
  5985. global $OUTPUT, $CFG, $USER;
  5986. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5987. $title = get_string('modulename', 'iassign'); // iAssign
  5988. print $OUTPUT->header();
  5989. print $OUTPUT->box_start();
  5990. $javascript = "
  5991. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5992. <script type='text/javascript'>
  5993. //<![CDATA[
  5994. function submit_close () {
  5995. window.opener.location.reload();
  5996. window.close();
  5997. }
  5998. //]]>
  5999. </script>\n";
  6000. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6001. // to the complete "applet" tag
  6002. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6003. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6004. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6005. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6006. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6007. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6008. if ($ilm_name != "ivprog") {
  6009. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6010. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6011. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6012. } else {
  6013. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6014. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6015. $timecreated = time();
  6016. $token = md5($timecreated);
  6017. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6018. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6019. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6020. $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)
  6021. }
  6022. $html = "
  6023. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6024. <table border='1'>
  6025. <tr><td>
  6026. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6027. <!-- iLM calls : end -->
  6028. </td></tr>
  6029. </table>
  6030. <table>
  6031. <tr>
  6032. <td align='center'>
  6033. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6034. </td></tr>
  6035. </table>
  6036. </form>\n";
  6037. print $javascript . $html;
  6038. print $OUTPUT->box_end();
  6039. //NAO echo format_string($html); // Moodle 3.X
  6040. die();
  6041. } // function preview_ilm($courseid, $iassign_ilm)
  6042. //r_ function preview_ilm ($iassign_ilm)
  6043. //r_ /// Function for preview iassign file from iassign filter.
  6044. //r_ function preview_ilm() {
  6045. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6046. //r_ $tag_filter = $this->tag_ilm($fileid);
  6047. //r_ $javascript = "<script type='text/javascript'>
  6048. //r_ //<![CDATA[
  6049. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6050. //r_ //]]>
  6051. //r_ </script>";
  6052. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6053. //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>
  6054. //r_ </table></form></body></html>";
  6055. //r_ echo $javascript . format_text($html);
  6056. //r_ die;
  6057. //r_ }
  6058. /// Function for export an package (zip) of iassign files
  6059. function export_files_ilm () {
  6060. global $CFG;
  6061. $context = context_course::instance($this->id);
  6062. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6063. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6064. $zip = new zip_archive();
  6065. $zip->open($zip_filename);
  6066. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6067. foreach ($files_id as $file_id) {
  6068. $file = $fs->get_file_by_id($file_id);
  6069. if (!$file->is_directory())
  6070. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6071. else {
  6072. $zip->add_directory($file->get_filepath());
  6073. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6074. foreach ($files_zip as $value) {
  6075. if (!$value->is_directory())
  6076. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6077. else
  6078. $zip->add_directory($value->get_filepath());
  6079. }
  6080. }
  6081. }
  6082. $zip->close();
  6083. header("Pragma: public");
  6084. header("Expires: 0");
  6085. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6086. header("Cache-Control: private", false);
  6087. header("Content-Type: application/zip");
  6088. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6089. header("Content-Transfer-Encoding: binary");
  6090. header("Content-Length: " . @filesize($zip_filename));
  6091. set_time_limit(0);
  6092. @readfile("$zip_filename") || die("File not found.");
  6093. unlink($zip_filename);
  6094. exit;
  6095. }
  6096. /// Function of execute a command in button editor tinymce
  6097. // @param int $fileid Id of file
  6098. function tinymce_ilm ($fileid) {
  6099. $tag_filter = $this->tag_ilm($fileid);
  6100. $output = "<script type='text/javascript'>
  6101. //<![CDATA[
  6102. var tag_filter = '$tag_filter';
  6103. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6104. // all right, insert it
  6105. } else {
  6106. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6107. }
  6108. // window.close();
  6109. //]]>
  6110. </script>\n";
  6111. print $output;
  6112. die();
  6113. }
  6114. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6115. /// Function to add content to the Editor Window
  6116. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6117. // @param int $fileid Id of file
  6118. function editor_ilm ($fileid, $editor) {
  6119. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6120. $output1 = "<script type='text/javascript'>
  6121. //<![CDATA[
  6122. var tag_filter = '$tag_filter';\n";
  6123. if ($editor == 'atto') {
  6124. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6125. } elseif ($editor == 'tinyMCE') {
  6126. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6127. } else
  6128. $output2 = "";
  6129. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6130. window.close();
  6131. //]]>
  6132. </script>\n";
  6133. //D var_dump($output);
  6134. print $output1 . $output2 . $output3;
  6135. die();
  6136. }
  6137. /// Function to add content to the Atto Editor Window
  6138. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6139. // @param int $fileid Id of file
  6140. function atto_ilm ($fileid) {
  6141. global $CFG, $DB;
  6142. $tag_filter = $this->tag_ilm($fileid);
  6143. $output = "<script type='text/javascript'>
  6144. //<![CDATA[
  6145. var tag_filter = '$tag_filter';
  6146. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6147. // all right, insert iLM tag to this editor
  6148. } else {
  6149. // error trying to insert
  6150. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6151. }
  6152. //window.close();
  6153. //]]>
  6154. </script>\n";
  6155. print $output;
  6156. die();
  6157. }
  6158. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6159. // @param string $key Key for return information
  6160. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6161. function get_dir_ilm ($key) {
  6162. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6163. $context = context_course::instance($this->id);
  6164. $dirid = optional_param('dirid', 0, PARAM_INT);
  6165. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6166. if ($dirid == 0) {
  6167. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6168. $dirid = $dir->get_id();
  6169. }
  6170. else {
  6171. $dir = $fs->get_file_by_id($dirid);
  6172. $dir_base = $dir->get_filepath();
  6173. }
  6174. $dir_parent = $dir->get_parent_directory();
  6175. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6176. return $data[$key];
  6177. }
  6178. /// Function for create an new dir
  6179. function new_dir_ilm () {
  6180. global $USER;
  6181. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6182. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6183. $dir_base = $this->get_dir_ilm('dir_base');
  6184. $context = context_course::instance($this->id);
  6185. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6186. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6187. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6188. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6189. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6190. }
  6191. /// Function for delete an dir
  6192. function delete_dir_ilm () { //
  6193. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6194. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6195. $context = context_course::instance($this->id);
  6196. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6197. $dir_parent = $this->get_dir_ilm('dir_parent');
  6198. if ($dir) {
  6199. if ($dir->is_directory()) {
  6200. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6201. foreach ($files_delete as $value)
  6202. $value->delete();
  6203. $dir->delete();
  6204. }
  6205. }
  6206. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6207. die();
  6208. }
  6209. /// Function for rename an dir
  6210. function rename_dir_ilm () {
  6211. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6212. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6213. $context = context_course::instance($this->id);
  6214. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6215. $dir_parent = $this->get_dir_ilm('dir_parent');
  6216. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6217. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6218. if ($dir->is_directory()) {
  6219. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6220. foreach ($files_rename_path as $value)
  6221. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6222. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6223. }
  6224. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6225. die();
  6226. }
  6227. /// Function for move an dir and your content for other dir
  6228. function selected_move_ilm () {
  6229. global $PAGE, $OUTPUT, $CFG;
  6230. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6231. $context = context_course::instance($this->id);
  6232. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6233. $dirid = $this->get_dir_ilm('dirid');
  6234. $dir_base = $this->get_dir_ilm('dir_base');
  6235. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6236. $code_javascript_ilm = "
  6237. <script type='text/javascript'>
  6238. //<![CDATA[
  6239. function getRadiobutton () {
  6240. var radioButtons = document.getElementsByTagName('input');
  6241. var param = '';
  6242. for (var counter=0; counter < radioButtons.length; counter++) {
  6243. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6244. param = radioButtons[counter].value;
  6245. }
  6246. return param;
  6247. }
  6248. function move_selected_ilm () {
  6249. var msgAnswer;
  6250. if (getRadiobutton() != '') {
  6251. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6252. if (msgAnswer)
  6253. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6254. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6255. }
  6256. else
  6257. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6258. }
  6259. function cancel_selected_ilm () {
  6260. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6261. }
  6262. //]]>
  6263. </script>\n";
  6264. $title = get_string('move_files', 'iassign');
  6265. $PAGE->set_title($title);
  6266. $PAGE->set_pagelayout('base');
  6267. print $OUTPUT->header();
  6268. print $OUTPUT->heading($title);
  6269. $dir_paths = array();
  6270. print $OUTPUT->box_start();
  6271. print "<center>";
  6272. foreach ($files_id as $file_id) {
  6273. $file = $fs->get_file_by_id($file_id);
  6274. if ($file) {
  6275. if (!$file->is_directory())
  6276. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6277. else {
  6278. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6279. array_push($dir_paths, $file->get_filepath());
  6280. }
  6281. }
  6282. }
  6283. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6284. if ($dir_base != '/') {
  6285. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6286. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6287. }
  6288. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6289. foreach ($files_tree as $file) {
  6290. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6291. $is_parent = false;
  6292. foreach ($dir_paths as $dir) {
  6293. $path = explode("/", $dir);
  6294. array_pop($path);
  6295. $path[count($path) - 1] = '';
  6296. $path = implode("/", $path);
  6297. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6298. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6299. }
  6300. if ($is_parent == false) {
  6301. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6302. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6303. }
  6304. }
  6305. }
  6306. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6307. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6308. print "</center>";
  6309. print $OUTPUT->box_end();
  6310. print $OUTPUT->footer();
  6311. print $code_javascript_ilm;
  6312. die;
  6313. }
  6314. /// Function for move files for an dir
  6315. function move_files_ilm () {
  6316. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6317. $context = context_course::instance($this->id);
  6318. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6319. $dirid = $this->get_dir_ilm('dirid');
  6320. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6321. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6322. foreach ($files_id as $file_id) {
  6323. $file = $fs->get_file_by_id($file_id);
  6324. if ($file) {
  6325. if ($file->is_directory()) {
  6326. $pathname = explode("/", $file->get_filepath());
  6327. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6328. foreach ($files_move_path as $value) {
  6329. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6330. $value->rename($path_move, $value->get_filename());
  6331. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6332. }
  6333. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6334. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6335. $file->rename($path_move, $file->get_filename());
  6336. } else {
  6337. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6338. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6339. }
  6340. }
  6341. }
  6342. //die;
  6343. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6344. die();
  6345. } // function move_files_ilm()
  6346. /// Function for recover files in use on all activities of a course
  6347. function recover_files_ilm () {
  6348. global $DB, $USER;
  6349. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6350. $courseid = optional_param('id', NULL, PARAM_INT);
  6351. $dirid = $this->get_dir_ilm('dirid');
  6352. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6353. $contextfile = context_course::instance($this->id);
  6354. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6355. foreach ($iassigns as $iassign) {
  6356. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6357. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6358. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6359. $context = context_module::instance($cm->id);
  6360. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6361. if ($files) {
  6362. foreach ($files as $value) {
  6363. $extension = explode(".", $value->get_filename());
  6364. if (!$value->is_directory()) {
  6365. $fileinfo = array('contextid' => $contextfile->id,
  6366. 'component' => 'mod_iassign',
  6367. 'filearea' => 'activity',
  6368. 'itemid' => 0,
  6369. 'filepath' => $this->get_dir_ilm('dir_base'),
  6370. 'userid' => $USER->id,
  6371. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6372. 'license' => 'allrightsreserved',
  6373. 'timecreated' => time(),
  6374. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6375. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6376. }
  6377. }
  6378. } // if ($files)
  6379. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6380. } // foreach ($iassigns as $iassign)
  6381. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6382. die();
  6383. } // function recover_files_ilm()
  6384. /// Auxiliary function the get all files in a given context
  6385. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6386. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6387. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6388. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6389. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6390. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6391. // (NAO s_iassign_statement.file = s_files.id)
  6392. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6393. $dir_base = $this->get_dir_ilm('dir_base');
  6394. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6395. $countf = 0;
  6396. $array_files_id = array(); // all files from this context
  6397. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6398. //$filename = $item_fc->get_filename();
  6399. //$filepath = $item_fc->get_filepath();
  6400. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6401. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6402. // $array_files_aux[] = $item_fc;
  6403. $itemid = $item_fc->get_id();
  6404. if (!in_array($itemid, $array_files_id)) {
  6405. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6406. if ($fileuserid == $userid)
  6407. $filesfrommine[] = $item_fc;
  6408. else
  6409. $filesfromothers[] = $item_fc;
  6410. $array_files_id[] = $itemid;
  6411. $countf++;
  6412. }
  6413. }
  6414. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6415. return $countf;
  6416. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6417. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6418. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6419. function get_all_ilm_files_by_fileid ($fileid) {
  6420. global $DB, $USER;
  6421. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6422. //TODO Criar coluna 'authorid'
  6423. $str_query = "SELECT * FROM {iassign_statement} " .
  6424. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6425. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6426. return $array_iassign_ilm;
  6427. }
  6428. //NN
  6429. //NN
  6430. // Build string with JavaScript code with function to edit/remove/double iLM files
  6431. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6432. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6433. global $CFG;
  6434. $error_files_exists = get_string('error_file_exists', 'iassign');
  6435. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6436. $code_javascript_ilm = "
  6437. <script type='text/javascript'>
  6438. //<![CDATA[
  6439. function preview_ilm (fileid, ilmid) { //JavaScript function
  6440. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6441. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6442. }
  6443. function update_ilm (ilmid, fileid) { //JavaScript function
  6444. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6445. }
  6446. function delete_ilm (ilmid, fileid) { //JavaScript function
  6447. var msgAnswer;
  6448. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6449. if (msgAnswer) {
  6450. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6451. }
  6452. }
  6453. function delete_selected_ilm () { //JavaScript function
  6454. var msgAnswer;
  6455. var param = getCheckbox();
  6456. if (param.join() != '') {
  6457. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6458. if (msgAnswer)
  6459. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6460. }
  6461. else
  6462. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6463. }
  6464. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6465. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6466. }
  6467. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6468. var filenamecopy;
  6469. var i;
  6470. var files = new Array(" . $files_array . ");
  6471. do {
  6472. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6473. } while (filenamecopy == '');
  6474. if (filenamecopy == null)
  6475. return false;\n
  6476. else {
  6477. for (i=0;i<files.length;i++) {
  6478. if (files[i]==filenamecopy) {
  6479. alert('" . $error_files_exists . "');
  6480. return false;\n
  6481. }
  6482. }\n" .
  6483. // @see: function 'duplicate_file_ilm()' above
  6484. "
  6485. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6486. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6487. } // else
  6488. }
  6489. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6490. var filenamecopy;
  6491. var i;
  6492. var files = new Array($files_array);
  6493. do {
  6494. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6495. } while (filenamecopy == '');
  6496. if (filenamecopy == null)
  6497. return false;
  6498. else {
  6499. for (i=0;i<files.length;i++) {
  6500. if (files[i]==filenamecopy) {
  6501. alert('" . $error_files_exists . "');
  6502. return false;
  6503. }
  6504. }
  6505. 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;
  6506. }
  6507. }
  6508. function export_files_ilm () { //JavaScript function
  6509. var param = getCheckbox();
  6510. if (param.join() != '')
  6511. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6512. else
  6513. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6514. }
  6515. function select_all_ilm () { //JavaScript function
  6516. var checkBoxes = document.getElementsByTagName('input');
  6517. var selectAll = document.getElementById('select_all');
  6518. for (var counter=0; counter < checkBoxes.length; counter++) {
  6519. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6520. checkBoxes[counter].checked = selectAll.checked;
  6521. }
  6522. }
  6523. function getCheckbox () { //JavaScript function
  6524. var checkBoxes = document.getElementsByTagName('input');
  6525. var param = new Array();
  6526. for (var counter=0; counter < checkBoxes.length; counter++) {
  6527. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6528. param.push(checkBoxes[counter].value);
  6529. }
  6530. return param;
  6531. }
  6532. function new_dir_ilm () { //JavaScript function
  6533. var dirname = '';
  6534. var i;
  6535. var dirs = new Array(" . $dirs_array . ");
  6536. do {
  6537. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6538. } while (dirname == '');
  6539. if (dirname == null)
  6540. return false;\n
  6541. else {
  6542. for (i=0;i<dirs.length;i++) {
  6543. if (dirs[i]==dirname) {
  6544. alert('" . $error_dir_exists . "');
  6545. return false;\n
  6546. }
  6547. }
  6548. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6549. }
  6550. }
  6551. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6552. var msgAnswer;
  6553. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6554. if (msgAnswer) {
  6555. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6556. }
  6557. }
  6558. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6559. var dirnamecopy;
  6560. var i;
  6561. var dirs = new Array($dirs_array);
  6562. do {
  6563. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6564. } while (dirnamecopy == '');
  6565. if (dirnamecopy == null)
  6566. return false;\n
  6567. else {
  6568. for (i=0;i<dirs.length;i++) {
  6569. if (dirs[i]==dirnamecopy) {
  6570. alert('" . $error_dir_exists . "');
  6571. return false;\n
  6572. }
  6573. }
  6574. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6575. }
  6576. }
  6577. function move_selected_ilm (ilmid) { //JavaScript function
  6578. var param = getCheckbox();
  6579. if (param.join() != '')
  6580. 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();
  6581. else
  6582. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6583. }
  6584. function recover_files_ilm () { //JavaScript function
  6585. var msgAnswer;
  6586. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6587. if (msgAnswer) {
  6588. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6589. }
  6590. }
  6591. window.onload = function() { //JavaScript function
  6592. var xPosition = 0;
  6593. var yPosition = 0;
  6594. element=document.getElementById('new_file');
  6595. while(element) {
  6596. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6597. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6598. element = element.offsetParent;
  6599. }
  6600. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6601. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6602. location.hash = '#new_file';
  6603. };
  6604. //]]>
  6605. </script>\n"; // end of $code_javascript_ilm
  6606. return $code_javascript_ilm;
  6607. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6608. /// List iassign files from course directory
  6609. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6610. function view_files_ilm ($iassign_ilm_class, $extension) {
  6611. global $CFG, $DB, $USER, $OUTPUT;
  6612. $fs = get_file_storage();
  6613. $context = context_course::instance($this->id);
  6614. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6615. $dirid = $this->get_dir_ilm('dirid');
  6616. $dir_base = $this->get_dir_ilm('dir_base');
  6617. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6618. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6619. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6620. $files_array = '';
  6621. foreach ($files_course as $value) {
  6622. if (!$value->is_directory())
  6623. $files_array .= "'" . $value->get_filename() . "',";
  6624. }
  6625. $files_array .= "''";
  6626. $error_files_exists = get_string('error_file_exists', 'iassign');
  6627. $dirs_array = '';
  6628. foreach ($files_course as $value) {
  6629. if ($value->is_directory()) {
  6630. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6631. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6632. }
  6633. }
  6634. $dirs_array .= "''";
  6635. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6636. // TODO Rever o preview pois só deixar ver uma vez.
  6637. $code_javascript_ilm = "
  6638. <script type='text/javascript'>
  6639. //<![CDATA[
  6640. function preview_ilm (fileid, ilmid) {
  6641. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6642. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6643. }
  6644. function update_ilm (ilmid, fileid) {
  6645. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6646. }
  6647. function delete_ilm (ilmid, fileid) {
  6648. var msgAnswer;
  6649. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6650. if (msgAnswer) {
  6651. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6652. }
  6653. }
  6654. function delete_selected_ilm () {
  6655. var msgAnswer;
  6656. var param = getCheckbox();
  6657. if (param.join() != '') {
  6658. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6659. if (msgAnswer)
  6660. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6661. }
  6662. else
  6663. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6664. }
  6665. function add_ilm_iassign (ilmid, filename, fileid) {
  6666. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6667. }
  6668. function duplicate_ilm (ilmid, filename, fileid) {
  6669. var filenamecopy;
  6670. var i;
  6671. var files = new Array($files_array);
  6672. do {
  6673. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6674. } while (filenamecopy == '');
  6675. if (filenamecopy == null)
  6676. return false;\n
  6677. else {
  6678. for (i=0;i<files.length;i++) {
  6679. if (files[i]==filenamecopy) {
  6680. alert('$error_files_exists');
  6681. return false;\n
  6682. }
  6683. }\n" .
  6684. // @see: function 'duplicate_file_ilm()' above
  6685. "
  6686. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6687. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6688. } // else
  6689. }
  6690. function rename_ilm (ilmid, filename, fileid) {
  6691. var filenamecopy;
  6692. var i;
  6693. var files = new Array($files_array);
  6694. do {
  6695. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6696. } while (filenamecopy == '');
  6697. if (filenamecopy == null)
  6698. return false;
  6699. else {
  6700. for (i=0;i<files.length;i++) {
  6701. if (files[i]==filenamecopy) {
  6702. alert('$error_files_exists');
  6703. return false;
  6704. }
  6705. }
  6706. 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;
  6707. }
  6708. }
  6709. function export_files_ilm () {
  6710. var param = getCheckbox();
  6711. if (param.join() != '')
  6712. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6713. else
  6714. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6715. }
  6716. function select_all_ilm () {
  6717. var checkBoxes = document.getElementsByTagName('input');
  6718. var selectAll = document.getElementById('select_all');
  6719. for (var counter=0; counter < checkBoxes.length; counter++) {
  6720. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6721. checkBoxes[counter].checked = selectAll.checked;
  6722. }
  6723. }
  6724. function getCheckbox () {
  6725. var checkBoxes = document.getElementsByTagName('input');
  6726. var param = new Array();
  6727. for (var counter=0; counter < checkBoxes.length; counter++) {
  6728. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6729. param.push(checkBoxes[counter].value);
  6730. }
  6731. return param;
  6732. }
  6733. function new_dir_ilm () {
  6734. var dirname = '';
  6735. var i;
  6736. var dirs = new Array($dirs_array);
  6737. do {
  6738. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6739. } while (dirname == '');
  6740. if (dirname == null)
  6741. return false;\n
  6742. else {
  6743. for (i=0;i<dirs.length;i++) {
  6744. if (dirs[i]==dirname) {
  6745. alert('$error_dir_exists');
  6746. return false;\n
  6747. }
  6748. }
  6749. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6750. }
  6751. }
  6752. function delete_dir_ilm (ilmid, dirid) {
  6753. var msgAnswer;
  6754. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6755. if (msgAnswer) {
  6756. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6757. }
  6758. }
  6759. function rename_dir_ilm (ilmid, dirname, dirid) {
  6760. var dirnamecopy;
  6761. var i;
  6762. var dirs = new Array($dirs_array);
  6763. do {
  6764. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6765. } while (dirnamecopy == '');
  6766. if (dirnamecopy == null)
  6767. return false;\n
  6768. else {
  6769. for (i=0;i<dirs.length;i++) {
  6770. if (dirs[i]==dirnamecopy) {
  6771. alert('$error_dir_exists');
  6772. return false;\n
  6773. }
  6774. }
  6775. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6776. }
  6777. }
  6778. function move_selected_ilm (ilmid) {
  6779. var param = getCheckbox();
  6780. if (param.join() != '')
  6781. 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();
  6782. else
  6783. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6784. }
  6785. function recover_files_ilm () {
  6786. var msgAnswer;
  6787. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6788. if (msgAnswer) {
  6789. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6790. }
  6791. }
  6792. window.onload = function() {
  6793. var xPosition = 0;
  6794. var yPosition = 0;
  6795. element=document.getElementById('new_file');
  6796. while(element) {
  6797. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6798. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6799. element = element.offsetParent;
  6800. }
  6801. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6802. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6803. location.hash = '#new_file';
  6804. };
  6805. //]]>
  6806. </script>\n";
  6807. $output = "";
  6808. $select_all = "";
  6809. $count_files = 0;
  6810. $extensions_allow = array();
  6811. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6812. foreach ($iassign_ilm as $item_iassign_ilm)
  6813. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6814. foreach ($files_course as $value) {
  6815. $filename = $value->get_filename();
  6816. $filepath = $value->get_filepath();
  6817. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6818. $pathname = $pathname[count($pathname) - 1];
  6819. $fileid = $value->get_id();
  6820. $tmp = explode(".", $filename);
  6821. if (count($tmp)>1) // avoid error if the file has no extension
  6822. $filetype = $tmp[1];
  6823. else // probably error...
  6824. $filetype = '';
  6825. $author = $value->get_author();
  6826. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6827. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6828. $extensions = explode(",", $extension);
  6829. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6830. $count_files ++;
  6831. // buscar fileid nas tabelas do iassign
  6832. $list_filein_use = "";
  6833. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6834. if ($iassign_statement_activity_list) {
  6835. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6836. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6837. }
  6838. }
  6839. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6840. if (!$iassign_ilm) {
  6841. $iassign_ilm = new stdClass();
  6842. $iassign_ilm->id = $ilmid;
  6843. }
  6844. // Do not use $var inside "..." - problem with some "unusual" operational system
  6845. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6846. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6847. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6848. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6849. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6850. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6851. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6852. $check_select = "";
  6853. $link_rename = "";
  6854. $link_delete = "";
  6855. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6856. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6857. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6858. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6859. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6860. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6861. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6862. if ($value->get_userid() == $USER->id) {
  6863. if ($iassign_statement_activity_list) {
  6864. $check_select = "";
  6865. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6866. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6867. $link_rename = "";
  6868. } else {
  6869. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6870. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6871. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6872. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6873. }
  6874. }
  6875. if (!in_array($filetype, $extensions_allow)) {
  6876. $link_edit = "";
  6877. $link_add_ilm_iassign = "";
  6878. $link_add_ilm_tinymce = "";
  6879. $link_add_ilm_atto = "";
  6880. $link_filter = "";
  6881. }
  6882. if ($value->is_directory()) {
  6883. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6884. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6885. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6886. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6887. <td><center>$author</center></td>
  6888. <td><center>$timecreated</center></td>
  6889. <td><center>$timemodified</center></td></tr>\n";
  6890. }
  6891. else if ($this->from == 'iassign') {
  6892. $new_id = "";
  6893. $new_class = "";
  6894. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6895. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6896. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6897. }
  6898. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6899. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6900. <td><center>$author</center></td>
  6901. <td><center>$timecreated</center></td>
  6902. <td><center>$timemodified</center></td></tr>\n";
  6903. }
  6904. else if ($this->from == 'block') {
  6905. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6906. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6907. <td><center>$author</center></td>
  6908. <td><center>$timecreated</center></td>
  6909. <td><center>$timemodified</center></td></tr>\n";
  6910. }
  6911. else if ($this->from == 'tinymce') {
  6912. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6913. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6914. <td><center>$author</center></td>
  6915. <td><center>$timecreated</center></td>
  6916. <td><center>$timemodified</center></td></tr>\n";
  6917. }
  6918. else if ($this->from == 'atto') {
  6919. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6920. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6921. <td><center>$author</center></td>
  6922. <td><center>$timecreated</center></td>
  6923. <td><center>$timemodified</center></td></tr>\n";
  6924. }
  6925. }
  6926. }
  6927. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6928. $dir_base = "";
  6929. $header = "";
  6930. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6931. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6932. foreach ($basename as $value) {
  6933. $dir_base .= $value . "/";
  6934. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6935. if ($dir_id) {
  6936. if ($value == "") {
  6937. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6938. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6939. } else {
  6940. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6941. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6942. }
  6943. }
  6944. } // foreach ($basename as $value)
  6945. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6946. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6947. $html .= "
  6948. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6949. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6950. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6951. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6952. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6953. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6954. </table>\n";
  6955. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6956. $html .= "<table width='100%'><tr>\n";
  6957. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6958. if ($count_files != 0) {
  6959. $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";
  6960. $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";
  6961. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6962. }
  6963. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6964. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6965. $html .= "</form>\n";
  6966. print $code_javascript_ilm;
  6967. print $html;
  6968. } // function view_files_ilm($extension)
  6969. } // class ilm_manager
  6970. /// Class to insert of icons
  6971. class iassign_icons {
  6972. static function insert ($icon) {
  6973. global $CFG;
  6974. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6975. return $string;
  6976. }
  6977. }
  6978. /// Class with util functions for plugin manage
  6979. class iassign_utils {
  6980. /// Function to return the filename extension
  6981. // @param string The $filename as an string
  6982. // @return string Return an string (last group after '.')
  6983. static function filename_extension ($filename) {
  6984. if ($filename == null || $filename == '') {
  6985. return null;
  6986. }
  6987. $itens = explode('.', $filename);
  6988. $num = count($itens);
  6989. if ($num < 2) {
  6990. return null;
  6991. }
  6992. return $itens[$num - 1];
  6993. }
  6994. /// Use the PHP class/package ZipArchive to create a Zip file
  6995. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6996. // 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
  6997. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6998. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6999. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7000. $zip = new zip_archive(); //2
  7001. $res = $zip->open($full_path_zip_filename);
  7002. $total_vet = count($vet_student_filename);
  7003. for ($ii=0; $ii<$total_vet; $ii++) {
  7004. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7005. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7006. }
  7007. $ret = $zip->close();
  7008. iassign_utils::download_file($full_path_zip_filename);
  7009. $filenameZip = $zip->filename;
  7010. return array($ret, $zip);
  7011. }
  7012. static function download_file ($zip_filename) {
  7013. header("Pragma: public");
  7014. header("Expires: 0");
  7015. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7016. header("Cache-Control: private", false);
  7017. header("Content-Type: application/zip");
  7018. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7019. header("Content-Transfer-Encoding: binary");
  7020. header("Content-Length: " . @filesize($zip_filename));
  7021. set_time_limit(0);
  7022. @readfile("$zip_filename") || die("File not found.");
  7023. unlink($zip_filename);
  7024. }
  7025. /// Function for format filename remove special caracters
  7026. // @param string $text String for clean
  7027. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7028. // @return string Return an string in clean format
  7029. static function format_filename ($text) {
  7030. if ($text != '.') {
  7031. //D $text = htmlspecialchars(urldecode($text));
  7032. //D echo "locallib.php: format_filename: $text<br/>";
  7033. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7034. $text = json_decode($text)->{current_language()};
  7035. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7036. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7037. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7038. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7039. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7040. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7041. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7042. // E.g. text = "exerc_midpoint.course.geo"
  7043. // 0123456789012345678901234
  7044. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7045. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7046. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7047. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7048. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7049. //$ext = strrpos($text, ".");
  7050. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7051. //$text = str_replace($array1, $array2, $text);
  7052. }
  7053. return $text;
  7054. }
  7055. /// Function to filter characters to the file name to iLM content
  7056. // @param string $text String for clean
  7057. // @param string $ext String ot the extension of the iLM
  7058. // @return string Return an string in clean format
  7059. static function filter_filename_extension ($filename, $ext) {
  7060. if ($filename != '.') {
  7061. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7062. $arrTo = array("_","","","","","","","","","","","","");
  7063. $filename = str_replace($arrFrom, $arrTo, $filename);
  7064. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7065. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7066. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7067. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7068. $index_lastposition = strlen($filenameF);
  7069. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7070. $text = str_replace(".", "_", $text); // erase all other "."
  7071. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7072. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7073. }
  7074. else
  7075. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7076. return $filenameF;
  7077. }
  7078. /// Function for format pathname remove special caracters
  7079. // @param string $text String for clean
  7080. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7081. // @return string Return an string in clean format
  7082. static function format_pathname ($text, $is_lowercase = true) {
  7083. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7084. $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", "-", "_", "", "", "");
  7085. $text = str_replace($array1, $array2, $text);
  7086. if ($is_lowercase)
  7087. $text = strtolower($text);
  7088. return $text;
  7089. }
  7090. /// Function for format file name from iLM original name
  7091. // @param string $text String to build the file neam
  7092. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7093. // @return string Return an string in clean format
  7094. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7095. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7096. $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", "-", "_", "", "", "");
  7097. $index_firstposition_blank = strpos($ilm_name, " ");
  7098. if ($index_firstposition_blank) { // truncate the name!
  7099. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7100. }
  7101. $index_firstposition_dots = strpos($ilm_name, ":");
  7102. if ($index_firstposition_dots) { // truncate the name!
  7103. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7104. }
  7105. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7106. if ($is_lowercase)
  7107. $namefiltered = strtolower($namefiltered);
  7108. return $namefiltered;
  7109. }
  7110. /// Function for insert version in the filename
  7111. // @param string $filename Name of file
  7112. // @return string Return the filename with version
  7113. static function version_filename ($filename) {
  7114. $array_filename = explode('.', $filename);
  7115. if (count($array_filename) > 1)
  7116. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7117. else
  7118. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7119. return $filename;
  7120. }
  7121. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7122. static function remove_code_message ($string) {
  7123. $array = explode("&lt;ia_uc&gt;", $string);
  7124. return $array[0];
  7125. }
  7126. }
  7127. // class iassign_utils
  7128. /// Class with language functions for plugin manage
  7129. class iassign_language {
  7130. /// Function for return text in language or get default language (en)
  7131. // @param string $lang Code of language
  7132. // @param string $description JSON text content all languages
  7133. // @return string Return an string in the language selected
  7134. static function get_description_lang ($lang, $descriptions) {
  7135. $description_lang = "";
  7136. $description = json_decode($descriptions);
  7137. if ($description == null) {
  7138. $description_lang = $descriptions;
  7139. }
  7140. else {
  7141. if (isset($description->{$lang}))
  7142. $description_lang = $description->{$lang};
  7143. else
  7144. if (isset($description->en)) //MOOC2014
  7145. $description_lang = $description->en;
  7146. else //MOOC2014
  7147. $description_lang = "en"; //MOOC2014
  7148. }
  7149. return $description_lang;
  7150. }
  7151. /// Function for return all language supported by iLM
  7152. // @param string $descriptions JSON text content all languages
  7153. // @return string Return as string with all languages
  7154. static function get_all_lang ($descriptions) {
  7155. $langs = "";
  7156. $description = json_decode($descriptions);
  7157. if ($description) {
  7158. foreach ($description as $key => $value) {
  7159. $langs .= $key . " ; ";
  7160. }
  7161. $langs = substr($langs, 0, strlen($langs) - 3);
  7162. }
  7163. return $langs;
  7164. }
  7165. /// Function for convert json in xml //MOOC2014
  7166. // @param string $json JSON text
  7167. // @return string Return as string with xml tags
  7168. static function json_to_xml ($json) {
  7169. $xml = "";
  7170. $json = json_decode($json);
  7171. foreach ($json as $key => $value) {
  7172. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7173. }
  7174. return $xml;
  7175. }
  7176. }
  7177. // class iassign_language
  7178. /// Class with log functions for plugin manage.
  7179. class iassign_log {
  7180. /// Function for insert log event
  7181. // @param string $action Code action of event
  7182. // @param string $information Text for describe action of event
  7183. // @param int $cmid Id of context module
  7184. // @param int $ilmid Id of iLM
  7185. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7186. global $COURSE, $CFG, $USER, $DB;
  7187. $newentry = new stdClass();
  7188. $newentry->time = time();
  7189. $newentry->userid = $USER->id;
  7190. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7191. $newentry->course = $COURSE->id;
  7192. $newentry->cmid = $cmid;
  7193. $newentry->ilmid = $ilmid;
  7194. $newentry->action = $action;
  7195. $newentry->info = $information;
  7196. $newentry->language = current_language();
  7197. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7198. if (ini_get("browscap") && function_exists('get_browse')) {
  7199. $browser = get_browse(null, true);
  7200. $newentry->javascript = $browser['javascript'];
  7201. $newentry->java = $browser['javaapplets'];
  7202. }
  7203. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7204. print_error('error_add_log', 'iassign');
  7205. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7206. } // class iassign_log