locallib.php 385 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258
  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 = array('shortname' => 'student');
  354. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  355. $context = context_course::instance($this->course->id);
  356. $params = 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);
  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. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  390. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  391. $zip = new zip_archive(); // create ZIP
  392. $zip->open($zip_filename);
  393. foreach ($exercises_list as $exercise) {
  394. $dir_ex = iassign_utils::format_filename($exercise->name);
  395. $zip->add_directory($dir_ex);
  396. $extension_ilm = '';
  397. foreach ($ilm_list as $ilm) {
  398. if ($exercise->iassign_ilmid == $ilm->id) {
  399. $extension_ilm = $ilm->extension;
  400. break;
  401. }
  402. }
  403. foreach ($students_list as $student) {
  404. $individual_dir =
  405. $dir_ex . DIRECTORY_SEPARATOR .
  406. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  407. $zip->add_directory($individual_dir);
  408. $i = 1;
  409. foreach($list as $item) {
  410. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  411. $date = new DateTime();
  412. $date->setTimestamp($item->timecreated);
  413. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s') . '.' . $extension_ilm);
  414. $zip->add_file_from_string($new_file, $item->answer);
  415. $temp_json = [];
  416. $temp_json[] = intval($item->id);
  417. $temp_json[] = $new_file;
  418. $temp_json[] = strlen($new_file);
  419. $temp_json[] = intval($item->timecreated);
  420. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  421. $temp_json[] = doubleval($item->grade);
  422. $temp_json[] = intval($item->userid);
  423. $temp_json[] = intval($exercise->id);
  424. $json_obj->submissions[] = $temp_json;
  425. }
  426. }
  427. }
  428. }
  429. $csv_str = "";
  430. foreach($json_obj->submissions as $sub) {
  431. $csv_str .= $this->csvstr($sub) . "\n";
  432. }
  433. $zip->add_file_from_string('index.csv', $csv_str);
  434. $zip->close();
  435. iassign_utils::download_file($zip_filename);
  436. exit;
  437. }
  438. function csvstr(array $fields) : string {
  439. $f = fopen('php://memory', 'r+');
  440. if (fputcsv($f, $fields) === false) {
  441. return false;
  442. }
  443. rewind($f);
  444. $csv_line = stream_get_contents($f);
  445. return rtrim($csv_line);
  446. }
  447. /// Download submissions from table iassign_allsubmissions
  448. function download_submissions () {
  449. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  450. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  451. exit;
  452. $type = optional_param('type', NULL, PARAM_TEXT);
  453. $item = optional_param('item', NULL, PARAM_TEXT);
  454. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  455. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  456. $sub_list = [];
  457. if ($type == 'individual') {
  458. $sub_list[] = $DB->get_record(
  459. 'iassign_allsubmissions', array('id' => $item));
  460. } elseif ($type == 'student') {
  461. $sub_list = $DB->get_records(
  462. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  463. } elseif ($type == 'exercise') {
  464. $sub_list = $DB->get_records(
  465. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  466. } elseif ($type == 'block') {
  467. $exercises_in_block = $DB->get_records(
  468. 'iassign_statement', array('iassignid' => $iassign_id));
  469. foreach ($exercises_in_block as $exercise) {
  470. $temp = $DB->get_records(
  471. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  472. $sub_list = array_merge($sub_list, $temp);
  473. }
  474. }
  475. $this->download_submissions_help($sub_list);
  476. }
  477. /// Delete submissions in table iassign_allsubmissions
  478. function delete_submissions () {
  479. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  480. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  481. exit;
  482. $type = optional_param('type', NULL, PARAM_TEXT);
  483. $item = optional_param('item', NULL, PARAM_TEXT);
  484. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  485. if ($type == 'individual') {
  486. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  487. } elseif ($type == 'student') {
  488. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  489. } elseif ($type == 'exercise') {
  490. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  491. }
  492. }
  493. function get_individual_submission () {
  494. global $DB, $USER;
  495. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  496. exit;
  497. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  498. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  499. print $submission->answer;
  500. }
  501. /// Open individual submission
  502. function open_individual_submission () {
  503. global $DB, $USER, $CFG;
  504. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  505. exit;
  506. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  507. $id = $this->cm->id;
  508. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  509. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  510. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  511. //print_r($atual_submission);
  512. $all_submissions = $DB->get_records('iassign_allsubmissions',
  513. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  514. $previous = null;
  515. $next = null;
  516. $i = 0;
  517. $found = false;
  518. foreach($all_submissions as $individual) {
  519. if (!$found && $individual->id != $submissionid) {
  520. $previous = $individual;
  521. }
  522. if ($found) {
  523. $next = $individual;
  524. break;
  525. }
  526. if ($individual->id === $submissionid) {
  527. $found = true;
  528. }
  529. $i ++;
  530. }
  531. print '<center style="padding-top: 2rem;">';
  532. if ($previous) {
  533. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  534. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  535. } else {
  536. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  537. }
  538. print ' (' . $i . '/' . count($all_submissions) . ')';
  539. if ($next) {
  540. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  541. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  542. } else {
  543. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  544. }
  545. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  546. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "view", 'Proposition' => $url]);
  547. print '</center>';
  548. }
  549. /// Manage all submissions in exercises to table iassign_allsubmissions
  550. function all_submissions () {
  551. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  552. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  553. exit;
  554. print $OUTPUT->header();
  555. $id = $this->cm->id;
  556. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  557. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  558. print '
  559. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  560. <div class="modal-dialog modal-dialog-centered" role="document">
  561. <div class="modal-content">
  562. <div class="modal-header">
  563. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  564. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  565. <span aria-hidden="true">&times;</span>
  566. </button>
  567. </div>
  568. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  569. <div class="modal-footer">
  570. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  571. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  572. </div>
  573. </div>
  574. </div>
  575. </div>'; // "
  576. print '
  577. <script>
  578. var sub_type;
  579. var sub_item;
  580. var sub_el;
  581. var sub_exercise;
  582. function delete_submission (type, item, el, exercise = 0) {
  583. sub_type = type;
  584. sub_item = item;
  585. sub_exercise = exercise;
  586. sub_el = el.closest("tr");
  587. if (!sub_el) sub_el = el.closest("a");
  588. $("#modalConfirm").modal();
  589. }
  590. function confirm_delete () {
  591. var url = "'.$enderecoPOST.'&action=delete_submissions";
  592. var xhttp = new XMLHttpRequest();
  593. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  594. xhttp.send();
  595. $("#modalConfirm").modal("hide");
  596. if ($(sub_el).attr("href"))
  597. $($(sub_el).attr("href")).remove();
  598. if (sub_el) sub_el.remove();
  599. }
  600. function download_submission(type, item, exercise = 0, iassign = 0) {
  601. var url = "'.$enderecoPOST.'&action=download_submissions";
  602. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  603. document.location = url;
  604. }
  605. function open_submission(item) {
  606. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  607. var poupup = window.open(url, "popup", "width=900,height=900");
  608. }
  609. </script>' . chr(13); // '
  610. // Get list of exercises in the instance:
  611. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  612. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  613. print '<h2 class="m-b-2">' . get_string('all_submissions_manager', 'iassign') . '';
  614. 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>';
  615. // Get list of enrolled students:
  616. $params = array('shortname' => 'student');
  617. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  618. $context = context_course::instance($this->course->id);
  619. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  620. $students_list = $DB->get_records_sql(
  621. "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);
  622. print '<div>';
  623. foreach ($exercises_list as $exercise) {
  624. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  625. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  626. print '
  627. <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> '
  628. . $exercise->name
  629. . ' - ' . $iassign_ilm->name
  630. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  631. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  632. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  633. . $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> '
  634. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  635. . '</a>';
  636. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  637. foreach ($students_list as $student) {
  638. $total = 0;
  639. $student_submissions = [];
  640. foreach ($submissions_list as $submission) {
  641. if ($submission->userid == $student->userid) {
  642. $student_submissions[] = $submission;
  643. $total ++;
  644. }
  645. }
  646. 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");\'>
  647. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  648. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  649. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  650. . '<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> '
  651. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  652. . ' </a>';
  653. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  654. print '<table class="table table-striped table-hover"><thead>
  655. <tr>
  656. <th scope="col">#</th>
  657. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  658. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  659. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  660. </tr>
  661. </thead><tbody>'; // "
  662. $i = 1;
  663. foreach ($student_submissions as $individual) {
  664. $date = new DateTime();
  665. $date->setTimestamp($individual->timecreated);
  666. print '<tr>';
  667. print '<td>'.$i++.'</td>';
  668. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  669. print '<td>'.$individual->grade.'</td>';
  670. print '<td>
  671. <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>
  672. <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>
  673. <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>';
  674. print " </tr>\n";
  675. }
  676. print '</tbody></table>';
  677. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  678. print '</div>';
  679. }
  680. print '</div>';
  681. }
  682. print '</div>';
  683. print $OUTPUT->footer();
  684. } // function all_submissions()
  685. /// This method runs activities auto evaluation in teacher area
  686. function auto_evaluate () {
  687. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  688. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  689. exit;
  690. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  691. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  692. // Get list of exercises in the instance:
  693. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  694. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  695. // Get list of enrolled students:
  696. $params = array('shortname' => 'student');
  697. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  698. $context = context_course::instance($this->course->id);
  699. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  700. $students_list = $DB->get_records_sql(
  701. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  702. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  703. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  704. print $OUTPUT->header();
  705. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  706. print '<ul style="list-style-type: none; margin: 1em;">';
  707. foreach ($exercises_list as $exercise) {
  708. $matches = [];
  709. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  710. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  711. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  712. if ($matches[0][0]) {
  713. 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>';
  714. } else {
  715. 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>';
  716. }
  717. } else {
  718. if ($matches[0][0]) {
  719. 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>';
  720. } else {
  721. 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>';
  722. }
  723. }
  724. }
  725. print '</ul>
  726. <center>
  727. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  728. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  729. <div id="evaluate_message" style="color: red"></div>
  730. <div id="evaluate_alerts"></div>
  731. <div>
  732. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  733. <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>
  734. </div>
  735. </center>'; // close "
  736. print ' </div>' + "\n";
  737. print ' <script>';
  738. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  739. print ' var submissions = [';
  740. // Get list of student id have submit for each exercise:
  741. foreach ($exercises_list as $exercise) {
  742. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  743. print '
  744. {
  745. "exerciseid": "' . $exercise->id . '",
  746. "grade": ' . $exercise->grade . ',
  747. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  748. "submited": ['; // "
  749. $params = array('iassign_statementid' => $exercise->id);
  750. $submited = $DB->get_records_sql( // Get userid and his grade
  751. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  752. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  753. foreach ($submited as $ss) {
  754. print($ss->userid . ',');
  755. }
  756. print '],';
  757. print '"allgrades": [';
  758. foreach ($submited as $ss) {
  759. print( $ss->grade . ',');
  760. }
  761. print ']
  762. },'; // close "
  763. } // foreach ($exercises_list as $exercise)
  764. print " ];\n";
  765. print '
  766. var total_submissions = 0;
  767. var selected_exercises;
  768. var count_steps;
  769. var value_by_step;
  770. var stoped = false;
  771. var time_interval = 5000;
  772. var var_interval;
  773. function add_hover_th (id_th, id_li) { //AJAX
  774. $("#" + id_th).hover(function() {
  775. $("#" + id_li).css("background-color", "#d9d8d8");
  776. $(this).css("background-color", "#d9d8d8");
  777. }, function() {
  778. $("#" + id_li).css("background-color", "");
  779. $(this).css("background-color", "");
  780. });
  781. }
  782. function start_evaluation () {
  783. stoped = false;
  784. //AJAX
  785. $("#progress_bar").css("display", "none");
  786. $("#evaluate_message").text("");
  787. $("#evaluate_alerts").text("");
  788. $(".added-col").remove();
  789. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  790. selected_exercises = [];
  791. var c = 0;
  792. for (var i = 0; i < exercises.length; i++) {
  793. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  794. selected_exercises[c++] = exercises[i];
  795. }
  796. }
  797. if (selected_exercises.length == 0) {
  798. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  799. return;
  800. } else {
  801. $("input:checkbox").attr("disabled", true); //AJAX
  802. for (var i = 0; i < selected_exercises.length; i++) {
  803. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  804. //AJAX
  805. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  806. $("#table-results tbody tr").each(function(e) {
  807. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  808. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  809. });
  810. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  811. }
  812. //AJAX
  813. $("#button_start").prop("disabled", true);
  814. $("#button_stop").prop("disabled", false);
  815. $("#progress_bar").css("display", "block");
  816. }
  817. total_submissions = selected_exercises.length * students.length;
  818. count_steps = 0;
  819. value_by_step = 100/total_submissions;
  820. actual_exercise = 0;
  821. actual_student = 0;
  822. actual_submission = 0;
  823. get_original_propositions();
  824. var_interval = setInterval(verifyBreak, time_interval);
  825. } // function start_evaluation()
  826. var actual_exercise;
  827. var actual_student;
  828. var actual_submission;
  829. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  830. function run_individual_evaluation () {
  831. if (stoped) return;
  832. // Verify if student really sent his answer
  833. var found = false;
  834. for (var j = 0; j < submissions.length; j++) {
  835. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  836. for (var k = 0; k < submissions[j].submited.length; k++) {
  837. if (students[actual_student] == submissions[j].submited[k]) {
  838. found = true;
  839. break;
  840. }
  841. }
  842. break;
  843. }
  844. }
  845. if (found == false) {
  846. postResultAutoEval();
  847. } else {
  848. // If it was sent, search it...
  849. var final_url = "";
  850. 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];
  851. for (var j = 0; j < submissions.length; j++) {
  852. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  853. final_url = submissions[j].ilm;
  854. break;
  855. }
  856. }
  857. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  858. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  859. window.frames["ifrm"].location=final_url;
  860. }
  861. } // function run_individual_evaluation()
  862. var break_student = -1;
  863. var break_exercise = -1;
  864. function verifyBreak () {
  865. if (actual_student == break_student && actual_exercise == break_exercise) {
  866. postResultAutoEval(-6);
  867. break_student = -1;
  868. break_exercise = -1;
  869. return;
  870. } else {
  871. break_student = actual_student;
  872. break_exercise = actual_exercise;
  873. }
  874. }
  875. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  876. function getStudentAnswerURL () {
  877. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  878. }
  879. // This function is called by the iLM!!!
  880. function getAutoEvalOriginalData () {
  881. return original_propositions[actual_exercise];
  882. }
  883. function updateProgressBar () {
  884. if (stoped) return;
  885. var temp = (count_steps * value_by_step)|0;
  886. count_steps ++;
  887. temp = temp > 100 ? 100 : temp;
  888. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  889. if (temp >= 100) {
  890. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  891. $("#button_start").prop("disabled", false);
  892. $("#button_stop").prop("disabled", true);
  893. $("input:checkbox").attr("disabled", false);
  894. clearInterval(var_interval);
  895. }
  896. }
  897. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  898. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  899. function postResultAutoEval (grade = null) {
  900. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  901. if (grade == null) {
  902. $("#"+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>\');
  903. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  904. } else {
  905. // Verify if the re-evaluation grade is the of that one registered:
  906. var actual_value = 0;
  907. var actual_student_grade = 0;
  908. for (var k = 0; k < submissions.length; k++) {
  909. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  910. actual_value = submissions[k].grade;
  911. for (var h = 0; h < submissions[k].submited.length; h++) {
  912. if (submissions[k].submited[h] == students[actual_student]) {
  913. actual_student_grade = submissions[k].allgrades[h];
  914. break;
  915. }
  916. }
  917. break;
  918. }
  919. }
  920. // @FeedbackConvention
  921. if (grade < 0) {
  922. switch (grade) {
  923. case -1:
  924. // Test-cases are empty:
  925. $("#"+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>\');
  926. var mm = actual_exercise;
  927. $("#"+id_t).find(".details-button").click(function(e) {
  928. $(".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>\');
  929. });
  930. break;
  931. case -2:
  932. // Test-cases were manually altered by the student (fraud!):
  933. $("#"+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>\');
  934. var mm = actual_exercise;
  935. $("#"+id_t).find(".details-button").click(function(e) {
  936. $(".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>");
  937. });
  938. //AJAX
  939. $.ajax({
  940. dataType: "html",
  941. 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",
  942. success: function(d) {} });
  943. break;
  944. case -5:
  945. // Execution failed:
  946. $("#"+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>\');
  947. var mm = actual_exercise;
  948. //AJAX
  949. $("#"+id_t).find(".details-button").click(function(e) {
  950. $(".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>\');
  951. });
  952. break;
  953. case -6: // iLM not answering was detected in "verifyBreak()"
  954. // The iLM are not answering:
  955. //AJAX
  956. $("#"+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>\');
  957. $("#"+id_t).find(".details-button").click(function(e) {
  958. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  959. });
  960. break;
  961. }
  962. //AJAX
  963. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  964. } else {
  965. console.log((grade), (actual_student_grade));
  966. if ((grade) == (actual_student_grade)) {
  967. $("#"+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>\');
  968. } else { // Notas diferem:
  969. $("#"+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>\');
  970. var mm = actual_exercise;
  971. //AJAX
  972. $("#"+id_t).find(".details-button").click(function(e) {
  973. $(".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>\');
  974. });
  975. //AJAX
  976. // Send to the endpoint the post_auto_eval_result to verify:
  977. $.ajax({
  978. dataType: "html",
  979. 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),
  980. success: function(d) {}
  981. });
  982. }
  983. //AJAX
  984. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  985. }
  986. }
  987. updateProgressBar();
  988. // Does it must continue in the same exercise or stop?
  989. if (actual_student < students.length) {
  990. actual_student ++;
  991. run_individual_evaluation();
  992. } else {
  993. actual_student = 0;
  994. // Does it go to next exercise or is it finished?
  995. if (actual_exercise < selected_exercises.length) {
  996. actual_exercise++;
  997. run_individual_evaluation();
  998. } else {
  999. //AJAX
  1000. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1001. }
  1002. }
  1003. }
  1004. var original_propositions;
  1005. function get_original_propositions () {
  1006. original_propositions = [];
  1007. var count = 0;
  1008. for (var i = 0; i < exercises.length; i++) {
  1009. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1010. //AJAX
  1011. $.ajax({
  1012. dataType: "html",
  1013. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1014. success: function(d) { // variable "d" has the iLM content
  1015. original_propositions[count] = d; // exercise original content
  1016. count ++;
  1017. if (count == selected_exercises.length) {
  1018. run_individual_evaluation();
  1019. }
  1020. }
  1021. });
  1022. }
  1023. }
  1024. }
  1025. function stop_evaluation () {
  1026. stoped = true;
  1027. //AJAX
  1028. $("#button_start").prop("disabled", false);
  1029. $("#button_stop").prop("disabled", true);
  1030. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1031. $("input:checkbox").attr("disabled", false);
  1032. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1033. clearInterval(var_interval);
  1034. }
  1035. var exercises = [ '; // '
  1036. foreach ($exercises_list as $exercise) {
  1037. print $exercise->id . ',';
  1038. }
  1039. print ' ];';
  1040. print ' var students = [ ';
  1041. foreach ($students_list as $student) {
  1042. print $student->userid . ',';
  1043. }
  1044. print '];';
  1045. print ' var ilms = [';
  1046. foreach ($exercises_list as $exercise) {
  1047. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1048. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1049. }
  1050. print ']';
  1051. print '</script>';
  1052. print '
  1053. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1054. <div class="modal-dialog modal-dialog-centered" role="document">
  1055. <div class="modal-content">
  1056. <div class="modal-header">
  1057. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1058. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1059. <span aria-hidden="true">&times;</span>
  1060. </button>
  1061. </div>
  1062. <div class="modal-body">
  1063. ...
  1064. </div>
  1065. <div class="modal-footer">
  1066. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1067. </div>
  1068. </div>
  1069. </div>
  1070. </div>'; //
  1071. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1072. print '<table id="table-results" class="table table-hover m-t-1">
  1073. <thead>
  1074. <tr id="cols-exercises">
  1075. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1076. </tr>
  1077. </thead>
  1078. <tbody>'; // "
  1079. foreach ($students_list as $student) {
  1080. $user = $DB->get_record('user', array('id' => $student->userid));
  1081. $avatar = new user_picture($user);
  1082. $avatar->courseid = $COURSE->id;
  1083. $avatar->link = true;
  1084. print ' <tr data-student="' . $student->userid . '">
  1085. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1086. </tr>' . "\n";
  1087. }
  1088. print " </tbody>
  1089. </table>\n";
  1090. print $OUTPUT->footer();
  1091. } // function auto_evaluate()
  1092. /// This method moves an iAssign activity
  1093. function move_activity () {
  1094. global $USER, $CFG, $DB, $COURSE;
  1095. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1096. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1097. $update_entry_new_iassign = new stdClass();
  1098. $update_entry_new_iassign->id = $iassign_id;
  1099. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1100. // Update the iassign_statement
  1101. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1102. // Update file context
  1103. $c_i = context_module::instance($this->cm->id);
  1104. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1105. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1106. $path_module = context_course::instance($COURSE->id);
  1107. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1108. if ($context_file) {
  1109. $id_context = $context_file->id;
  1110. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1111. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1112. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1113. foreach ($files as $value) {
  1114. if ($value->get_filename() != ".") {
  1115. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1116. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1117. $updateentry = new stdClass();
  1118. $updateentry->id = $iassign_id;
  1119. $updateentry->filesid = $newfile->get_itemid();
  1120. $DB->update_record("iassign_statement", $updateentry);
  1121. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1122. break;
  1123. }
  1124. }
  1125. }
  1126. $this->return_home_course('moved_activity');
  1127. exit;
  1128. }
  1129. /// This method duplicates an iAssign activity
  1130. function duplicate_activity () {
  1131. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1132. $id = $this->cm->id;
  1133. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1134. $context = context_module::instance($this->cm->id);
  1135. $contextuser = context_user::instance($USER->id);
  1136. // Get the the iAssign acitivity to be duplicated
  1137. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1138. // Remove the current id of activity
  1139. $iassign_statement->id=0;
  1140. // Get the information about current author, and add this information in author_modified field
  1141. $author = $DB->get_record("user", array('id' => $USER->id));
  1142. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1143. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1144. // Store the activity in the table
  1145. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1146. // Duplicate activity file
  1147. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1148. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1149. foreach ($files as $value) {
  1150. if ($value->get_filename() != ".") {
  1151. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1152. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1153. $updateentry = new stdClass();
  1154. $updateentry->id = $id_;
  1155. $updateentry->filesid = $newfile->get_itemid();
  1156. // Update the duplicated iLM iAssign with new file id
  1157. $DB->update_record("iassign_statement", $updateentry);
  1158. }
  1159. }
  1160. }
  1161. // log event --------------------------------------------------------------------------------------
  1162. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1163. $this->return_home_course('duplicated_activity');
  1164. exit;
  1165. }
  1166. // / This method gets the content from comment and register it
  1167. function add_comment () {
  1168. global $USER, $DB;
  1169. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1170. $comment = false;
  1171. if ($submission_comment)
  1172. $comment = $this->write_comment_submission();
  1173. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1174. if (!$id_submission) {
  1175. $iassign_submission =
  1176. $DB->get_record("iassign_submission",
  1177. array(
  1178. "iassign_statementid" => $this->activity->get_activity()->id,
  1179. "userid" => $USER->id
  1180. )
  1181. );
  1182. if ($iassign_submission) {
  1183. $id_submission = $iassign_submission->id;
  1184. }
  1185. }
  1186. echo $this->search_comment_submission($id_submission);
  1187. }
  1188. /// This method gets the content from the iLM and register it
  1189. // It could be the "exercise template" (teacher) or an answer (student)
  1190. function get_answer () {
  1191. global $USER, $CFG, $DB, $OUTPUT;
  1192. $id = $this->cm->id;
  1193. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1194. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1195. if ($submission_ajax == 1) ob_start();
  1196. $comment = false;
  1197. if ($submission_comment)
  1198. $comment = $this->write_comment_submission();
  1199. // receives data of iLM using the current activity
  1200. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1201. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1202. // receives data of submission of current activity
  1203. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1204. // receives post and get
  1205. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1206. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1207. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1208. $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)
  1209. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1210. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1211. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1212. $msg = '';
  1213. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1214. $newentry = new stdClass();
  1215. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1216. $newentry->userid = $this->userid_iassign;
  1217. $newentry->timecreated = time();
  1218. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1219. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1220. $DB->insert_record("iassign_allsubmissions", $newentry);
  1221. }
  1222. // Feedback
  1223. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1224. $str_action = "view"; // repeat
  1225. if (strtolower($iassign_ilm->name) == "igeom") {
  1226. }
  1227. $title = get_string('evaluate_iassign', 'iassign');
  1228. print $OUTPUT->header();
  1229. print $OUTPUT->box_start();
  1230. // Action = { view ; repeat ; viewsubmission }
  1231. // * '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")
  1232. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1233. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1234. $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;
  1235. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1236. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1237. print '<table width=100% >';
  1238. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1239. //TODO alterar aqui???
  1240. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1241. // empty_answer_post = No solution was posted.
  1242. if ($comment)
  1243. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1244. else
  1245. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1246. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1247. } else {
  1248. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1249. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1250. // Correct answer!!
  1251. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1252. $this->write_solution = 1; //
  1253. $status = 3;
  1254. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1255. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1256. // log record
  1257. $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;
  1258. // Trigger module viewed event.
  1259. $event = \mod_iassign\event\submission_created::create(array(
  1260. 'objectid' => $this->iassign->id,
  1261. 'context' => $this->context,
  1262. 'other' => $info
  1263. ));
  1264. $event->add_record_snapshot('course', $this->course);
  1265. $event->trigger();
  1266. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1267. // Wrong answer...: get_answer_incorrect
  1268. $status = 2;
  1269. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1270. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1271. // log record
  1272. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1273. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1274. // Trigger module viewed event.
  1275. $event = \mod_iassign\event\submission_created::create(array(
  1276. 'objectid' => $this->iassign->id,
  1277. 'context' => $this->context,
  1278. 'other' => $info
  1279. ));
  1280. $event->add_record_snapshot('course', $this->course);
  1281. $event->trigger();
  1282. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1283. // Presents to the learner the result of the automatic evaluate?
  1284. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1285. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1286. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1287. print '<tr>';
  1288. // log record
  1289. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1290. // Trigger module viewed event.
  1291. $event = \mod_iassign\event\submission_created::create(array(
  1292. 'objectid' => $this->iassign->id,
  1293. 'context' => $this->context,
  1294. 'other' => $info
  1295. ));
  1296. $event->add_record_snapshot('course', $this->course);
  1297. $event->trigger();
  1298. } else { // yes!!!
  1299. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1300. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1301. print '<tr>';
  1302. print $msg;
  1303. }
  1304. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1305. $status = 1;
  1306. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1307. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1308. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1309. print '<tr>';
  1310. // log record
  1311. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1312. $event = \mod_iassign\event\submission_created::create(array(
  1313. 'objectid' => $this->iassign->id,
  1314. 'context' => $this->context,
  1315. 'other' => $info
  1316. ));
  1317. $event->add_record_snapshot('course', $this->course);
  1318. $event->trigger();
  1319. } // if ($iassign_ilm->evaluate == 1)
  1320. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1321. print '</tr></table>';
  1322. print $OUTPUT->box_end();
  1323. // add or update evaluate
  1324. if ($this->write_solution == 1) {
  1325. $timenow = time();
  1326. // new record
  1327. if (!$iassign_submission) {
  1328. $newentry = new stdClass();
  1329. $newentry->userid = $this->userid_iassign;
  1330. // $newentry->userid = $USER->id;
  1331. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1332. $newentry->timecreated = $timenow;
  1333. $newentry->timemodified = $timenow;
  1334. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1335. $newentry->grade = round($grade_student, 2);
  1336. $newentry->status = $status;
  1337. $newentry->experiment = 1;
  1338. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1339. print_error('error_insert', 'iassign');
  1340. } else {
  1341. // Trigger module viewed event.
  1342. $event = \mod_iassign\event\submission_created::create(array(
  1343. 'objectid' => $this->iassign->id,
  1344. 'context' => $this->context
  1345. ));
  1346. $event->add_record_snapshot('course', $this->course);
  1347. $event->trigger();
  1348. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1349. }
  1350. } elseif ($iassign_submission->status != 3) {
  1351. $newentry = new stdClass();
  1352. $newentry->id = $iassign_submission->id;
  1353. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1354. $newentry->userid = $iassign_submission->userid;
  1355. $newentry->timecreated = $iassign_submission->timecreated;
  1356. $newentry->timemodified = $timenow;
  1357. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1358. $newentry->grade = round($grade_student, 2);
  1359. $newentry->status = $status;
  1360. $newentry->experiment = $iassign_submission->experiment + 1;
  1361. if (!$DB->update_record("iassign_submission", $newentry)) {
  1362. print_error('error_update', 'iassign');
  1363. //D depurar...
  1364. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1365. //D $fp = fopen("teste1.txt","w");
  1366. //D fwrite($fp,$stringAux);
  1367. } else {
  1368. // Trigger module viewed event.
  1369. $event = \mod_iassign\event\submission_updated::create(array(
  1370. 'objectid' => $this->iassign->id,
  1371. 'context' => $this->context
  1372. ));
  1373. $event->add_record_snapshot('course', $this->course);
  1374. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1375. }
  1376. } else {
  1377. if ($return_get_answer == 1) {
  1378. $newentry = new stdClass();
  1379. $newentry->id = $iassign_submission->id;
  1380. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1381. $newentry->userid = $iassign_submission->userid;
  1382. $newentry->timecreated = $iassign_submission->timecreated;
  1383. $newentry->timemodified = $timenow;
  1384. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1385. $newentry->grade = round($grade_student, 2);
  1386. $newentry->status = $status;
  1387. $newentry->experiment = $iassign_submission->experiment + 1;
  1388. if (!$DB->update_record("iassign_submission", $newentry))
  1389. print_error('error_update', 'iassign');
  1390. else {
  1391. $event = \mod_iassign\event\submission_updated::create(array(
  1392. 'objectid' => $this->iassign->id,
  1393. 'context' => $this->context
  1394. ));
  1395. $event->add_record_snapshot('course', $this->course);
  1396. $event->trigger();
  1397. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1398. print $OUTPUT->box_start();
  1399. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1400. print $OUTPUT->box_end();
  1401. }
  1402. } elseif ($return_get_answer == 2) {
  1403. print $OUTPUT->box_start();
  1404. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1405. print $OUTPUT->box_end();
  1406. } else {
  1407. print $OUTPUT->box_start();
  1408. print "
  1409. <script type='text/javascript'>
  1410. //<![CDATA[
  1411. function overwrite () {
  1412. document.formEnvio.return_get_answer.value = 1;
  1413. document.formEnvio.submit();
  1414. }
  1415. function nooverwrite () {
  1416. document.formEnvio.return_get_answer.value = 2;
  1417. document.formEnvio.submit();
  1418. }
  1419. //]]>
  1420. </script>";
  1421. $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;
  1422. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1423. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1424. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1425. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1426. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1427. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1428. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1429. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1430. <input type='hidden' name='return_get_answer'/> ";
  1431. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1432. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1433. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1434. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1435. print " </form>";
  1436. print $OUTPUT->box_end();
  1437. }
  1438. }
  1439. } // if ($this->write_solution == 1)
  1440. print $OUTPUT->footer();
  1441. if ($submission_ajax == 1) {
  1442. ob_end_clean();
  1443. print 'OK';
  1444. }
  1445. die();
  1446. } // function get_answer()
  1447. /// Export in file the answer of student.
  1448. function export_file_answer () {
  1449. global $DB;
  1450. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1451. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1452. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1453. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1454. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1455. $extensions = explode(",", $iassign_ilm->extension);
  1456. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1457. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1458. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1459. header("Pragma: public");
  1460. header("Expires: 0");
  1461. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1462. header("Cache-Control: private", false);
  1463. header("Content-Type: document/unknown");
  1464. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1465. set_time_limit(0);
  1466. print($iassign_submission->answer);
  1467. exit;
  1468. } // function export_file_answer()
  1469. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1470. // @calledby $this->export_package_answer()
  1471. //TODO Precisa terminar! //TODO_HTML
  1472. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1473. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1474. <head>
  1475. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1476. $str_html .= " </head>
  1477. <body>\n";
  1478. $tam = sizeof($array_iassign_name);
  1479. for ($ii=0; $ii<$tam; $ii++) {
  1480. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1481. }
  1482. $str_html .= "
  1483. </body>\n</html>";
  1484. return $str_html;
  1485. }
  1486. /// Export an package (zip) with all answer of students
  1487. // @calledby $this->action()
  1488. function export_package_answer () {
  1489. global $DB, $CFG, $OUTPUT;
  1490. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1491. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1492. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1493. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1494. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1495. $userid = optional_param('userid', NULL, PARAM_INT);
  1496. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1497. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1498. //TODO_HTML echo "username=$username<br/>"; exit;
  1499. $current_date = date('Y_m_d_H');
  1500. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1501. // If temporary directory under Moodle data does not exists => create it
  1502. if (!is_dir($diretorio)) {
  1503. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1504. // created directory with permissions to be seen by everyone
  1505. }
  1506. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1507. if (!is_writable($diretorio)) { // send a highlighted message!
  1508. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1509. exit; // just in case
  1510. }
  1511. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1512. $zip = new zip_archive(); // create ZIP
  1513. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1514. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1515. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1516. $vet_student_filename = array();
  1517. $vet_student_content = array();
  1518. foreach ($iassign_statements as $iassign_statement) {
  1519. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1520. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1521. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1522. $extensions = explode(",", $iassign_ilm->extension);
  1523. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1524. if ($iassign_submission) {
  1525. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1526. $student_content = $iassign_submission->answer;
  1527. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1528. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1529. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1530. if ($resp) {
  1531. $vet_student_filename[] = $student_filename;
  1532. $vet_student_content[] = $student_content;
  1533. }
  1534. else { // send a highlighted message!
  1535. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1536. exit; // just in case
  1537. }
  1538. }
  1539. }
  1540. $zip->close(); // close the ZIP file
  1541. if (count($vet_student_filename)>0) {
  1542. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1543. $result_tf = $vet_result[0];
  1544. $filenameZip = $vet_result[1]->filename;
  1545. }
  1546. iassign_utils::download_file($zip_filename); // download the ZIP file
  1547. exit;
  1548. } // function export_package_answer()
  1549. /// Editing status of interactive activities
  1550. function edit_status () {
  1551. global $USER, $DB, $OUTPUT;
  1552. $newentry = new stdClass();
  1553. $newentry->id = $this->iassign_submission_current;
  1554. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1555. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1556. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1557. $newentry->status = $iassign_submission->status;
  1558. $newentry->teacher = $USER->id;
  1559. if (!$DB->update_record('iassign_submission', $newentry))
  1560. print_error('error_update', 'iassign');
  1561. else {
  1562. // Trigger module viewed event.
  1563. $event = \mod_iassign\event\submission_updated::create(array(
  1564. 'objectid' => $this->iassign->id,
  1565. 'context' => $this->context
  1566. ));
  1567. $event->add_record_snapshot('course', $this->course);
  1568. $event->trigger();
  1569. $this->action = 'viewsubmission';
  1570. $this->view_iassign_current();
  1571. } // if (!$DB->update_record('iassign_submission', $newentry))
  1572. } // function edit_status()
  1573. /// Editing grade of interactive activities
  1574. function edit_grade () {
  1575. global $USER, $DB, $OUTPUT;
  1576. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1577. if ($newgrade && $newgrade >= 0) {
  1578. $newentry = new stdClass();
  1579. $newentry->id = $this->iassign_submission_current;
  1580. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1581. $newentry->teacher = $USER->id;
  1582. if (!$DB->update_record('iassign_submission', $newentry))
  1583. print_error('error_update', 'iassign');
  1584. else {
  1585. // Trigger module viewed event.
  1586. $event = \mod_iassign\event\submission_updated::create(array(
  1587. 'objectid' => $this->iassign->id,
  1588. 'context' => $this->context
  1589. ));
  1590. $event->add_record_snapshot('course', $this->course);
  1591. $event->trigger();
  1592. }
  1593. } // if ($newgrade >= 0)
  1594. $this->action = 'viewsubmission';
  1595. $this->view_iassign_current();
  1596. }
  1597. /// Add or Edit interactive activities
  1598. // @calledby $this->action()
  1599. function add_edit_iassign () {
  1600. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1601. require_once('iassign_form.php');
  1602. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1603. $iassignid = $this->iassign->id;
  1604. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1605. $param->action = $this->action; // hidden
  1606. $param->id = $id; // hidden
  1607. $COURSE->cm = $id;
  1608. $COURSE->iassignid = $iassignid;
  1609. $COURSE->iassign_file_id = NULL;
  1610. // echo "<br/><br/><br/>locallib.php: add_edit_iassign(): id=$id, iassignid=$iassignid, action=" . $this->action . "<br/>\n";
  1611. // locallib.php: add_edit_iassign(): id=18612, iassignid=1355, action=edit
  1612. $context = context_module::instance($this->cm->id);
  1613. $contextuser = context_user::instance($USER->id);
  1614. $component = 'mod_iassign';
  1615. $filearea = 'exercise';
  1616. if (!empty($this->iassign_current))
  1617. $COURSE->iassign_id = $this->iassign_current;
  1618. else
  1619. $COURSE->iassign_id = 0;
  1620. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1621. if ($this->action == 'add') {
  1622. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1623. $params = array('iassignid' => $iassignid);
  1624. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1625. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1626. $total_of_activities = count($iassign_statement);
  1627. $param->iassignid = $iassignid;
  1628. $param->name = "";
  1629. $param->oldname = "";
  1630. $param->type_iassign = 3;
  1631. $param->proposition = "";
  1632. $author = $DB->get_record("user", array("id" => $USER->id));
  1633. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1634. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1635. $param->author = $param->author_name;
  1636. $param->author_modified = $param->author_modified_name;
  1637. $COURSE->iassign_list = array();
  1638. $param->iassign_list = array();
  1639. if ($iassign_statement) {
  1640. foreach ($iassign_statement as $iassign) {
  1641. $iassignid = $iassign->id;
  1642. $param->iassign_list[$iassignid] = 0;
  1643. $COURSE->iassign_list[$iassignid] = new stdClass();
  1644. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1645. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1646. $COURSE->iassign_list[$iassignid]->enable = 1;
  1647. } // foreach ($iassign_statement as $iassign)
  1648. }
  1649. $param->iassign_ilmid = 0;
  1650. $param->filesid = 0;
  1651. $param->fileold = 0;
  1652. $param->filename = "";
  1653. $param->grade = $iassign_data->grade;
  1654. $param->timemodified = time();
  1655. $param->timecreated = time();
  1656. $param->timeavailable = $iassign_data->timeavailable;
  1657. $param->timedue = $iassign_data->timedue;
  1658. $param->preventlate = $iassign_data->preventlate;
  1659. $param->test = $iassign_data->test;
  1660. $param->special_param1 = 0;
  1661. $param->visible = 1;
  1662. $param->max_experiment = $iassign_data->max_experiment;
  1663. $param->dependency = 0;
  1664. $param->automatic_evaluate = 1;
  1665. $param->show_answer = 1;
  1666. } // if ($this->action == 'add')
  1667. elseif ($this->action == 'edit') {
  1668. $COURSE->iassign_list = array();
  1669. $this_activity = $this->activity->get_activity();
  1670. if ($this_activity != null) {
  1671. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1672. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1673. $param->iassign_id = $iassign_statement_current->id; // oculto
  1674. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1675. $param->name = $iassign_statement_current->name;
  1676. $param->oldname = $iassign_statement_current->name;
  1677. $param->type_iassign = $iassign_statement_current->type_iassign;
  1678. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1679. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1680. //2019 $param->proposition = $iassign_statement_current->proposition;
  1681. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1682. $param->author_name = $iassign_statement_current->author_name; // oculto
  1683. $param->author = $iassign_statement_current->author_name;
  1684. $author = $DB->get_record("user", array('id' => $USER->id));
  1685. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1686. $param->author_modified = $param->author_modified_name;
  1687. $dependency = explode(';', $iassign_statement_current->dependency);
  1688. $param->iassign_list = array();
  1689. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1690. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1691. $array_dependency = array();
  1692. $subdependency = "";
  1693. $sub_subdependency = "";
  1694. // Dependents on this exercise
  1695. if ($iassign_statement_dependency) {
  1696. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1697. // to whom this exercise depends
  1698. foreach ($inter as $tmp)
  1699. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1700. $list_dependency = $subdependency . $sub_subdependency;
  1701. $array_dependency = explode(";", $list_dependency);
  1702. }
  1703. // Get all activities in the same iAssigment block:
  1704. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  1705. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1706. //echo "<br/><br/><br/>1. all_others_iassign_statement="; print_r($all_others_iassign_statement); echo "<br/>";
  1707. // [5426] => stdClass Object ( [id] => 5426 [name] => 1. iHanói: com 3 discos )
  1708. // [5428] => stdClass Object ( [id] => 5428 [name] => 1. iFrações: trator 1, fase 1 )
  1709. // [5427] => stdClass Object ( [id] => 5427 [name] => 1. iFrações: trator 1, fase 2 )
  1710. // [5429] => stdClass Object ( [id] => 5429 [name] => 1. iVProg. Ler e imprimir inteiro. ) )
  1711. $total_of_activities = count($all_others_iassign_statement) + 1;
  1712. $inter = array();
  1713. if ($all_others_iassign_statement) {
  1714. foreach ($all_others_iassign_statement as $iassign)
  1715. if (in_array($iassign->id, $dependency))
  1716. $inter[] = $iassign->id;
  1717. }
  1718. if ($all_others_iassign_statement) {
  1719. foreach ($all_others_iassign_statement as $iassign) {
  1720. $iassignid = $iassign->id;
  1721. $COURSE->iassign_list[$iassignid] = new stdClass();
  1722. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1723. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1724. if (in_array($iassignid, $dependency))
  1725. $param->iassign_list[$iassignid] = 1;
  1726. else
  1727. $param->iassign_list[$iassignid] = 0;
  1728. if (in_array($iassignid, $array_dependency))
  1729. $COURSE->iassign_list[$iassignid]->enable = 0;
  1730. else
  1731. $COURSE->iassign_list[$iassignid]->enable = 1;
  1732. } // foreach ($all_others_iassign_statement as $iassign)
  1733. }
  1734. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  1735. $param->fileold = 0;
  1736. $param->filesid = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1737. $param->filename = '';
  1738. $param->grade = $iassign_statement_current->grade;
  1739. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1740. $param->timeavailable = $iassign_statement_current->timeavailable;
  1741. $param->timedue = $iassign_statement_current->timedue;
  1742. $param->preventlate = $iassign_statement_current->preventlate;
  1743. $param->test = $iassign_statement_current->test;
  1744. $param->special_param1 = $iassign_statement_current->special_param1;
  1745. $param->position = $iassign_statement_current->position; // oculto
  1746. $param->visible = $iassign_statement_current->visible;
  1747. $param->max_experiment = $iassign_statement_current->max_experiment;
  1748. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1749. $param->show_answer = $iassign_statement_current->show_answer;
  1750. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1751. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  1752. if ($files) {
  1753. foreach ($files as $file) {
  1754. if ($file->get_filename() != '.') {
  1755. $param->filename = $file->get_filename();
  1756. $param->filesid = $file->get_id();
  1757. $param->fileold = $file->get_id();
  1758. $COURSE->iassign_file_id = $file->get_id();
  1759. }
  1760. }
  1761. }
  1762. //TODO //MOOC2014 -- inicio
  1763. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1764. //D if ($iassign_ilm_configs) {
  1765. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1766. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1767. //D } //MOOC2014 -- fim
  1768. } // if ($this_activity != null)
  1769. } // elseif ($this->action == 'edit')
  1770. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1771. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1772. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1773. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1774. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1775. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1776. $param->position = $total_of_activities;
  1777. // Create form and associate its data
  1778. // $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  1779. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1780. $mform->set_data($param);
  1781. if ($mform->is_cancelled()) {
  1782. $this->return_home_course('iassign_cancel');
  1783. exit;
  1784. }
  1785. else { // else if ($mform->is_cancelled())
  1786. $result = $mform->get_data();
  1787. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1788. if ($result) {
  1789. $result->context = $context;
  1790. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1791. $result->grade = 0;
  1792. if ($result->type_iassign == 1) {
  1793. $result->automatic_evaluate = 0;
  1794. $result->show_answer = 0;
  1795. }
  1796. elseif ($result->automatic_evaluate == 0)
  1797. $result->show_answer = 0;
  1798. // $_POST['iassign_list']
  1799. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1800. if ($result->iassign_list) {
  1801. foreach ($result->iassign_list as $key => $value)
  1802. $result->dependency .= $key . ';';
  1803. }
  1804. else
  1805. $result->dependency = 0;
  1806. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1807. //TODO Then get it directly from the form data $_POST!
  1808. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1809. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1810. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1811. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1812. if ($this->action == 'add') {
  1813. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1814. if ($iassign_statement_name) {
  1815. $this->return_home_course('error_iassign_name');
  1816. die();
  1817. }
  1818. // Really insert the new iActivity in table '*_iassign_statement'
  1819. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1820. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1821. // Trigger module viewed event.
  1822. $event = \mod_iassign\event\iassign_created::create(array(
  1823. 'objectid' => $iassignid,
  1824. 'context' => $context
  1825. ));
  1826. $event->add_record_snapshot('course', $this->course);
  1827. $event->trigger();
  1828. $this->return_home_course('iassign_add');
  1829. } // if ($this->action == 'add')
  1830. elseif ($this->action == 'edit') {
  1831. $iassignid = $this->activity->update_iassign($result);
  1832. $this->activity->update_calendar($iassignid, $result->oldname);
  1833. // Trigger module viewed event.
  1834. $event = \mod_iassign\event\iassign_updated::create(array(
  1835. 'objectid' => $iassignid,
  1836. 'context' => $context
  1837. ));
  1838. $event->add_record_snapshot('course', $this->course);
  1839. $event->trigger();
  1840. $this->return_home_course('iassign_update');
  1841. } // elseif ($this->action == 'edit')
  1842. die();
  1843. } // if ($result)
  1844. } // else if ($mform->is_cancelled())
  1845. print $OUTPUT->header();
  1846. $mform->display();
  1847. print $OUTPUT->footer();
  1848. die();
  1849. } // function add_edit_iassign()
  1850. /// Search for dependencies
  1851. function search_dependency ($search_iassing_id, $iassign_statement) {
  1852. global $DB, $OUTPUT;
  1853. $dependency = "";
  1854. if ($iassign_statement)
  1855. foreach ($iassign_statement as $iassign) {
  1856. $inter_dependency = explode(';', $iassign->dependency);
  1857. if (in_array($search_iassing_id, $inter_dependency)) {
  1858. $dependency .= $iassign->id . ";";
  1859. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1860. } // if (in_array($search_iassing_id, $inter_dependency))
  1861. } // foreach ($iassign_statement as $iassign)
  1862. return $dependency;
  1863. }
  1864. /// Search for "sub"dependency
  1865. function search_sub_dependency ($search_iassing_id) {
  1866. global $DB, $OUTPUT;
  1867. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1868. $dependency = "";
  1869. if ($iassign_statement) {
  1870. $inter_dependency = explode(';', $iassign_statement->dependency);
  1871. foreach ($inter_dependency as $tmp) {
  1872. if ($tmp != 0)
  1873. $dependency .= $tmp . ";";
  1874. $dependency .= $this->search_sub_dependency($tmp);
  1875. } // foreach ($inter_dependency as $tmp)
  1876. } // if ($iassign_statement)
  1877. return $dependency;
  1878. }
  1879. // Warning message
  1880. static function warning_message_iassign ($strcode) {
  1881. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1882. }
  1883. /// Update grade of iAssign
  1884. // Called always any iAssign activity is created
  1885. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1886. static function update_grade_iassign ($iassignid) {
  1887. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1888. require_once($CFG->libdir . '/gradelib.php');
  1889. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1890. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1891. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1892. // Each iAssign item is associated with one item on the "gradebook"
  1893. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1894. //$sum_grade = 0;
  1895. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1896. //foreach($grade as $tmp) {
  1897. // $sum_grade += $tmp->grade;
  1898. // }
  1899. //1 Solution 1
  1900. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1901. //1 $sum_grade = 0; //1
  1902. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1903. //2 Solution 2
  1904. $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
  1905. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1906. if (key($array_sum_grade))
  1907. $sum_grade = key($array_sum_grade); //2
  1908. else
  1909. $sum_grade = 0; //2
  1910. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1911. $grades = NULL;
  1912. $params = array('itemname' => $grade_iassign->name);
  1913. $params['iteminstance'] = $iassignid;
  1914. $params['gradetype'] = GRADE_TYPE_VALUE;
  1915. //2016 if ($sum_grade != 0) {
  1916. $params['grademax'] = $sum_grade;
  1917. $params['rawgrademax'] = $sum_grade;
  1918. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1919. $params['grademin'] = 0;
  1920. // @calls /lib/gradelib.php: call to grade_item->insert()
  1921. //TODO: is there any error here in Moodle version 3.0?
  1922. //TODO: Incorrect property 'grademax' found when inserting grade object
  1923. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1924. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1925. }
  1926. /// Update grade of student
  1927. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1928. global $CFG, $DB, $OUTPUT;
  1929. require_once($CFG->libdir . '/gradelib.php');
  1930. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1931. // Review all the student submission for this iAssign activity
  1932. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1933. $total_grade = 0;
  1934. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1935. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1936. if ($iassign_submission)
  1937. $total_grade += $iassign_submission->grade;
  1938. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1939. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1940. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1941. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1942. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1943. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1944. $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
  1945. if (key($array_sum_grade))
  1946. $sum_grade = key($array_sum_grade); //2
  1947. else
  1948. $sum_grade = 0; //2
  1949. $grades['userid'] = $userid;
  1950. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1951. $params = array('itemname' => $grade_iassign->name);
  1952. $params['iteminstance'] = $iassignid;
  1953. $params['gradetype'] = GRADE_TYPE_VALUE;
  1954. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1955. $params['grademax'] = $sum_grade;
  1956. $params['rawgrademax'] = $sum_grade;
  1957. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1958. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1959. }
  1960. /// Display caption of icons
  1961. function view_legend_icons () {
  1962. global $USER, $CFG, $DB, $OUTPUT;
  1963. $id = $this->cm->id;
  1964. if ($this->action == 'print')
  1965. print '<table border=1 width=100%><tr>';
  1966. else
  1967. print '<table width=100%><tr>';
  1968. print '<td >';
  1969. if ($this->action != 'print')
  1970. print $OUTPUT->help_icon('legend', 'iassign');
  1971. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1972. // $imagetext = '');
  1973. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1974. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1975. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1976. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1977. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1978. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1979. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1980. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1981. print '</td>' . "\n";
  1982. if ($this->action != 'print') {
  1983. $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>";
  1984. $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>";
  1985. $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>";
  1986. $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>";
  1987. $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>";
  1988. print '<td width=10% align="right">' . $link_stats . '</td>' . "\n";
  1989. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  1990. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1991. print '<td width=16% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  1992. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1993. } // if ($this->action != 'print')
  1994. print '</tr></table>' . "\n";
  1995. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1996. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1997. $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>";
  1998. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1999. print '</tr></table>' . "\n";
  2000. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2001. else
  2002. print '</td></tr></table>' . "\n";
  2003. } // function view_legend_icons()
  2004. /// Display activity current
  2005. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2006. function view_iassign_current () {
  2007. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2008. $id = $this->cm->id;
  2009. $iassignid = $this->iassign->id;
  2010. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2011. $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
  2012. // 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 ...
  2013. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2014. if (!$iassign_statement_activity_item) {
  2015. print $OUTPUT->header();
  2016. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2017. print $OUTPUT->footer();
  2018. exit;
  2019. }
  2020. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2021. $ilm_name = '';
  2022. if ($ilm->ilm)
  2023. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2024. // 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
  2025. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2026. // log record
  2027. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2028. //Trigger module viewed event.
  2029. $event = \mod_iassign\event\submission_viewed::create(array(
  2030. 'objectid' => $iassign->id,
  2031. 'context' => $this->context,
  2032. 'other' => $info
  2033. ));
  2034. $event->add_record_snapshot('course', $this->course);
  2035. $event->trigger();
  2036. // Search of iLM data used in the current activity
  2037. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2038. // Add actual activity to navbar:
  2039. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2040. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2041. print $OUTPUT->header();
  2042. if ($this->action == 'viewsubmission') {
  2043. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2044. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2045. else
  2046. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2047. } else {
  2048. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2049. }
  2050. if ($iassign_submission)
  2051. $this->update_comment($iassign_submission->id);
  2052. $file = $iassign_statement_activity_item->filesid;
  2053. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2054. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2055. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2056. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2057. $this->bottonPost = 0; // hide submit button
  2058. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2059. $this->view_iassign = false; // disable visualization of activity
  2060. $repeat = "";
  2061. $last_iassign = "";
  2062. $student_answer = "";
  2063. $comment = "";
  2064. // *** Teacher access (view learner's submission)
  2065. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2066. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2067. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2068. // ---> access teacher for test
  2069. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2070. $this->bottonPost = 1;
  2071. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2072. $this->activity->view_dates();
  2073. $USER->iassignEdit = $this->bottonPost;
  2074. $this->activity->show_info_iassign();
  2075. if ($iassign_submission) {
  2076. //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;
  2077. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2078. } else {
  2079. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2080. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2081. }
  2082. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2083. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2084. // Prepare tags to present the iLM
  2085. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2086. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2087. // *** (end) Teacher access (view the activity)
  2088. // *** Teacher access (view learner's submission to the activity)
  2089. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2090. // It is teacher or 'nonediting teacher' that can evaluate
  2091. // ----> area teacher evaluate
  2092. $row = optional_param('row', 0, PARAM_INT);
  2093. $column = optional_param('column', 0, PARAM_INT);
  2094. $link_next = iassign_icons::insert('right_disable');
  2095. $link_previous = iassign_icons::insert('left_disable');
  2096. $link_up = iassign_icons::insert('up_disable');
  2097. $link_down = iassign_icons::insert('down_disable');
  2098. // next_activity
  2099. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2100. $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);
  2101. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2102. }
  2103. // previous_activity
  2104. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2105. $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);
  2106. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2107. }
  2108. // previous_student
  2109. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2110. $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);
  2111. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2112. }
  2113. // next_student
  2114. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2115. $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);
  2116. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2117. }
  2118. if ($iassign_submission) {
  2119. $student_answer = $iassign_submission->answer;
  2120. }
  2121. $last_iassign = get_string('last_iassign', 'iassign');
  2122. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2123. // Messages related to due date (and user role)
  2124. $this->activity->view_dates();
  2125. print $OUTPUT->box_start();
  2126. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2127. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2128. print $OUTPUT->user_picture($user_data);
  2129. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2130. print '</td>' . "\n";
  2131. print '<td width=20% align=right>' . "\n";
  2132. print '<table width=50 cellpadding="0">';
  2133. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2134. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2135. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2136. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2137. print '</table>' . "\n";
  2138. print '</td></tr></table>' . "\n";
  2139. print $OUTPUT->box_end();
  2140. print $OUTPUT->box_start();
  2141. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2142. print '<td width=60% valign="top">' . "\n";
  2143. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2144. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2145. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2146. $resp = get_string('yes');
  2147. else
  2148. $resp = get_string('no');
  2149. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2150. if ($iassign_statement_activity_item->show_answer == 1)
  2151. $resp = get_string('yes');
  2152. else
  2153. $resp = get_string('no');
  2154. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2155. print '</td>';
  2156. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2157. print '<td width=40% valign="top" align="left">';
  2158. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2159. // check status of solution sent by the student
  2160. if ($iassign_submission) {
  2161. switch ($iassign_submission->status) {
  2162. case 3 :
  2163. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2164. break;
  2165. case 2 :
  2166. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2167. break;
  2168. case 1 :
  2169. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2170. break;
  2171. default :
  2172. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2173. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2174. } // switch ($iassign_submission->status)
  2175. }
  2176. else { // if ($iassign_submission)
  2177. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2178. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2179. }
  2180. // update_status
  2181. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2182. $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);
  2183. print " <script type='text/javascript'>
  2184. //<![CDATA[
  2185. function overwriteStatus (newstatus) {
  2186. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2187. document.formEditStatus.return_status.value=newstatus;
  2188. document.formEditStatus.submit();
  2189. }
  2190. else
  2191. document.formEditStatus.return_status.value=-1;
  2192. }
  2193. //]]>
  2194. </script>";
  2195. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2196. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2197. 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";
  2198. print " <input type='hidden' name='return_status'>\n";
  2199. print "</form>\n";
  2200. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2201. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2202. $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);
  2203. print "
  2204. <script type='text/javascript'>
  2205. //<![CDATA[
  2206. function overwriteGrade (newgrade,maxgrade) {
  2207. if (newgrade<0 || newgrade>maxgrade) {
  2208. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2209. document.formEditGrade.return_grade.value=-1;
  2210. document.formEditGrade.submit();
  2211. }
  2212. else {
  2213. document.formEditGrade.return_grade.value=newgrade;
  2214. document.formEditGrade.submit();
  2215. }
  2216. }
  2217. //]]>
  2218. </script>";
  2219. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2220. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2221. print " <input type='text' name='grade' size='6'>";
  2222. print " <input type='hidden' name='return_grade'> ";
  2223. 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";
  2224. print "</form>";
  2225. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2226. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2227. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2228. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2229. if ($teacher)
  2230. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2231. } // if ($iassign_submission->experiment > 0)
  2232. print '</td>';
  2233. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2234. print '</tr></table>';
  2235. print $OUTPUT->box_end();
  2236. $USER->iassignEdit = $this->bottonPost;
  2237. if ($iassign_submission && $allow_resubmission) {
  2238. // Put the iLM to
  2239. print $OUTPUT->box_start();
  2240. print '<p><strong>' . $last_iassign . '</strong></p>';
  2241. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2242. $enderecoPOST = "";
  2243. // Prepare tags to present the iLM
  2244. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2245. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2246. print $OUTPUT->box_end();
  2247. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2248. // ATTENTION: exception used by iGeom (exercise with "script")
  2249. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2250. if (substr($ilm_name, 0, 5)=="igeom") {
  2251. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2252. $loadTeacherActivity = true;
  2253. }
  2254. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2255. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2256. // Prepare tags to present the iLM
  2257. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2258. }
  2259. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2260. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2261. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2262. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2263. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2264. // *** (end) Teacher access (view learner's submission to the activity)
  2265. // *** Student access (view the activity)
  2266. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2267. // It could be the learner (he could send or resend the activity)
  2268. // ---> access student
  2269. $time_now = time();
  2270. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2271. // activity of type example - not submit button for submission
  2272. $this->view_iassign = true;
  2273. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2274. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2275. // activity of type test - iLM automatic evaluator - submit button for submission
  2276. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2277. $this->bottonPost = 1;
  2278. $this->view_iassign = true;
  2279. } else
  2280. $this->view_iassign = false;
  2281. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2282. // activity of type exercise (learner can send his answer, if yet open...)
  2283. $this->view_iassign = true;
  2284. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2285. $this->view_iassign = false;
  2286. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2287. $this->bottonPost = 1; // allow the submit button
  2288. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2289. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2290. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2291. if (!$iassign_submission) {
  2292. $str_iassign_submission_id = '';
  2293. $str_iassign_submission_answer = '';
  2294. }
  2295. else {
  2296. $str_iassign_submission_id = $iassign_submission->id;
  2297. $str_iassign_submission_answer = $iassign_submission->answer;
  2298. }
  2299. if ($this->action != 'repeat') {
  2300. $repeat = "<a href='view.php?action=repeat&id="
  2301. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2302. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2303. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2304. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2305. }
  2306. $this->bottonPost = 1;
  2307. $this->write_solution = 1; // can register his submission
  2308. $student_answer = $str_iassign_submission_answer;
  2309. }
  2310. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2311. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2312. $last_iassign = get_string('last_iassign', 'iassign');
  2313. if ($iassign_submission) {
  2314. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2315. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2316. $student_answer = $iassign_submission->answer;
  2317. } else {
  2318. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2319. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2320. }
  2321. }
  2322. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2323. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2324. $this->bottonPost = 1;
  2325. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2326. } else {
  2327. $last_iassign = get_string('last_iassign', 'iassign');
  2328. if ($iassign_submission) {
  2329. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2330. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2331. $student_answer = $iassign_submission->answer;
  2332. } else {
  2333. // Symbol of "redo activity"
  2334. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2335. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2336. }
  2337. }
  2338. } // elseif ($iassign_statement_activity_item->test == 1)
  2339. elseif ($iassign_statement_activity_item->test == 0)
  2340. $this->view_iassign = false;
  2341. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2342. if ($iassign_submission)
  2343. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2344. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2345. else
  2346. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2347. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2348. $this->activity->view_dates();
  2349. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2350. print $OUTPUT->box_start();
  2351. print '<table width=100% border=0 valign="top">' . "\n";
  2352. print '<tr><td width=60% valign="top">' . "\n";
  2353. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2354. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2355. $flag_dependency = true;
  2356. if ($iassign_statement_activity_item->type_iassign == 3) {
  2357. if ($iassign_statement_activity_item->dependency == 0) {
  2358. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2359. } else {
  2360. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2361. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2362. foreach ($dependencys as $dependency) {
  2363. if ($dependency) {
  2364. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2365. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2366. if ($dependencysubmissions) {
  2367. if ($dependencysubmissions->status == 3)
  2368. $icon = iassign_icons::insert('correct');
  2369. elseif ($dependencysubmissions->status == 2) {
  2370. $icon = iassign_icons::insert('incorrect');
  2371. $flag_dependency = false;
  2372. } elseif ($dependencysubmissions->status == 1) {
  2373. $icon = iassign_icons::insert('post');
  2374. $flag_dependency = false;
  2375. } elseif ($dependencysubmissions->status == 0) {
  2376. $icon = iassign_icons::insert('not_post');
  2377. $flag_dependency = false;
  2378. }
  2379. } else {
  2380. $icon = iassign_icons::insert('not_post');
  2381. $flag_dependency = false;
  2382. } // if ($dependencysubmissions)
  2383. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2384. } // if ($dependency)
  2385. } // foreach ($dependencys as $dependency)
  2386. } // if ($iassign_statement_activity_item->dependency == 0)
  2387. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2388. if ($flag_dependency == false) {
  2389. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2390. $this->view_iassign = false;
  2391. print '</tr></table>' . "\n";
  2392. }
  2393. else {
  2394. $this->view_iassign = true;
  2395. print '</td>' . "\n";
  2396. } // if ($flag_dependency == false)
  2397. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2398. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2399. // receiver=1 - message to teacher
  2400. // receiver=2 - message to student
  2401. if ($iassign_submission) {
  2402. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2403. if ($verify_message)
  2404. $comment = iassign_icons::insert('comment_unread');
  2405. }
  2406. print '<td width=40% valign="top" align="left">';
  2407. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2408. if ($iassign_statement_activity_item->show_answer == 1) {
  2409. // check status of solution sent by the student
  2410. if ($iassign_submission) {
  2411. switch ($iassign_submission->status) {
  2412. case 3 :
  2413. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2414. break;
  2415. case 2 :
  2416. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2417. break;
  2418. case 1 :
  2419. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2420. break;
  2421. default :
  2422. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2423. $repeat = "";
  2424. $last_iassign = "";
  2425. } // switch ($iassign_submission->status)
  2426. } else {
  2427. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2428. $repeat = "";
  2429. $last_iassign = "";
  2430. }
  2431. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2432. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2433. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2434. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2435. if ($iassign_statement_activity_item->max_experiment == 0)
  2436. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2437. else {
  2438. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2439. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2440. $repeat = "";
  2441. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2442. $this->bottonPost = 0;
  2443. $this->write_solution = 0;
  2444. }
  2445. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2446. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2447. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2448. if ($teacher)
  2449. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2450. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2451. } // if ($iassign_statement_activity_item->show_answer==1)
  2452. else {
  2453. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2454. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2455. $repeat = "";
  2456. $last_iassign = "";
  2457. } elseif ($iassign_submission->status == 1) {
  2458. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2459. }
  2460. }
  2461. print '</td>';
  2462. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2463. print '</tr></table>' . "\n";
  2464. // Presents the iLM
  2465. print '<table width=100% border=0 valign="top">' . "\n";
  2466. print '<td width=80% align="left">';
  2467. 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\".
  2468. print '<td width=20% align="rigth">';
  2469. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2470. print $repeat; // symbol of "redo activity"
  2471. print '</td></tr></table>' . "\n";
  2472. //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)'
  2473. $output = '';
  2474. if (!$iassign_ilm) {
  2475. $iassign_ilm = new stdClass();
  2476. $iassign_ilm->file_jar = "";
  2477. }
  2478. $output .= $OUTPUT->box_start();
  2479. $USER->iassignEdit = $this->bottonPost;
  2480. // ---
  2481. // Presents the iLM
  2482. // Prepare tags to present the iLM
  2483. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2484. $student_answer = ""; //?
  2485. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2486. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2487. $student_answer = "";
  2488. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2489. } else {
  2490. // When student is redoing his activity
  2491. // ATTENTION: exception used by iGeom (exercise with "script")
  2492. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2493. if (substr($ilm_name, 0, 5)=="igeom") {
  2494. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2495. $loadTeacherActivity = true;
  2496. }
  2497. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2498. }
  2499. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2500. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2501. //1 $history_comment = '';
  2502. //1 if ($iassign_submission) {
  2503. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2504. //1 }
  2505. //1 if (!empty($history_comment)) {
  2506. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2507. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2508. //1 $output .= $history_comment;
  2509. //1 $output .= "</table>\n";
  2510. //1 }
  2511. //1 $output .= "</form></center>\n";
  2512. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2513. //1 }
  2514. $output .= $OUTPUT->box_end();
  2515. print $output;
  2516. } // if ($this->view_iassign)
  2517. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2518. } // if ($this->view_iassign)
  2519. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2520. else
  2521. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2522. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2523. print '<table width=100% border=0 valign="top">' . "\n";
  2524. print '<tr><td width=60% valign="top">' . "\n";
  2525. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2526. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2527. print '</tr></table>' . "\n";
  2528. $student_answer = "";
  2529. $enderecoPOST = "";
  2530. // Prepare tags to present the iLM
  2531. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2532. print $output;
  2533. }
  2534. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2535. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2536. 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
  2537. // Put a block with area to sent/answer comments
  2538. $output = '';
  2539. $history_comment = '';
  2540. $row = optional_param('row', 0, PARAM_INT);
  2541. $column = optional_param('column', 0, PARAM_INT);
  2542. if ($iassign_submission) {
  2543. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2544. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2545. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2546. }
  2547. else {
  2548. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2549. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2550. }
  2551. $output .= $OUTPUT->box_start();
  2552. //if (!empty($history_comment)) {
  2553. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2554. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2555. $output .= "</table>";
  2556. print " <script type='text/javascript'>
  2557. //<![CDATA[
  2558. function submit_comment(url) {
  2559. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2560. var formData = new FormData();
  2561. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2562. var request = new XMLHttpRequest();
  2563. request.open('POST', url);
  2564. document.getElementById('comments_history').innerHTML = '';
  2565. request.onload = function (e) {
  2566. if (request.readyState === 4) {
  2567. if (request.status === 200) {
  2568. document.getElementById('comments_history').innerHTML = request.responseText;
  2569. document.getElementById('check-message-success').style.visibility = 'visible';
  2570. setTimeout(function(){
  2571. document.getElementById('check-message-success').style.visibility = 'hidden';
  2572. }, 3000);
  2573. }
  2574. }
  2575. };
  2576. document.formEnvioComment.submission_comment.value = '';
  2577. request.send(formData);
  2578. }
  2579. //]]>
  2580. </script>";
  2581. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2582. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2583. $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";
  2584. $output .= "</form> </center>\n";
  2585. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2586. // }
  2587. $output .= $OUTPUT->box_end();
  2588. print $output;
  2589. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2590. // final block 'studant'
  2591. print $OUTPUT->footer();
  2592. die();
  2593. } // function view_iassign_current()
  2594. /// Export the data from performance report into CSV file format
  2595. function export_csv () {
  2596. global $USER, $CFG, $DB, $OUTPUT;
  2597. $str = "";
  2598. $fields = "student_id, student_name";
  2599. // Finding all iassign activities for the iassign:
  2600. $id = $this->cm->id;
  2601. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2602. $c = 1;
  2603. foreach ($iassign_list as $iassign) {
  2604. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2605. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2606. $c ++;
  2607. }
  2608. // Finding enrolled students:
  2609. $params = array('shortname' => 'student');
  2610. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2611. $context = context_course::instance($this->course->id);
  2612. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2613. $students = $DB->get_records_sql(
  2614. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2615. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2616. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2617. foreach ($students as $student) {
  2618. $str .= $student->userid . ',';
  2619. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2620. foreach ($iassign_list as $iassign) {
  2621. $str .= ',' . $iassign->id . ',';
  2622. $str .= '"' . $iassign->name . '",';
  2623. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2624. if ($student_submissions) {
  2625. $str .= $student_submissions->experiment . ',';
  2626. $str .= $student_submissions->grade . ',';
  2627. switch ($student_submissions->status) {
  2628. case 3:
  2629. $str .= '"correct",';
  2630. break;
  2631. case 2:
  2632. $str .= '"incorrect",';
  2633. break;
  2634. case 1:
  2635. $str .= '"post",';
  2636. break;
  2637. case 0:
  2638. $str .= '"not_post",';
  2639. break;
  2640. }
  2641. }
  2642. else {
  2643. $str .= ',,"not_post",';
  2644. }
  2645. $str .= $iassign->iassign_ilmid . ',';
  2646. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2647. $str .= '"' . $ilm_activity->name . '"';
  2648. }
  2649. $str .= "\n";
  2650. }
  2651. $str = $fields . "\n" . $str;
  2652. header("Content-type: text/csv");
  2653. header("Content-disposition: attachment; filename=report.csv");
  2654. header("Pragma: no-cache");
  2655. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2656. header('Content-Length: ' . strlen($str));
  2657. header('Connection: close');
  2658. print $str;
  2659. flush();
  2660. } // function export_csv()
  2661. /// Display report of performance
  2662. function report () {
  2663. global $USER, $CFG, $DB, $OUTPUT;
  2664. $id = $this->cm->id;
  2665. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2666. if ($this->action != 'print') {
  2667. $title = get_string('report', 'iassign');
  2668. print $OUTPUT->header();
  2669. } // if ($this->action != 'print')
  2670. print $OUTPUT->box_start();
  2671. $this->view_legend_icons();
  2672. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2673. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2674. print $OUTPUT->box_end();
  2675. if ($this->action == 'print')
  2676. print '<table border=1 width="100%">' . "\n";
  2677. else
  2678. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped" width="100%">' . "\n";
  2679. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2680. // $num = array();
  2681. $i = 1;
  2682. $num = array();
  2683. $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;";
  2684. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2685. $test_exercise = "";
  2686. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2687. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2688. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2689. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2690. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2691. $num[$i] = new stdClass();
  2692. $num[$i]->name = $iassign->name;
  2693. $num[$i]->id = $i;
  2694. $num[$i]->iassignid = $iassign->id;
  2695. print ' <tr >' . "\n";
  2696. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2697. print "<td class=\"cell c0 actvity\">";
  2698. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2699. print ' </tr>' . "\n";
  2700. $i++;
  2701. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2702. } // foreach ($iassign_list as $iassign)
  2703. $num_exerc = $i; // total of exercises
  2704. print "</table>";
  2705. print "<p></p>";
  2706. if ($this->action == 'print')
  2707. print '<table border=1 width="100%">' . "\n";
  2708. else // ./theme/boost/style/moodle.css: .generaltable
  2709. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  2710. $context = context_course::instance($this->course->id);
  2711. if ($num_exerc > 1) {
  2712. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2713. $params = array('shortname' => 'student');
  2714. $role = $DB->get_record_sql(
  2715. "SELECT s.id, s.shortname FROM {role} s " .
  2716. " WHERE s.shortname = :shortname", $params);
  2717. // $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");
  2718. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2719. $students = $DB->get_records_sql(
  2720. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2721. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2722. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2723. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2724. $width = 90/$num_exerc;
  2725. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  2726. $sum_iassign_correct[$j] = 0;
  2727. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2728. }
  2729. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2730. $sum_iassign = $j - 1;
  2731. print '</tr>' . "\n";
  2732. $total = 0;
  2733. $sum_student = 0;
  2734. $comment = iassign_icons::insert('comment_read');
  2735. $sum_comment = 0;
  2736. $sum_correct_iassign = array();
  2737. $sum_correct_student = array();
  2738. $USER->matrix_iassign = array();
  2739. if ($students) {
  2740. $w = 0;
  2741. foreach ($students as $tmp) { // count students
  2742. $users_array[$w] = $tmp;
  2743. $w++;
  2744. }
  2745. for ($x=0; $x<$w; $x++) { // for all students
  2746. print '<tr>' . "\n";
  2747. $sum_student ++;
  2748. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2749. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  2750. $total_student = 0;
  2751. $tentativas = 0;
  2752. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  2753. $sum_comment = $sum_verify_message = 0;
  2754. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2755. if ($student_submissions) {
  2756. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2757. $tentativas = $student_submissions->experiment;
  2758. // Get student comments
  2759. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2760. $params = array('iassign_submissionid' => $student_submissions->id);
  2761. $student_submissions_comment = $DB->get_record_sql(
  2762. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2763. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2764. if ($student_submissions_comment) // student has comment
  2765. foreach ($student_submissions_comment as $tmp)
  2766. $sum_comment = $tmp;
  2767. // informations to previous activities
  2768. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  2769. else $iassign_previous = $num[$j - 1]->iassignid;
  2770. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2771. else $user_previous = $users_array[$x - 1]->userid;
  2772. // next
  2773. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2774. else $iassign_next = "-1";
  2775. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2776. else $user_next = "-1";
  2777. $position = "&row= $x&column=$j";
  2778. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2779. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2780. $url .= $position;
  2781. // receiver=1 - message to teacher
  2782. // receiver=2 - message to student
  2783. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2784. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2785. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2786. $verify_message = $DB->get_record_sql(
  2787. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2788. "WHERE iassign_submissionid = :iassign_submissionid " .
  2789. " AND return_status= :return_status " .
  2790. " AND receiver= :receiver", $params);
  2791. if ($verify_message)
  2792. foreach ($verify_message as $tmp)
  2793. $sum_verify_message = $tmp;
  2794. if ($sum_verify_message > 0)
  2795. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  2796. else
  2797. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  2798. if ($student_submissions->status == 3) {
  2799. $sum_iassign_correct[$j] ++;
  2800. $total_student ++;
  2801. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  2802. }
  2803. elseif ($student_submissions->status == 2) {
  2804. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  2805. }
  2806. elseif ($student_submissions->status == 1) {
  2807. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2808. }
  2809. elseif ($student_submissions->status == 0) {
  2810. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2811. }
  2812. if ($this->action != 'print') {
  2813. if ($tentativas > 0)
  2814. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2815. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2816. . $feedback
  2817. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2818. . $tentativas
  2819. . '</span> </button>'
  2820. . '</a>' . "\n";
  2821. else
  2822. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2823. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2824. . $feedback
  2825. .'</button>'
  2826. . '</a>' . "\n";
  2827. if ($sum_comment > 0 && $sum_verify_message > 0)
  2828. print '<a href="' . $url . '"> '
  2829. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2830. . $comment
  2831. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2832. . $sum_verify_message . '/' . $sum_comment
  2833. . '</span> </button>'
  2834. . '</a>';
  2835. else if ($sum_comment > 0)
  2836. print '<a href="' . $url . '"> '
  2837. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  2838. . $comment
  2839. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2840. . $sum_comment
  2841. . '</span> </button>'
  2842. . '</a>';
  2843. print '</td>' . "\n";
  2844. }
  2845. if ($this->action == 'print')
  2846. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2847. } // if ($student_submissions)
  2848. else { // if ($student_submissions)
  2849. // Student does not have any submission
  2850. // informations to browse previous activities
  2851. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  2852. else $iassign_previous = $num[$j - 1]->iassignid;
  2853. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2854. else $user_previous = $users_array[$x - 1]->userid;
  2855. // next
  2856. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2857. else $iassign_next = "-1";
  2858. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2859. else $user_next = "-1";
  2860. $position = "&row= $x&column=$j";
  2861. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2862. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2863. $url .= $position;
  2864. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2865. if ($this->action == 'print')
  2866. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2867. else {
  2868. print '<td style="text-align: center;"> <a href="' . $url . '">'
  2869. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2870. . $feedback
  2871. .'</button>'
  2872. . '</a>' . "\n";
  2873. // print '<td> &nbsp;</td>';
  2874. if ($sum_comment > 0)
  2875. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  2876. // else print '<td> &nbsp;</td>';
  2877. print '</td>';
  2878. }
  2879. } // else if ($student_submissions)
  2880. $USER->matrix_iassign[$x][$j] = new stdClass();
  2881. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2882. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2883. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2884. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2885. if ($student_submissions)
  2886. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2887. else
  2888. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2889. //print '</td>' . "\n";
  2890. } // for ($j=1; $j<$num_exerc; $j++)
  2891. $total = $total + $total_student;
  2892. $porcentagem = ($total_student / ($j - 1)) * 100;
  2893. if ($tentativas != 0 && $tentativas != null) {
  2894. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2895. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2896. }
  2897. else {
  2898. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2899. }
  2900. print '</tr>' . "\n";
  2901. $sum_correct_student[$sum_student] = new stdClass();
  2902. $sum_correct_student[$sum_student]->name = $name;
  2903. $sum_correct_student[$sum_student]->sum = $total_student;
  2904. } // for ($x = 0; $x < $w; $x ++)
  2905. for ($i = 1; $i < $j; $i ++) {
  2906. if (is_null($sum_iassign_correct[$i]))
  2907. $sum_iassign_correct[$i] = 0;
  2908. $sum_correct_iassign[$i] = new stdClass();
  2909. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2910. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2911. }
  2912. // print '</tr></table>' . "\n";
  2913. }
  2914. } // if ($i>1)
  2915. else {
  2916. print_string('no_activity', 'iassign');
  2917. }
  2918. print "</table>\n";
  2919. if ($this->action != 'print')
  2920. print $OUTPUT->footer();
  2921. die();
  2922. } // function report()
  2923. /// Display graphics of performance
  2924. function stats () {
  2925. global $USER, $CFG, $DB, $OUTPUT;
  2926. $id = $this->cm->id;
  2927. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2928. if ($this->action != 'printstats')
  2929. $title = get_string('graphic', 'iassign');
  2930. $num = array();
  2931. $sum_correct_iassign = array();
  2932. $sum_correct_student = array();
  2933. $sum_student = 0;
  2934. $i = 1;
  2935. foreach ($iassign_list as $iassign) {
  2936. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2937. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2938. $sum_iassign_correct[$i] = 0;
  2939. $num[$i] = new stdClass();
  2940. $num[$i]->name = $iassign->name;
  2941. $num[$i]->id = $i;
  2942. $num[$i]->iassignid = $iassign->id;
  2943. $i ++;
  2944. } // if ($iassign->type_iassign == 3)
  2945. } // foreach ($iassign_list as $iassign)
  2946. $sum_iassign = $i - 1;
  2947. $context = context_course::instance($this->course->id);
  2948. if ($i > 1) {
  2949. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2950. $params = array('shortname' => 'student');
  2951. $role = $DB->get_record_sql(
  2952. "SELECT s.id, s.shortname FROM {role} s " .
  2953. " WHERE s.shortname = :shortname", $params);
  2954. // $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");
  2955. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2956. $students = $DB->get_records_sql(
  2957. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2958. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2959. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2960. $total = 0;
  2961. $sum_student = 0;
  2962. $j = 0;
  2963. $sum_correct_iassign = array();
  2964. $sum_correct_student = array();
  2965. $sum_experiment = array();
  2966. if ($students) {
  2967. foreach ($students as $users) {
  2968. $sum_student ++;
  2969. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2970. // rows
  2971. $total_student = 0;
  2972. for ($j = 1; $j < $i; $j ++) {
  2973. $total_experiment = 0;
  2974. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2975. if ($student_submissions) {
  2976. if ($student_submissions->status == 3) {
  2977. $sum_iassign_correct[$j] ++;
  2978. $total_student ++;
  2979. } // if ($student_submissions->status == 3)
  2980. $total_experiment += $student_submissions->experiment;
  2981. }
  2982. $sum_experiment[$j] = $total_experiment;
  2983. } // for ($j=1; $j<$i; $j++)
  2984. $total = $total + $total_student;
  2985. $sum_correct_student[$sum_student] = new stdClass();
  2986. $sum_correct_student[$sum_student]->name = $name;
  2987. $sum_correct_student[$sum_student]->sum = $total_student;
  2988. } // foreach ($students as $users)
  2989. }
  2990. for ($i = 1; $i < $j; $i ++) {
  2991. if (is_null($sum_iassign_correct[$i]))
  2992. $sum_iassign_correct[$i] = 0;
  2993. $sum_correct_iassign[$i] = new stdClass();
  2994. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2995. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2996. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2997. } // for ($i = 1; $i < $j; $i++)
  2998. } // if ($i > 1)
  2999. if ($this->action != 'printstats') {
  3000. $title = get_string('graphic', 'iassign');
  3001. print $OUTPUT->header();
  3002. $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>";
  3003. $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>";
  3004. print '<table width=100%><tr>';
  3005. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3006. print '<td width=15% align="right">' . $link_report . '</td>';
  3007. print '</td></tr></table>' . "\n";
  3008. print "<br><br>";
  3009. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3010. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3011. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3012. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3013. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3014. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3015. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3016. print '</tr>' . "\n";
  3017. $sum_correct = 0;
  3018. if ($sum_correct_iassign) {
  3019. foreach ($sum_correct_iassign as $iassign) {
  3020. if (is_null($iassign->experiment))
  3021. $iassign->experiment = 0;
  3022. $bar = "";
  3023. $sum = $iassign->sum;
  3024. $percent = ($sum / $sum_student) * 100;
  3025. $text = number_format($percent, 1) . '%';
  3026. $sum_correct += $sum;
  3027. if ($sum > 0) {
  3028. for ($i = 1; $i < $percent * 2; $i ++)
  3029. $bar .= iassign_icons::insert('hbar_blue');
  3030. $bar .= iassign_icons::insert('hbar_blue_r');
  3031. } // if ($sum > 0)
  3032. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3033. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3034. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3035. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3036. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3037. print '</tr>' . "\n";
  3038. } // foreach ($sum_correct_iassign as $iassign)
  3039. }
  3040. print "</table>";
  3041. print "<br><br>";
  3042. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3043. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3044. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3045. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3046. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3047. print '</tr>' . "\n";
  3048. $sum_correct = 0;
  3049. foreach ($sum_correct_student as $student) {
  3050. $bar = "";
  3051. $sum = $student->sum;
  3052. $percent = ($sum / $sum_iassign) * 100;
  3053. $text = number_format($percent, 1) . '%';
  3054. $sum_correct += $sum;
  3055. if ($sum > 0) {
  3056. for ($i = 1; $i < $percent * 2; $i ++)
  3057. $bar .= iassign_icons::insert('hbar_blue');
  3058. $bar .= iassign_icons::insert('hbar_blue_r');
  3059. } // if ($sum > 0)
  3060. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3061. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3062. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3063. print '</tr>' . "\n";
  3064. } // foreach ($sum_correct_student as $student)
  3065. print "</table>\n";
  3066. print "<br><br>\n";
  3067. $var = 0;
  3068. $cv = 0;
  3069. $dv = 0;
  3070. $avg = 0;
  3071. if ($sum_correct_student) {
  3072. $avg = $sum_correct / $sum_student;
  3073. if ($avg > 0) {
  3074. foreach ($sum_correct_student as $student)
  3075. $var += pow($student->sum - $avg, 2);
  3076. $var = $var / $sum_student;
  3077. $dv = sqrt($var);
  3078. $cv = ($dv / $avg) * 100;
  3079. }
  3080. }
  3081. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3082. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3083. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3084. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3085. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3086. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3087. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3088. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3089. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3090. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3091. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3092. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3093. print "</table>\n";
  3094. print $OUTPUT->footer();
  3095. } else {
  3096. print "<STYLE TYPE='text/css'>
  3097. <!--
  3098. .boldtable {
  3099. font-family:sans-serif;
  3100. font-size:10pt;
  3101. }
  3102. -->
  3103. </STYLE>\n";
  3104. print '<table border=1 width=100%>' . "\n";
  3105. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3106. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3107. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3108. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3109. print '</tr>' . "\n";
  3110. $sum_correct = 0;
  3111. foreach ($sum_correct_iassign as $iassign) {
  3112. $bar = "";
  3113. $sum = $iassign->sum;
  3114. $percent = ($sum / $sum_student) * 100;
  3115. $text = number_format($percent, 1) . '%';
  3116. $sum_correct += $sum;
  3117. if ($sum > 0) {
  3118. for ($i = 1; $i < $percent * 2; $i ++)
  3119. $bar .= iassign_icons::insert('hbar_blue');
  3120. $bar .= iassign_icons::insert('hbar_blue_r');
  3121. } // if ($sum > 0)
  3122. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3123. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3124. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3125. print '</tr>' . "\n";
  3126. } // foreach ($sum_correct_iassign as $iassign)
  3127. print "</table>";
  3128. print "<br><br>";
  3129. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3130. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3131. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3132. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3133. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3134. print '</tr>' . "\n";
  3135. $sum_correct = 0;
  3136. foreach ($sum_correct_student as $student) {
  3137. $bar = "";
  3138. $sum = $student->sum;
  3139. $percent = ($sum / $sum_iassign) * 100;
  3140. $text = number_format($percent, 1) . '%';
  3141. $sum_correct += $sum;
  3142. if ($sum > 0) {
  3143. for ($i = 1; $i < $percent * 2; $i ++)
  3144. $bar .= iassign_icons::insert('hbar_blue');
  3145. $bar .= iassign_icons::insert('hbar_blue_r');
  3146. } // if ($sum > 0)
  3147. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3148. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3149. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3150. print '</tr>' . "\n";
  3151. } // foreach ($sum_correct_student as $student)
  3152. print "</table>\n";
  3153. print "<br/><br/>\n";
  3154. $var = 0;
  3155. $cv = 0;
  3156. $dv = 0;
  3157. $avg = 0;
  3158. if ($sum_correct_student) {
  3159. $avg = $sum_correct / $sum_student;
  3160. if ($avg > 0) {
  3161. foreach ($sum_correct_student as $student)
  3162. $var += pow($student->sum - $avg, 2);
  3163. $var = $var / $sum_student;
  3164. $dv = sqrt($var);
  3165. $cv = ($dv / $avg) * 100;
  3166. }
  3167. }
  3168. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3169. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3170. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3171. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3172. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3173. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3174. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3175. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3176. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3177. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3178. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3179. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3180. print "</table>\n";
  3181. } // if ($this->action != 'printstats')
  3182. die();
  3183. }
  3184. /// Display graphics of performance for students
  3185. function stats_students () {
  3186. global $USER, $CFG, $DB, $OUTPUT;
  3187. $id = $this->cm->id;
  3188. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3189. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3190. $title = get_string('results', 'iassign');
  3191. $sum_correct = 0;
  3192. $sum_incorrect = 0;
  3193. $sum_post = 0;
  3194. $sum_nopost = 0;
  3195. $sum_iassign = count($iassign_statement_list);
  3196. $bar_nopost = "";
  3197. $bar_correct = "";
  3198. $bar_incorrect = "";
  3199. $bar_post = "";
  3200. $text_nopost = "";
  3201. $text_correct = "";
  3202. $text_incorrect = "";
  3203. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3204. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3205. if ($iassign_submission) {
  3206. if ($iassign_submission->status == 3)
  3207. $sum_correct ++;
  3208. elseif ($iassign_submission->status == 2)
  3209. $sum_incorrect ++;
  3210. elseif ($iassign_submission->status == 1)
  3211. $sum_post ++;
  3212. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3213. $sum_nopost ++;
  3214. } // if ($iassign_submission)
  3215. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3216. if ($sum_iassign > 0) {
  3217. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3218. $text_correct = number_format($percent_correct, 1) . '%';
  3219. }
  3220. if ($sum_correct > 0) {
  3221. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3222. $bar_correct .= iassign_icons::insert('hbar_green');
  3223. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3224. } // if ($sum_correct > 0)
  3225. if ($sum_iassign > 0) {
  3226. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3227. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3228. }
  3229. if ($sum_incorrect > 0) {
  3230. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3231. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3232. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3233. } // if ($sum_incorrect > 0)
  3234. if ($sum_iassign > 0) {
  3235. $percent_post = ($sum_post / $sum_iassign) * 100;
  3236. $text_post = number_format($percent_post, 1) . '%';
  3237. }
  3238. if ($sum_post > 0) {
  3239. for ($i = 1; $i < $percent_post * 2; $i ++)
  3240. $bar_post .= iassign_icons::insert('hbar_blue');
  3241. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3242. } // if ($sum_post > 0)
  3243. if ($sum_iassign > 0) {
  3244. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3245. $text_nopost = number_format($percent_nopost, 1) . '%';
  3246. }
  3247. if ($sum_nopost > 0) {
  3248. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3249. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3250. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3251. } // if ($sum_nopost > 0)
  3252. print $OUTPUT->header();
  3253. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3254. print '<table width=100%><tr>';
  3255. print '<td align="right">' . $link_return . '</td>' . "\n";
  3256. print '</td></tr></table>' . "\n";
  3257. print "<br/><br/>\n";
  3258. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  3259. print '<tr><th colspan=3 class="header c1">' . "\n";
  3260. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3261. // $imagetext = '');
  3262. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3263. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3264. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3265. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3266. print '</tr>' . "\n";
  3267. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3268. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3269. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3270. print '</tr>' . "\n";
  3271. if ($sum_post) {
  3272. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3273. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3274. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3275. print '</tr>' . "\n";
  3276. } // if ($sum_post)
  3277. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3278. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3279. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3280. print '</tr>' . "\n";
  3281. print "</table>";
  3282. print "<br><br>";
  3283. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3284. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3285. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3286. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3287. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3288. $sum_grade = 0;
  3289. $sum_grade_student = 0;
  3290. $avg = 0;
  3291. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3292. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3293. if (!$iassign_submission) {
  3294. $iassign_submission = new stdClass();
  3295. $iassign_submission->grade = 0;
  3296. }
  3297. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3298. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3299. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3300. print '</tr>' . "\n";
  3301. $sum_grade += $iassign_statement_activity_item->grade;
  3302. $sum_grade_student += $iassign_submission->grade;
  3303. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3304. if ($sum_grade > 0)
  3305. $avg = $sum_grade_student / $sum_grade * 100;
  3306. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3307. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3308. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3309. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3310. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3311. print "</table>";
  3312. print $OUTPUT->footer();
  3313. die();
  3314. } // function stats_students()
  3315. /// Display page of iAssign's activity
  3316. function view_iassigns () {
  3317. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3318. $id = $this->cm->id;
  3319. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3320. $notice = optional_param('notice', '', PARAM_TEXT);
  3321. if (strpos($notice, 'error'))
  3322. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3323. else if ($notice != '')
  3324. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3325. print $OUTPUT->box_start();
  3326. print '<table width=100% border=0><tr>' . "\n";
  3327. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3328. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  3329. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  3330. $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>";
  3331. $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>";
  3332. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3333. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3334. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3335. // Has capability to see "report": teacher or up
  3336. print '<td width=10% align="left">' . "\n";
  3337. print $link_help;
  3338. print '</td>' . "\n";
  3339. print '<td width=10% align="left">' . "\n";
  3340. print $link_report;
  3341. print '</td>' . "\n";
  3342. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3343. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3344. print '<td width=15% align="left">' . "\n";
  3345. print $link_add;
  3346. print "</td>\n";
  3347. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3348. //print '</tr></table>' . "\n";
  3349. print '<div style="float: right;">';
  3350. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3351. if ($iassign_list) {
  3352. print '<td align="right">' . "\n";
  3353. // $USER->iassignEdit == 0 view 'Turn editing off'
  3354. // $USER->iassignEdit == 1 view 'Turn editing on'
  3355. if (!isset($USER->iassignEdit))
  3356. $USER->iassignEdit = 0;
  3357. if ($USER->iassignEdit == 0) {
  3358. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3359. $botton = 1;
  3360. } // if ($USER->iassignEdit == 0)
  3361. elseif ($USER->iassignEdit == 1) {
  3362. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3363. $botton = 0;
  3364. } // elseif ($USER->iassignEdit == 1)
  3365. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3366. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3367. print " <input type=submit value='$bottonEdit_message'/>\n";
  3368. print "</form>\n";
  3369. print "</td>\n";
  3370. } // if ($iassign_list)
  3371. }
  3372. print '</tr></table>' . "\n";
  3373. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3374. // $this->view_legend_icons();
  3375. print $OUTPUT->box_end();
  3376. $iassign_array_exercise = array();
  3377. $i_exercise = 0;
  3378. $iassign_array_test = array();
  3379. $i_test = 0;
  3380. $iassign_array_example = array();
  3381. $i_example = 0;
  3382. $iassign_array_general = array();
  3383. $i_general = 0;
  3384. if ($iassign_list) {
  3385. if ($this->iassign->activity_group == 0) {
  3386. foreach ($iassign_list as $iassign) {
  3387. $iassign_array_general[$i_general] = $iassign;
  3388. $i_general ++;
  3389. }
  3390. } // if ($this->iassign->activity_group == 0)
  3391. else {
  3392. foreach ($iassign_list as $iassign) {
  3393. if ($iassign->type_iassign == 3) {
  3394. $iassign_array_exercise[$i_exercise] = $iassign;
  3395. $i_exercise ++;
  3396. } // if ($iassign->type_iassign == 3)
  3397. if ($iassign->type_iassign == 2) {
  3398. $iassign_array_test[$i_test] = $iassign;
  3399. $i_test ++;
  3400. } // if ($iassign->type_iassign == 2)
  3401. if ($iassign->type_iassign == 1) {
  3402. $iassign_array_example[$i_example] = $iassign;
  3403. $i_example ++;
  3404. } // if ($iassign->type_iassign == 1)
  3405. }
  3406. }
  3407. if ($iassign_array_exercise) {
  3408. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3409. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3410. }
  3411. if ($iassign_array_test) {
  3412. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3413. $this->show_iassign($title, $iassign_array_test, $i_test);
  3414. }
  3415. if ($iassign_array_example) {
  3416. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3417. $this->show_iassign($title, $iassign_array_example, $i_example);
  3418. }
  3419. if ($iassign_array_general) {
  3420. $title = "";
  3421. $this->show_iassign($title, $iassign_array_general, $i_general);
  3422. }
  3423. } else { // if ($iassign_list)
  3424. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3425. }
  3426. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3427. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3428. print $OUTPUT->box_start();
  3429. print '<table width=100% border=0><tr>' . "\n";
  3430. print '<td width=10% align="left">' . "\n";
  3431. print $link_report;
  3432. print '</td>' . "\n";
  3433. print '</tr></table>' . "\n";
  3434. print $OUTPUT->box_end();
  3435. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3436. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3437. print $OUTPUT->box_start();
  3438. print '<table width=100% border=0><tr>' . "\n";
  3439. print '<td align="left">' . "\n";
  3440. print $link_add;
  3441. print '</td>' . "\n";
  3442. print '</tr></table>' . "\n";
  3443. print $OUTPUT->box_end();
  3444. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3445. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3446. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3447. $this->view_legend_icons();
  3448. } // function view_iassigns()
  3449. /// Display all iAssigns
  3450. function show_iassign ($title, $iassign_array, $i) {
  3451. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3452. $id = $this->cm->id;
  3453. print $OUTPUT->box_start();
  3454. print " <script type='text/javascript'>
  3455. //<![CDATA[
  3456. function validate_move () {
  3457. var radios = document.getElementsByName('iassign_destiny');
  3458. var formValid = false;
  3459. //alert('aqui validate_move()');
  3460. var i = 0;
  3461. while (!formValid && i < radios.length) {
  3462. if (radios[i].checked) formValid = true;
  3463. i++;
  3464. }
  3465. if (!formValid) {
  3466. document.getElementById('move_dest').classList.add('alert-danger');
  3467. }
  3468. return formValid;
  3469. }
  3470. var modal;
  3471. function load_move(id_ias) {
  3472. document.form_move_activity.iassign_current.value = id_ias;
  3473. modal.style.display = 'block';
  3474. var radios = document.getElementsByName('iassign_destiny');
  3475. var i = 0;
  3476. while (i < radios.length) {
  3477. radios[i].checked = false;
  3478. i++;
  3479. }
  3480. document.getElementById('move_dest').classList.remove('alert-danger');
  3481. }
  3482. function load_modal_elements() {
  3483. modal = document.getElementById('myModal');
  3484. var span = document.getElementById('close_modal');
  3485. span.onclick = function() {
  3486. modal.style.display = 'none';
  3487. }
  3488. window.onclick = function(event) {
  3489. if (event.target == modal) {
  3490. modal.style.display = 'none';
  3491. }
  3492. }
  3493. }
  3494. window.onload = load_modal_elements;
  3495. //]]>
  3496. </script>\n";
  3497. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3498. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3499. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3500. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3501. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3502. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3503. <input type='hidden' name='iassign_current' value='' />";
  3504. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3505. $section = $course_sections[0];
  3506. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3507. for ($k = 0; $k < count($ids_sections); $k++) {
  3508. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3509. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3510. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3511. if ($c_cm) {
  3512. if ($ccm->instance == $c_cm->instance) {
  3513. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3514. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3515. }
  3516. else {
  3517. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3518. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3519. }
  3520. }
  3521. }
  3522. $radio_buttons .= "</ul>";
  3523. }
  3524. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3525. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3526. </form>
  3527. </div></div> </div></div>\n";
  3528. print " <style>.modal {
  3529. display: none;
  3530. position: fixed;
  3531. z-index: 1;
  3532. left: 0;
  3533. top: 0;
  3534. width: 100%;
  3535. height: 100%;
  3536. overflow: scroll;
  3537. background-color: rgb(0,0,0);
  3538. background-color: rgba(0,0,0,0.4);
  3539. }
  3540. .modal-content {
  3541. background-color: #fefefe;
  3542. margin: 15% auto;
  3543. padding: 10px 10px;
  3544. border: 1px solid #888;
  3545. width: 50%;
  3546. }
  3547. #close_modal {
  3548. color: #aaa;
  3549. float: right;
  3550. font-size: 28px;
  3551. font-weight: bold;
  3552. margin-top: -15px;
  3553. margin-right: -3px;
  3554. }
  3555. #close_modal:hover,
  3556. #close_modal:focus {
  3557. color: black;
  3558. text-decoration: none;
  3559. cursor: pointer;
  3560. }
  3561. #modal_title {
  3562. min-height: 3rem;
  3563. color: initial;
  3564. background: initial;
  3565. font-size: 1.5rem;
  3566. line-height: 1.5;
  3567. padding: 15px;
  3568. border-bottom: 1px solid #e5e5e5;
  3569. }
  3570. .input_move {
  3571. width: 90%;
  3572. padding: 2px;
  3573. }
  3574. .input_move:hover {
  3575. background: #eff0ef;
  3576. }
  3577. </style>";
  3578. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3579. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3580. for ($j = 0; $j < $i; $j ++) {
  3581. $iassign_current = $iassign_array[$j]->id;
  3582. // receiver=1 - message to teacher
  3583. // receiver=2 - message to student
  3584. $sum_comment = 0;
  3585. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3586. foreach ($iassign_submissions as $iassign_submission) {
  3587. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3588. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3589. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3590. if ($verify_message)
  3591. foreach ($verify_message as $tmp)
  3592. $sum_comment += $tmp;
  3593. } // foreach ($iassign_submissions as $iassign_submission)
  3594. if ($sum_comment == 0)
  3595. $comment_unread = "";
  3596. else {
  3597. $comment_unread_message = get_string('comment_unread', 'iassign');
  3598. if ($sum_comment == 1)
  3599. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3600. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3601. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3602. }
  3603. if ($j == $i - 1)
  3604. $iassign_down = $iassign_array[$j]->id;
  3605. else
  3606. $iassign_down = $iassign_array[$j + 1]->id;
  3607. if ($j > 0)
  3608. $iassign_up = $iassign_array[$j - 1]->id;
  3609. else
  3610. $iassign_up = $iassign_array[$j]->id;
  3611. if ($iassign_array[$j]->visible == 0)
  3612. $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>";
  3613. else
  3614. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3615. $links .= $comment_unread;
  3616. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3617. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3618. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3619. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3620. if ($j==0) // first activity
  3621. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3622. else
  3623. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3624. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3625. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3626. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3627. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3628. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3629. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3630. if (count($iassign_array) > 1) {
  3631. if ($j == 0)
  3632. $links .= $link_down;
  3633. elseif ($j == $i - 1)
  3634. $links .= $link_up;
  3635. else
  3636. $links .= $link_up . $link_down;
  3637. } // if (count($iassign_array) > 1)
  3638. $links .= $link_edit . $link_delete;
  3639. if ($iassign_array[$j]->visible == 0)
  3640. $links .= $link_visible_show;
  3641. else
  3642. $links .= $link_visible_hide;
  3643. $links .= $link_duplicate_activity . $link_move_activity;
  3644. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3645. print '<p>' . $links . '</p>' . "\n";
  3646. }
  3647. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3648. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3649. print '<table width=100% ><tr>' . "\n";
  3650. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3651. print '</tr></table>' . "\n";
  3652. for ($j = 0; $j < $i; $j ++) {
  3653. $icon_status = "";
  3654. $icon_comment = "";
  3655. if ($iassign_array[$j]->visible == 1) {
  3656. $iassign_current = $iassign_array[$j]->id;
  3657. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3658. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3659. $icon_status = "";
  3660. $icon_comment = "";
  3661. if ($iassign_submission) {
  3662. // receiver=1 - message to teacher
  3663. // receiver=2 - message to student
  3664. // $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");
  3665. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3666. $verify_message = $DB->get_record_sql(
  3667. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3668. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3669. if ($verify_message)
  3670. foreach ($verify_message as $tmp)
  3671. $sum_comment = $tmp;
  3672. if ($sum_comment > 0) {
  3673. $comment_unread_message = get_string('comment_unread', 'iassign');
  3674. if ($sum_comment == 1)
  3675. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3676. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3677. }
  3678. // $icon_comment = iassign_icons::insert('comment_unread');
  3679. if ($iassign_array[$j]->type_iassign == 3) {
  3680. if ($iassign_array[$j]->show_answer == 1) {
  3681. if ($iassign_submission->status == 3)
  3682. $icon_status = iassign_icons::insert('correct');
  3683. elseif ($iassign_submission->status == 2)
  3684. $icon_status = iassign_icons::insert('incorrect');
  3685. elseif ($iassign_submission->status == 1)
  3686. $icon_status = iassign_icons::insert('post');
  3687. elseif ($iassign_submission->status == 0)
  3688. $icon_status = iassign_icons::insert('not_post');
  3689. } // if ($iassign_array[$j]->show_answer==1)
  3690. else {
  3691. if ($iassign_submission->status == 0)
  3692. $icon_status = iassign_icons::insert('not_post');
  3693. else
  3694. $icon_status = iassign_icons::insert('post');
  3695. }
  3696. } // if ($iassign_array[$j]->type_iassign == 3)
  3697. } // if ($iassign_submission)
  3698. elseif ($iassign_array[$j]->type_iassign == 3) {
  3699. $icon_status = iassign_icons::insert('not_post');
  3700. } // if ($iassign_array[$j]->type_iassign == 3)
  3701. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3702. } // if ($iassign_array[$j]->visible == 1)
  3703. } // for ($j = 0; $j < $i; $j++)
  3704. } else if (isguestuser()) {
  3705. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3706. print '<table width=100% ><tr>' . "\n";
  3707. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3708. print '</tr></table>' . "\n";
  3709. for ($j = 0; $j < $i; $j ++) {
  3710. $icon_status = "";
  3711. $icon_comment = "";
  3712. if ($iassign_array[$j]->visible == 1) {
  3713. $iassign_current = $iassign_array[$j]->id;
  3714. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3715. print '<p>' . $links . '</p>' . "\n";
  3716. } // if ($iassign_array[$j]->visible == 1)
  3717. }
  3718. }
  3719. print $OUTPUT->box_end();
  3720. } // function show_iassign($title, $iassign_array, $i)
  3721. /// Show message of return
  3722. function return_home_course ($message) {
  3723. //D global $DB, $OUTPUT;
  3724. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3725. //D echo $OUTPUT->box_start();
  3726. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3727. //D echo '<tr><td align="left"><strong>' . "\n";
  3728. //D print_string($message, 'iassign');
  3729. //D echo '</strong></td>' . "\n";
  3730. //D echo '<td width=20% align="right">' . "\n";
  3731. //D echo $link_return;
  3732. //D echo '</td></tr></table>' . "\n";
  3733. //D echo $OUTPUT->box_end();
  3734. //D // echo $OUTPUT->footer();
  3735. redirect(new moodle_url($this->return . '&notice=' . $message));
  3736. exit;
  3737. }
  3738. /// Search comment of activity
  3739. function search_comment_submission ($iassign_submissionid) {
  3740. global $USER, $DB, $OUTPUT, $COURSE;
  3741. // $context = context_course::instance($COURSE->id);
  3742. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3743. $colorEdit2 = "#d2e5fc";
  3744. $has_capability = 0;
  3745. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3746. $text = "";
  3747. if ($comments) {
  3748. $even = 1;
  3749. foreach ($comments as $tmp) {
  3750. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3751. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3752. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3753. // $text .= $tmp->comment . "</td></tr>";
  3754. //} else {
  3755. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3756. $avatar = new user_picture($user_data);
  3757. $avatar->courseid = $COURSE->id;
  3758. $avatar->link = true;
  3759. $user_picture = $OUTPUT->render($avatar);
  3760. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3761. if ($even) {
  3762. $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";
  3763. $even = 0;
  3764. } else {
  3765. $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";
  3766. $even = 1;
  3767. }
  3768. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3769. } // foreach ($comments as $tmp)
  3770. }
  3771. return $text;
  3772. }
  3773. /// Update comment of activity
  3774. function update_comment ($iassign_submissionid) {
  3775. global $USER, $DB, $OUTPUT;
  3776. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3777. $receiver = 1; // student message to teacher
  3778. else
  3779. $receiver = 2; // teacher message to student
  3780. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3781. if ($verify_message) {
  3782. foreach ($verify_message as $message) {
  3783. if ($message->receiver == $receiver) {
  3784. $newentry = new stdClass();
  3785. $newentry->id = $message->id;
  3786. $newentry->return_status = 1;
  3787. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3788. print_error('error_update', 'iassign');
  3789. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3790. } // if ($message->receiver == $receiver)
  3791. // Trigger module viewed event.
  3792. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3793. 'objectid' => $this->iassign->id,
  3794. 'context' => $this->context
  3795. ));
  3796. $event->add_record_snapshot('course', $this->course);
  3797. $event->trigger();
  3798. } // foreach ($verify_message as $message)
  3799. }
  3800. }
  3801. /// Record comment of activity
  3802. function write_comment_submission () {
  3803. global $USER, $CFG, $DB;
  3804. $id = $this->cm->id;
  3805. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3806. $row = optional_param('row', 0, PARAM_INT);
  3807. $column = optional_param('column', 0, PARAM_INT);
  3808. $sum_comment = 0;
  3809. $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);
  3810. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3811. $str1 = trim($submission_comment);
  3812. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3813. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3814. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3815. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3816. $receiver = 1; // student message to teacher
  3817. $this->action = 'view';
  3818. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3819. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3820. } else {
  3821. $receiver = 2; // teacher message to student
  3822. $this->action = 'viewsubmission';
  3823. //D $tousers = array(); //MOOC 2016
  3824. //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
  3825. }
  3826. //MOOC 2016: foi p/ 15 linhas acima:
  3827. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3828. // verificar se existe uma submissão para o exercício e aluno informados
  3829. if (!$iassign_submission) {
  3830. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3831. }
  3832. if (!$iassign_submission) {
  3833. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3834. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3835. $this->iassign_submission_current = $id_submission;
  3836. } else {
  3837. $id_submission = $iassign_submission->id;
  3838. } // if (!$iassign_submission)
  3839. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3840. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3841. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3842. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3843. $comments = $DB->get_record_sql(
  3844. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3845. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3846. if ($comments)
  3847. foreach ($comments as $tmp)
  3848. $sum_comment = $tmp;
  3849. if ($sum_comment == 0) {
  3850. $newentry = new stdClass();
  3851. $newentry->iassign_submissionid = $id_submission;
  3852. $newentry->comment_authorid = $USER->id;
  3853. $newentry->timecreated = time();
  3854. $newentry->comment = $submission_comment;
  3855. $newentry->receiver = $receiver;
  3856. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3857. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3858. //T $eventdata = new stdClass();
  3859. //T $eventdata->component = 'mod_iassign'; //your component name
  3860. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3861. //T $eventdata->userfrom = $USER;
  3862. //T $eventdata->userto = $touser;
  3863. //T $eventdata->subject = "Teste de Subject";
  3864. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3865. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3866. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3867. //T $eventdata->smallmessage = "Teste de Mensagem";
  3868. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3869. //T // alteracao tulio faria
  3870. //T //message_send($eventdata);
  3871. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3872. // Trigger module viewed event.
  3873. $event = \mod_iassign\event\submission_comment_created::create(array(
  3874. 'objectid' => $this->iassign->id,
  3875. 'context' => $this->context
  3876. ));
  3877. $event->add_record_snapshot('course', $this->course);
  3878. $event->trigger();
  3879. }
  3880. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3881. // if ($this->action=='viewsubmission') {
  3882. // echo $OUTPUT->header();
  3883. // $this->return_last('confirm_add_comment', $link_return);
  3884. // die;
  3885. // }
  3886. return true;
  3887. } // function write_comment_submission()
  3888. /// Writes a new submission
  3889. // The first student answer is under 'function get_answer()'
  3890. function new_submission ($iassignid, $id_user, $receiver) {
  3891. global $USER, $DB, $OUTPUT;
  3892. $newentry = new stdClass();
  3893. $newentry->iassign_statementid = $iassignid;
  3894. $newentry->userid = $id_user;
  3895. $newentry->timecreated = time();
  3896. $newentry->timemodified = time();
  3897. $newentry->answer = 0; // student only submit message
  3898. if ($receiver == 2) // teacher message to student (write id teacher)
  3899. $newentry->teacher = $USER->id;
  3900. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3901. return_home_course('error_insert_submissions');
  3902. else {
  3903. // Trigger module view event
  3904. $event = \mod_iassign\event\submission_created::create(array(
  3905. 'objectid' => $this->iassign->id,
  3906. 'context' => $this->context
  3907. ));
  3908. $event->add_record_snapshot('course', $this->course);
  3909. $event->trigger();
  3910. }
  3911. return $newentry->id;
  3912. }
  3913. /// Return to a specific address of page
  3914. function return_last ($message, $link_return) {
  3915. global $DB, $OUTPUT;
  3916. print $OUTPUT->box_start();
  3917. print '<table width=100% border=0 valign="top">' . "\n";
  3918. print '<tr><td align="left"><strong>' . "\n";
  3919. print_string($message, 'iassign');
  3920. print '</strong></td>' . "\n";
  3921. print '<td width=20% align="right">' . "\n";
  3922. print $link_return;
  3923. print '</td></tr></table>' . "\n";
  3924. print $OUTPUT->box_end();
  3925. print $OUTPUT->footer();
  3926. die();
  3927. } // function return_last($message, $link_return)
  3928. } // class iassign
  3929. /// Class for manage activities
  3930. class activity {
  3931. var $activity;
  3932. /// Constructor of class.
  3933. // @param int $id Id of activity
  3934. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3935. //D public function activity($id) { self::__construct($id); }
  3936. function __construct ($id) {
  3937. global $DB;
  3938. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3939. if (empty($this->activity))
  3940. $this->activity = null;
  3941. }
  3942. /// Get an activity
  3943. // @return NULL
  3944. function get_activity () {
  3945. if ($this->activity != null)
  3946. return $this->activity;
  3947. else
  3948. return null;
  3949. }
  3950. /// Delete interactive activities
  3951. function delete ($return) {
  3952. global $USER, $CFG, $DB, $OUTPUT;
  3953. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3954. $output = $OUTPUT->header();
  3955. $output .= $OUTPUT->box_start();
  3956. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3957. if ($iassign_submission_currents) {
  3958. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3959. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3960. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3961. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3962. $output .= $OUTPUT->box_end();
  3963. $output .= $OUTPUT->footer();
  3964. print $output;
  3965. die();
  3966. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3967. } // if ($iassign_submission_currents)
  3968. else
  3969. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3970. $output .= '<table width=50% border=0>';
  3971. $output .= '<tr valign="top"><td>';
  3972. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3973. $output .= '</td><td>';
  3974. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3975. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3976. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3977. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3978. $output .= "</form>\n";
  3979. $output .= '</td><td>';
  3980. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3981. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3982. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3983. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3984. $output .= "</form>\n";
  3985. $output .= '</td></tr></table>' . "\n";
  3986. $output .= $OUTPUT->box_end();
  3987. $output .= $OUTPUT->footer();
  3988. print $output;
  3989. } // function delete($return)
  3990. /// Function for confirm the delete of activity
  3991. // @param String $return Url of return
  3992. // @param Object $iassign Object content an activity
  3993. function deleteyes ($return, $iassign) {
  3994. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3995. $msg = '';
  3996. if (!empty($this->activity->id)) {
  3997. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3998. if ($iassign_submission_currents) {
  3999. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4000. foreach ($iassign_submission_currents as $iassign_submission)
  4001. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4002. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4003. } // if ($iassign_submission_currents)
  4004. }
  4005. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4006. // Remove all files associated to this activity:
  4007. $fs = get_file_storage();
  4008. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4009. $this->delete_calendar($this->activity->id);
  4010. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4011. iassign::update_grade_iassign($this->activity->iassignid);
  4012. if ($delete_iassign_current) {
  4013. $iassign->return_home_course('confirm_delete_iassign');
  4014. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4015. } else {
  4016. $iassign->return_home_course('error_confirm_delete_iassign');
  4017. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4018. }
  4019. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4020. }
  4021. }
  4022. /// Changes position of activities (between those inside a group of interactive activities)
  4023. // @param $move_action = must be "up" or "down"
  4024. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4025. function move_iassign ($move_action, $target, $return) {
  4026. global $DB, $OUTPUT;
  4027. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4028. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4029. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4030. if ($move_action=="firstdown") {
  4031. $final_position_source = 2;
  4032. $final_position_target = 1;
  4033. }
  4034. else
  4035. if ($move_action=="down") {
  4036. $final_position_target = $this->activity->position;
  4037. $final_position_source = $final_position_target + 1;
  4038. }
  4039. else
  4040. if ($move_action=="up") {
  4041. $final_position_target = $this->activity->position;
  4042. $final_position_source = $final_position_target - 1;
  4043. }
  4044. else { // error:
  4045. print_error('error_update_move_iassign', 'iassign');
  4046. exit;
  4047. }
  4048. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4049. $newentry->id = $this->activity->id; // ID of the "source activity"
  4050. $newentry->position = $final_position_source;
  4051. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4052. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4053. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4054. print_error('error_update_move_iassign', 'iassign');
  4055. }
  4056. else { // first update performed successfully
  4057. $newentry->id = $iassign_target->id;
  4058. $newentry->position = $final_position_target;
  4059. if (!$DB->update_record('iassign_statement', $newentry))
  4060. print_error('error_update_move_iassign', 'iassign');
  4061. }
  4062. redirect($return);
  4063. }
  4064. /// Enable or disable the display of interactive activities
  4065. function visible_iassign ($return) {
  4066. global $DB;
  4067. $newentry = new stdClass();
  4068. $newentry->id = $this->activity->id;
  4069. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4070. if (!$DB->update_record('iassign_statement', $newentry))
  4071. print_error('error_update_visible_iassign', 'iassign');
  4072. redirect($return);
  4073. }
  4074. /// Add news interactive activities (register in table 'iassign_statement')
  4075. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4076. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4077. function new_iassign ($param) {
  4078. global $DB;
  4079. $newentry = new stdClass();
  4080. $newentry->iassignid = $param->iassignid;
  4081. $newentry->name = $param->name;
  4082. $newentry->type_iassign = $param->type_iassign;
  4083. $newentry->store_all_submissions = $param->store_all_submissions;
  4084. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4085. $proposition = $param->proposition;
  4086. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4087. else $proposition_text = $proposition;
  4088. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4089. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4090. //TODO Then get it directly from the form data $_POST!
  4091. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4092. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4093. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4094. $newentry->author_name = $param->author_name;
  4095. $newentry->author_modified_name = $param->author_modified_name;
  4096. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4097. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4098. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4099. $newentry->grade = $param->grade;
  4100. $newentry->timemodified = time();
  4101. $newentry->timecreated = time();
  4102. if ($param->type_iassign == 1) {
  4103. $newentry->timedue = 0;
  4104. $newentry->timeavailable = 0;
  4105. } // if ($param->type_iassign == 1)
  4106. else {
  4107. $newentry->timedue = $param->timedue;
  4108. $newentry->timeavailable = $param->timeavailable;
  4109. }
  4110. $newentry->preventlate = $param->preventlate;
  4111. $newentry->test = $param->test;
  4112. $newentry->special_param1 = $param->special_param1;
  4113. $newentry->visible = $param->visible;
  4114. $newentry->position = $param->position;
  4115. $newentry->max_experiment = $param->max_experiment;
  4116. $newentry->dependency = $param->dependency;
  4117. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4118. $newentry->show_answer = $param->show_answer;
  4119. $id = $DB->insert_record("iassign_statement", $newentry);
  4120. if ($id) {
  4121. $component = 'mod_iassign';
  4122. $filearea = 'exercise';
  4123. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4124. $file = $fs->get_file_by_id($param->file);
  4125. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4126. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4127. //$itemid = $id;
  4128. // File already inserted in other context!
  4129. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4130. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4131. $updateentry = new stdClass();
  4132. $updateentry->id = $id;
  4133. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4134. $updateentry->filesid = $newfile->get_itemid();
  4135. if (!$DB->update_record("iassign_statement", $updateentry))
  4136. print_error('error_add', 'iassign');
  4137. if ($param->type_iassign == 3)
  4138. iassign::update_grade_iassign($param->iassignid);
  4139. //TODO iLM_HTML5 :: //MOOC2014
  4140. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4141. //D if ($iassign_ilm_configs) {
  4142. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4143. //D if ($iassign_ilm_config->param_type != 'static') {
  4144. //D $newentry = new stdClass();
  4145. //D $newentry->iassign_statementid = $id;
  4146. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4147. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4148. //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});
  4149. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4150. //D print_error('error_add_param', 'iassign');
  4151. //D }
  4152. //D }
  4153. //D }
  4154. // log event --------------------------------------------------------------------------------------
  4155. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4156. // log event --------------------------------------------------------------------------------------
  4157. return $id;
  4158. }
  4159. else
  4160. print_error('error_add', 'iassign');
  4161. } // function new_iassign($param)
  4162. /// Add the calendar entries for this iassign
  4163. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4164. // @return bool
  4165. static function add_calendar ($iassignid) {
  4166. global $DB, $CFG;
  4167. require_once($CFG->dirroot . '/calendar/lib.php');
  4168. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4169. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4170. $event = new stdClass();
  4171. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4172. $event->description = $iassign_statement_activity_item->name;
  4173. $event->courseid = $iassign->course;
  4174. $event->groupid = 0;
  4175. $event->userid = 0;
  4176. $event->modulename = 'iassign';
  4177. $event->instance = $iassign->id;
  4178. $event->eventtype = 'due';
  4179. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4180. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4181. calendar_event::create($event);
  4182. }
  4183. /// Update the calendar entries for this iassign
  4184. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4185. // @return bool
  4186. function update_calendar ($iassignid, $olddescription) {
  4187. global $DB, $CFG;
  4188. require_once($CFG->dirroot . '/calendar/lib.php');
  4189. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4190. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4191. $event = new stdClass();
  4192. $event->id = 0;
  4193. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4194. if ($events) {
  4195. foreach ($events as $value) {
  4196. if ($value->description == $olddescription) {
  4197. $event->id = $value->id;
  4198. }
  4199. }
  4200. }
  4201. if ($event->id != 0) {
  4202. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4203. $event->description = $iassign_statement_activity_item->name;
  4204. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4205. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4206. $calendarevent = calendar_event::load($event->id);
  4207. $calendarevent->update($event);
  4208. } else
  4209. $this->add_calendar($iassignid);
  4210. }
  4211. /// Update the calendar entries for this iassign
  4212. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4213. // @return bool
  4214. function delete_calendar ($iassignid) {
  4215. global $DB, $CFG;
  4216. require_once($CFG->dirroot . '/calendar/lib.php');
  4217. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4218. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4219. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4220. if ($events) {
  4221. foreach ($events as $value) {
  4222. if ($value->description == $iassign_statement_activity_item->name) {
  4223. $DB->delete_records('event', array('id' => $value->id));
  4224. }
  4225. }
  4226. }
  4227. }
  4228. /// Update interactive activities
  4229. function update_iassign ($param) {
  4230. global $DB;
  4231. $component = 'mod_iassign';
  4232. $filearea = 'exercise';
  4233. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4234. $file = $fs->get_file_by_id($param->file);
  4235. $fileold = $fs->get_file_by_id($param->fileold);
  4236. if ($param->file != $param->fileold) {
  4237. if ($fileold) {
  4238. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4239. foreach ($fileoldarea as $value) {
  4240. $value->delete();
  4241. }
  4242. }
  4243. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4244. $itemid = $file->get_itemid() + $param->iassign_id;
  4245. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4246. $param->file = $newfile->get_itemid();
  4247. } else
  4248. $param->file = $file->get_itemid();
  4249. } else {
  4250. $param->file = $file->get_itemid();
  4251. }
  4252. $newentry = new stdClass();
  4253. $newentry->id = $param->iassign_id;
  4254. $newentry->name = $param->name;
  4255. $newentry->type_iassign = $param->type_iassign;
  4256. $newentry->store_all_submissions = $param->store_all_submissions;
  4257. //2019 $newentry->proposition = $param->proposition;
  4258. $proposition = $param->proposition;
  4259. if (is_array($proposition))
  4260. $proposition_text = $proposition['text'];
  4261. else
  4262. $proposition_text = $proposition;
  4263. $newentry->proposition = $proposition_text;
  4264. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4265. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4266. $newentry->grade = $param->grade;
  4267. $newentry->author_modified_name = $param->author_modified_name;
  4268. $newentry->timemodified = time();
  4269. if ($param->type_iassign == 1) {
  4270. $newentry->timedue = 0;
  4271. $newentry->timeavailable = 0;
  4272. } // if ($param->type_iassign == 1)
  4273. else {
  4274. $newentry->timedue = $param->timedue;
  4275. $newentry->timeavailable = $param->timeavailable;
  4276. }
  4277. $newentry->preventlate = $param->preventlate;
  4278. $newentry->test = $param->test;
  4279. if (isset($param->special_param1))
  4280. $newentry->special_param1 = $param->special_param1;
  4281. else
  4282. $newentry->special_param1 = NULL;
  4283. $newentry->visible = $param->visible;
  4284. $newentry->max_experiment = $param->max_experiment;
  4285. $newentry->dependency = $param->dependency;
  4286. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4287. $newentry->show_answer = $param->show_answer;
  4288. if (!$DB->update_record("iassign_statement", $newentry))
  4289. print_error('error_update', 'iassign');
  4290. if ($param->type_iassign == 3) {
  4291. iassign::update_grade_iassign($param->iassignid);
  4292. }
  4293. //$id = $newentry->id; // MOOC 2016 --- inicio
  4294. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4295. //if ($iassign_activity_item_configs) {
  4296. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4297. // $newentry = new stdClass();
  4298. // $newentry->id = $iassign_activity_item_config->id;
  4299. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4300. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4301. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4302. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4303. // print_error('error_edit_param', 'iassign');
  4304. // }
  4305. // } // MOOC 2016 --- final
  4306. // log event --------------------------------------------------------------------------------------
  4307. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4308. // log event --------------------------------------------------------------------------------------
  4309. return $newentry->id;
  4310. // if ($param->type_iassign==3)
  4311. // $this->update_grade_iassign($param->iassignid);
  4312. } // function update_iassign($param)
  4313. /// Show information of activity
  4314. function show_info_iassign () {
  4315. global $DB, $OUTPUT;
  4316. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  4317. if ($this->activity->type_iassign == 3) {
  4318. if ($this->activity->dependency == 0) {
  4319. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  4320. } else {
  4321. $dependencys = explode(';', $this->activity->dependency);
  4322. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  4323. foreach ($dependencys as $dependency) {
  4324. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4325. if ($dependencyiassign)
  4326. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4327. } // foreach ($dependencys as $dependency)
  4328. } // if ($iassign_statement_activity_item->dependency == 0)
  4329. if ($this->activity->max_experiment == 0)
  4330. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4331. else
  4332. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4333. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4334. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4335. print $OUTPUT->box($output);
  4336. } // function show_info_iassign()
  4337. /// Shows date of opening and closing activities
  4338. function view_dates () {
  4339. global $USER, $CFG, $DB, $OUTPUT;
  4340. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4341. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4342. $status_iassign = "";
  4343. $status_iassign1 = "";
  4344. $status_iassign2 = "";
  4345. if ($this->activity->type_iassign == 1) // activity of type example
  4346. $type_iassign = get_string('example_iassign', 'iassign');
  4347. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4348. $type_iassign = get_string('test_iassign', 'iassign');
  4349. if ($this->activity->timeavailable > time()) {
  4350. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4351. } elseif ($this->activity->timedue < time()) {
  4352. $status_iassign = get_string('last_timedue', 'iassign');
  4353. }
  4354. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4355. $type_iassign = get_string('exercise_iassign', 'iassign');
  4356. if ($this->activity->timeavailable > time()) {
  4357. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4358. } elseif ($this->activity->timedue < time()) { // after delivery
  4359. $status_iassign = get_string('last_timedue', 'iassign');
  4360. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4361. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4362. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4363. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4364. if ($this->activity->test == 1) // allowed to test after of deadline
  4365. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4366. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4367. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4368. } // elseif ($iassign_statement_activity_item->test == 0)
  4369. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4370. } // elseif ($iassign_statement_activity_item->timedue < time())
  4371. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4372. $output = '<table width=100% >' . "\n";
  4373. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4374. $output .= '<tr>' . "\n";
  4375. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4376. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4377. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4378. // leo $output .= '<td width=80%>' . $type_iassign;
  4379. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4380. // $output .= '</td>' . "\n";
  4381. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4382. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4383. $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>";
  4384. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4385. } else {
  4386. $link_next = "";
  4387. $link_previous = "";
  4388. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4389. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4390. // previous_activity
  4391. if ($iassign_previous) {
  4392. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4393. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4394. } // next_activity
  4395. if ($iassign_next) {
  4396. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4397. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4398. }
  4399. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4400. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4401. $output .= '</tr></table>' . "\n";
  4402. $output .= '<table width=100% >' . "\n";
  4403. if ($this->activity->type_iassign > 1) {
  4404. if ($this->activity->timeavailable)
  4405. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4406. if ($this->activity->timedue)
  4407. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4408. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4409. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4410. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4411. $output .= '</table>' . "\n";
  4412. print $OUTPUT->box($output);
  4413. } // function view_dates()
  4414. } // class activity
  4415. /// Class to manage Interactive Learning Module (iLM)
  4416. class ilm {
  4417. var $ilm;
  4418. /// Constructor of class
  4419. // @param int $id Id of iLM
  4420. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4421. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4422. function __construct ($id) {
  4423. global $DB;
  4424. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4425. if (empty($this->ilm))
  4426. $this->ilm = null;
  4427. }
  4428. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4429. // @calledby view_iassign_current()
  4430. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4431. global $USER, $CFG, $DB;
  4432. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4433. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4434. $typec = strtolower($iassign_ilm->type);
  4435. require_once 'ilm_handlers/' . $typec . '.php';
  4436. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4437. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4438. return $retorno;
  4439. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4440. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4441. // @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);
  4442. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4443. // @param Object $file File in use in activity
  4444. // @return int Return the id of log
  4445. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4446. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4447. $newentry = new stdClass();
  4448. $newentry->iassign_statementid = $iassign_activity_itemid;
  4449. $newentry->userid = $USER->id;
  4450. $newentry->filesid = $content_or_id_from_ilm_security;
  4451. $newentry->timecreated = time();
  4452. $newentry->view = 1;
  4453. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4454. if (!$id_iLM_security) {
  4455. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4456. } // from (!$DB->insert_record("iassign_security", $newentry))
  4457. return $id_iLM_security;
  4458. }
  4459. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4460. // @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);
  4461. // @param int $userid
  4462. // @param int $iassign_activity_itemid Id of iassign statement
  4463. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4464. global $DB;
  4465. // 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")
  4466. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4467. }
  4468. } // class ilm
  4469. /// Class to manage settings of iLM.
  4470. class ilm_settings {
  4471. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4472. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4473. // @param int $ilm_id Id of iLM
  4474. // @param array $options An array with options for create dynamic tag html APPLET
  4475. // @return string Return with a tag html APPLET created
  4476. static function build_ilm_tags ($ilm_id, $options = array()) {
  4477. global $DB;
  4478. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4479. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4480. $typec = strtolower($iassign_ilm->type);
  4481. require_once 'ilm_handlers/' . $typec . '.php';
  4482. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4483. return $retorno;
  4484. } // static function build_ilm_tags($ilm_id, $options = array())
  4485. /// Function for get modified date of iLM file
  4486. // @param string $file_jar String with Ids of iLM files
  4487. // @return string Return with the filenames and modified date
  4488. static function applet_filetime ($file_jar) {
  4489. $filetime = "";
  4490. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4491. $files_jar = explode(",", $file_jar);
  4492. foreach ($files_jar as $one_file) {
  4493. $file = $fs->get_file_by_id($one_file);
  4494. if ($file)
  4495. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4496. }
  4497. return $filetime;
  4498. }
  4499. /// Function for verify an default applet
  4500. // @param String $file_jar String containing an list de ids of applet files
  4501. // @return boolean Return true or fale if applet is default
  4502. static function applet_default ($file_jar) {
  4503. $is_default = true;
  4504. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4505. $files_jar = explode(",", $file_jar);
  4506. foreach ($files_jar as $one_file) {
  4507. $file = $fs->get_file_by_id($one_file);
  4508. if ($file)
  4509. $is_default &= ($file->get_itemid() == 0);
  4510. }
  4511. return $is_default;
  4512. }
  4513. /// Function for get form variables for add, edit, or copy iLM
  4514. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4515. // @see settings_form.php
  4516. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4517. // @param int $ilm_id Id of iLM
  4518. // @param string $action String with the action
  4519. // @return object Return an object with forms variables
  4520. static function add_edit_copy_ilm ($ilm_id, $action) {
  4521. global $USER, $DB, $CFG;
  4522. require_once('settings_form.php'); // put the form
  4523. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4524. $param = new stdClass();
  4525. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  4526. $param->action = $action;
  4527. $param->ilm_id = $ilm_id;
  4528. $CFG->action_ilm = $action;
  4529. $CFG->ilm_id = $ilm_id;
  4530. if ($action == 'add') {
  4531. $param->title = get_string('add_ilm', 'iassign');
  4532. $param->name = "";
  4533. $param->version = "";
  4534. $param->url = "";
  4535. $param->description = "";
  4536. $param->extension = "";
  4537. $param->author = $USER->id;
  4538. $param->file_jar = "";
  4539. $param->file_jar_static = "";
  4540. $param->file_class = "";
  4541. $param->width = 800;
  4542. $param->height = 600;
  4543. $param->enable = 0; // 0 - hide / 1 - show
  4544. $param->timecreated = time();
  4545. $param->timemodified = time();
  4546. $param->evaluate = 0;
  4547. $param->parent = 0;
  4548. }
  4549. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4550. if ($iassign_ilm) {
  4551. $description = json_decode($iassign_ilm->description);
  4552. $param->title = get_string('edit_ilm', 'iassign');
  4553. $param->id = $iassign_ilm->id;
  4554. $param->name_ilm = $iassign_ilm->name;
  4555. $param->name = $iassign_ilm->name;
  4556. $param->version = $iassign_ilm->version;
  4557. $param->ilm_type = $iassign_ilm->type;
  4558. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4559. $param->url = $iassign_ilm->url; // iLM official URL
  4560. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  4561. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4562. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4563. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4564. if (!isset($description->{current_language()})) {
  4565. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4566. else
  4567. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4568. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4569. }
  4570. else
  4571. $param->description = $description->{current_language()};
  4572. $param->description_lang = $iassign_ilm->description;
  4573. $param->extension = $iassign_ilm->extension;
  4574. $param->author = $iassign_ilm->author;
  4575. $param->file_jar = $iassign_ilm->file_jar;
  4576. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4577. $param->file_class = $iassign_ilm->file_class;
  4578. $param->width = $iassign_ilm->width;
  4579. $param->height = $iassign_ilm->height;
  4580. $param->enable = $iassign_ilm->enable;
  4581. $param->timecreated = $iassign_ilm->timecreated;
  4582. $param->timemodified = time();
  4583. $param->evaluate = $iassign_ilm->evaluate;
  4584. $param->parent = $iassign_ilm->parent;
  4585. }
  4586. }
  4587. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4588. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4589. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4590. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4591. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4592. // echo "Sem dados<br/>"; exit;
  4593. return;
  4594. }
  4595. $description = json_decode($iassign_ilm->description);
  4596. if ($iassign_ilm) {
  4597. if ($iassign_ilm->parent == 0)
  4598. $iassign_ilm->parent = $ilm_id;
  4599. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4600. $param->title = get_string('new_version_ilm', 'iassign');
  4601. $param->name_ilm = $iassign_ilm->name;
  4602. $param->name = $iassign_ilm->name;
  4603. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4604. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4605. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4606. $param->ilm_type = $iassign_ilm->type;
  4607. $param->url = $iassign_ilm->url;
  4608. $param->description = $description->{current_language()};
  4609. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4610. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4611. $param->extension = $iassign_ilm->extension;
  4612. $param->author = $USER->id;
  4613. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4614. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4615. $param->file_jar_static = '';
  4616. $param->file_class = $iassign_ilm->file_class;
  4617. $param->width = $iassign_ilm->width;
  4618. $param->height = $iassign_ilm->height;
  4619. $param->enable = 0;
  4620. $param->timecreated = time();
  4621. $param->timemodified = time();
  4622. $param->evaluate = $iassign_ilm->evaluate;
  4623. $param->parent = $iassign_ilm->parent;
  4624. }
  4625. }
  4626. elseif ($action == 'copy') {
  4627. $description = json_decode($iassign_ilm->description);
  4628. if ($iassign_ilm) {
  4629. if ($iassign_ilm->parent == 0)
  4630. $iassign_ilm->parent = $ilm_id;
  4631. $param->title = get_string('copy_ilm', 'iassign');
  4632. $param->id = $iassign_ilm->id;
  4633. $param->name_ilm = $iassign_ilm->name;
  4634. $param->name = $iassign_ilm->name;
  4635. $param->version = "";
  4636. $param->ilm_type = $iassign_ilm->type;
  4637. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4638. $param->url = $iassign_ilm->url;
  4639. $param->description = $description->{current_language()};
  4640. $param->description_lang = $iassign_ilm->description;
  4641. $param->extension = $iassign_ilm->extension;
  4642. $param->author = $USER->id;
  4643. $param->file_jar = '';
  4644. $param->file_jar_static = '';
  4645. $param->file_class = $iassign_ilm->file_class;
  4646. $param->width = $iassign_ilm->width;
  4647. $param->height = $iassign_ilm->height;
  4648. $param->enable = 0;
  4649. $param->timecreated = time();
  4650. $param->timemodified = time();
  4651. $param->evaluate = $iassign_ilm->evaluate;
  4652. $param->parent = $iassign_ilm->parent;
  4653. }
  4654. }
  4655. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  4656. //D var_dump(debug_backtrace());
  4657. //D print_r(debug_backtrace());
  4658. return $param;
  4659. } // static function add_edit_copy_ilm($ilm_id, $action)
  4660. /// Function for save iLM file in moodledata
  4661. // @param int $itemid Itemid of file save in draft (upload file)
  4662. // @param int $ilm_id Id of iLM
  4663. // @return string Return an string with ids of iLM files
  4664. static function new_file_ilm ($itemid, $iassign_ilm) {
  4665. global $CFG, $USER, $DB;
  4666. $return = null;
  4667. $file_jar = array();
  4668. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4669. $contextuser = context_user::instance($USER->id);
  4670. $contextsystem = context_system::instance();
  4671. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4672. if ($files_ilm) {
  4673. foreach ($files_ilm as $value) {
  4674. // CHECK IF file is HTML type
  4675. if ($iassign_ilm->type == 1) {
  4676. // Check if the file extension is ZIP
  4677. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4678. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4679. if ((strtolower($ext) == 'zip')) {
  4680. // Coping...:
  4681. $destination = 'ilm_debug/' . $value->get_filename();
  4682. $value->copy_content_to($destination);
  4683. // Extracting content...:
  4684. $zip = new ZipArchive();
  4685. $extracted = './ilm';
  4686. $dir = "";
  4687. if ($zip->open($destination) === TRUE) {
  4688. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4689. if (is_dir($dir)) {
  4690. $i = 1;
  4691. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4692. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4693. $i ++;
  4694. }
  4695. $name = $previous . "_" . $i;
  4696. $dir = './ilm/' . $name . "/";
  4697. $j = 0;
  4698. while ($item_name = $zip->getNameIndex($j)) {
  4699. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4700. $j++;
  4701. }
  4702. $zip->close();
  4703. }
  4704. $zip->open($destination);
  4705. $zip->extractTo($extracted);
  4706. $zip->close();
  4707. // After the extraction, remove it from DEBUG
  4708. unlink($destination);
  4709. } else { // Error trying to open destination...
  4710. // After the extraction error, also remove it from DEBUG
  4711. unlink($destination);
  4712. print_error('error_add_ilm_zip', 'iassign');
  4713. }
  4714. return $dir;
  4715. }
  4716. } // if ($iassign_ilm->type == 1)
  4717. if ($value->get_filename() != '.') {
  4718. $file_ilm = array(
  4719. 'userid' => $USER->id,
  4720. 'contextid' => $contextsystem->id,
  4721. 'component' => 'mod_iassign',
  4722. 'filearea' => 'ilm',
  4723. 'itemid' => rand(1, 999999999),
  4724. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4725. 'filename' => $value->get_filename());
  4726. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4727. array_push($file_jar, $file_ilm->get_id());
  4728. }
  4729. }
  4730. if (!empty($file_jar)) {
  4731. $return = implode(",", $file_jar);
  4732. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4733. foreach ($old_file_jar as $value) {
  4734. $file = $fs->get_file_by_id($value);
  4735. if ($file)
  4736. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4737. }
  4738. }
  4739. }
  4740. else // if ($files_ilm)
  4741. $return = $iassign_ilm->file_jar;
  4742. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4743. return $return;
  4744. } // static function new_file_ilm($itemid, $iassign_ilm)
  4745. /// Function for save in database an new iLM
  4746. // @param object $param An object with iLM params
  4747. static function new_ilm ($itemid) {
  4748. global $CFG, $USER, $OUTPUT;
  4749. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4750. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4751. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4752. }
  4753. $pathtemp = $CFG->dataroot . '/temp/';
  4754. $contextuser = context_user::instance($USER->id);
  4755. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4756. $zip = new zip_packer();
  4757. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4758. foreach ($files as $file) {
  4759. if (!$file->is_directory())
  4760. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4761. }
  4762. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4763. // Verifica se o pacote possui o XML
  4764. if (!$application_xml) {
  4765. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4766. return;
  4767. } else {
  4768. $missing = "";
  4769. if (!isset($application_xml->name)) {
  4770. $missing .= "name";
  4771. }
  4772. if (!isset($application_xml->version)) {
  4773. $missing .= ", version";
  4774. }
  4775. if (!isset($application_xml->type)) {
  4776. $missing .= ", type";
  4777. }
  4778. if (!isset($application_xml->extension)) {
  4779. $missing .= ", extension";
  4780. }
  4781. if (!isset($application_xml->file_jar)) {
  4782. $missing .= ", file_jar";
  4783. }
  4784. if (!isset($application_xml->file_class)) {
  4785. $missing .= ", file_class";
  4786. }
  4787. if (!isset($application_xml->width)) {
  4788. $missing .= ", width";
  4789. }
  4790. if (!isset($application_xml->height)) {
  4791. $missing .= ", height";
  4792. }
  4793. if (!isset($application_xml->evaluate)) {
  4794. $missing .= ", evaluate";
  4795. }
  4796. if (strlen($missing) > 2) {
  4797. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4798. return;
  4799. }
  4800. }
  4801. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4802. $typec = strtolower($application_xml->type);
  4803. require_once 'ilm_handlers/' . $typec . '.php';
  4804. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4805. return $retorno;
  4806. } // static function new_ilm($itemid)
  4807. /// Function for save in database an iLM edit
  4808. // @param object $param An object with iLM params
  4809. static function edit_ilm ($param, $itemid) {
  4810. // Descobrir o tipo de iLM:
  4811. global $DB, $USER, $CFG;
  4812. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4813. $pathtemp = $CFG->dataroot . '/temp/';
  4814. $contextuser = context_user::instance($USER->id);
  4815. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4816. $zip = new zip_packer();
  4817. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4818. $files_extract = null;
  4819. foreach ($files as $file) {
  4820. if (!$file->is_directory())
  4821. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4822. }
  4823. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4824. $typec = strtolower($iassign_t->type);
  4825. require_once 'ilm_handlers/' . $typec . '.php';
  4826. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4827. }
  4828. /// Function for register the new iLM (in database and in the directory)
  4829. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4830. // @param object $param An object with iLM params
  4831. static function copy_new_version_ilm ($param) {
  4832. global $DB, $CFG, $USER;
  4833. $itemid = $param->file;
  4834. $pathtemp = $CFG->dataroot . '/temp/';
  4835. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4836. //D echo "pathtemp=$pathtemp<br/>";
  4837. $contextuser = context_user::instance($USER->id);
  4838. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4839. $zip = new zip_packer();
  4840. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4841. $files_extract = null;
  4842. foreach ($files as $file) {
  4843. if (!$file->is_directory())
  4844. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4845. }
  4846. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4847. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4848. $typec = strtolower($iassign_t->type);
  4849. require_once 'ilm_handlers/' . $typec . '.php';
  4850. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4851. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4852. } // static function copy_new_version_ilm($param)
  4853. //VER::
  4854. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4855. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4856. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4857. /// Function for change visibility of iLM
  4858. // @param int $ilm_id Id of iLM
  4859. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4860. static function visible_ilm ($ilm_id, $status) {
  4861. global $DB;
  4862. if ($status == 0)
  4863. $visible = 1;
  4864. else
  4865. $visible = 0;
  4866. $newentry = new stdClass();
  4867. $newentry->id = $ilm_id;
  4868. $newentry->enable = $visible;
  4869. if (!$DB->update_record("iassign_ilm", $newentry))
  4870. error(get_string('error_edit_ilm', 'iassign'));
  4871. }
  4872. /// Function for confirm change default iLM
  4873. // @param int $ilm_id Id of iLM
  4874. // @param int $ilm_parent Id of parent iLM
  4875. // @return string Return with an string for create default page confirmation
  4876. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4877. global $OUTPUT, $DB;
  4878. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4879. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4880. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4881. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4882. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4883. return $return;
  4884. }
  4885. /// Function for change the default iLM
  4886. // @see settings_ilm.php
  4887. // @param int $ilm_id Id of iLM
  4888. // @return int Return Id of default iLM
  4889. static function default_ilm ($ilm_id) {
  4890. global $DB;
  4891. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4892. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4893. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4894. $iassign_ilm_default->id = $iassign_ilm->id;
  4895. $iassign_ilm_default->parent = 0;
  4896. $iassign_ilm->parent = $iassign_ilm_default->id;
  4897. $iassign_ilm->id = 0;
  4898. $iassign_ilm_default->enable = 1;
  4899. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4900. print_error('error_edit_ilm', 'iassign');
  4901. }
  4902. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4903. if (!$inserted) {
  4904. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4905. print_error($msg_error);
  4906. //xx print_error('error_add_ilm', 'iassign');
  4907. }
  4908. return $iassign_ilm_default->id;
  4909. } // static function default_ilm ($ilm_id)
  4910. /// Function for confirm delete iLM
  4911. // @param int $ilm_id Id of iLM
  4912. // @param int $ilm_parent Id of parent iLM
  4913. // @return string Return with an string for create delete page confirmation
  4914. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4915. global $OUTPUT, $DB;
  4916. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4917. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4918. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4919. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4920. }
  4921. /// Function for delete directory where the iLM is allocated.
  4922. // @param string $dirPath
  4923. // @throws InvalidArgumentException
  4924. public static function delete_dir ($dirPath) {
  4925. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4926. $dirPath .= '/';
  4927. }
  4928. $files = glob($dirPath . '*', GLOB_MARK);
  4929. foreach ($files as $file) {
  4930. if (is_dir($file)) {
  4931. ilm_settings::delete_dir($file);
  4932. } else {
  4933. unlink($file);
  4934. }
  4935. }
  4936. rmdir($dirPath);
  4937. }
  4938. /// Function for delete iLM
  4939. // @param int $ilm_id Id of iLM
  4940. // @return int Return Id of parent iLM
  4941. static function delete_ilm ($ilm_id) {
  4942. global $DB;
  4943. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4944. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4945. $typec = strtolower($iassign_ilm->type);
  4946. require_once 'ilm_handlers/' . $typec . '.php';
  4947. $retorno = $typec::delete_ilm($ilm_id);
  4948. return $retorno;
  4949. }
  4950. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4951. // @param int $ilm_id Id of iLM
  4952. static function export_ilm ($ilm_id) {
  4953. global $DB;
  4954. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4955. if (!$iassign_ilm) return; // security debug...
  4956. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4957. $typec = strtolower($iassign_ilm->type);
  4958. if (!$typec) $typec = "html5"; // security debug...
  4959. require_once 'ilm_handlers/' . $typec . '.php';
  4960. $typec::export_ilm($ilm_id);
  4961. } // static function export_ilm($ilm_id)
  4962. //TODO iLM_HTML5 :: //MOOC 2016
  4963. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4964. // @param int $ilm_id Id of iLM
  4965. static function export_update_ilm ($ilm_id) {
  4966. global $DB, $CFG;
  4967. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4968. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4969. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4970. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4971. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4972. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4973. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4974. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4975. $upgrade_descriptor .= '</upgrade>' . "\n";
  4976. file_put_contents($xml_filename, $upgrade_descriptor);
  4977. header("Pragma: public");
  4978. header("Expires: 0");
  4979. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4980. header("Cache-Control: private", false);
  4981. header('Content-Type: application/xml; charset=utf-8');
  4982. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4983. header("Content-Length: " . @filesize($xml_filename));
  4984. set_time_limit(0);
  4985. @readfile("$xml_filename") || die("File not found.");
  4986. unlink($xml_filename);
  4987. exit;
  4988. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4989. /// Function for save iLM from XML descriptor
  4990. // @param array $application_xml Data of XML descriptor
  4991. // @param array $files_extract Filenames of extract files
  4992. // @return array Return an array content id of JAR files
  4993. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4994. global $CFG, $USER;
  4995. // Tratamento diferenciado se for do tipo HTML5:
  4996. $source = "";
  4997. $diretorio = "";
  4998. if (strtolower($application_xml->type) == 'html5') {
  4999. $i = 0;
  5000. foreach ($files_extract as $key => $value) {
  5001. $file = $CFG->dataroot . '/temp/' . $key;
  5002. // Verifica se já existe a pasta no diretório dos iLM:
  5003. if ($i == 0) {
  5004. $source = $file;
  5005. if (file_exists("ilm/" . basename($file))) {
  5006. $j = 1;
  5007. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5008. $j ++;
  5009. }
  5010. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5011. // mkdir($diretorio, 0777, true);
  5012. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5013. }
  5014. else {
  5015. $diretorio = 'ilm/' . basename($file);
  5016. // mkdir($diretorio, 0777, true);
  5017. mkdir($diretorio, 0755, true);
  5018. }
  5019. break;
  5020. }
  5021. $i ++;
  5022. }
  5023. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5024. if ($item->isDir()) {
  5025. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5026. }
  5027. else {
  5028. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5029. }
  5030. }
  5031. ilm_settings::delete_dir($source);
  5032. return "./" . $diretorio;
  5033. }
  5034. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5035. $file_jar = array();
  5036. $files_ilm = explode(",", $application_xml->file_jar);
  5037. $contextsystem = context_system::instance();
  5038. foreach ($files_ilm as $value) {
  5039. $file_ilm = array(
  5040. 'userid' => $USER->id,
  5041. 'contextid' => $contextsystem->id,
  5042. 'component' => 'mod_iassign',
  5043. 'filearea' => 'ilm',
  5044. 'itemid' => rand(1, 999999999),
  5045. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5046. 'filename' => $value);
  5047. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5048. array_push($file_jar, $file_ilm->get_id());
  5049. }
  5050. foreach ($files_extract as $key => $value) {
  5051. $file = $CFG->dataroot . '/temp/' . $key;
  5052. if (file_exists($file))
  5053. unlink($file);
  5054. }
  5055. return $file_jar;
  5056. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5057. /// Function for import the iLM from an package
  5058. // @param int $itemid Itemid of zip file
  5059. static function import_ilm ($itemid) {
  5060. global $CFG, $USER, $OUTPUT;
  5061. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5062. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5063. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5064. }
  5065. $pathtemp = $CFG->dataroot . '/temp/';
  5066. $contextuser = context_user::instance($USER->id);
  5067. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5068. $zip = new zip_packer();
  5069. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5070. foreach ($files as $file) {
  5071. if (!$file->is_directory())
  5072. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5073. }
  5074. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5075. // Verifica se o pacote possui o XML
  5076. if (!$application_xml) {
  5077. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5078. return;
  5079. } else {
  5080. $missing = "";
  5081. if (!isset($application_xml->name)) {
  5082. $missing .= "name";
  5083. }
  5084. if (!isset($application_xml->version)) {
  5085. $missing .= ", version";
  5086. }
  5087. if (!isset($application_xml->type)) {
  5088. $missing .= ", type";
  5089. }
  5090. if (!isset($application_xml->extension)) {
  5091. $missing .= ", extension";
  5092. }
  5093. if (!isset($application_xml->file_jar)) {
  5094. $missing .= ", file_jar";
  5095. }
  5096. if (!isset($application_xml->file_class)) {
  5097. $missing .= ", file_class";
  5098. }
  5099. if (!isset($application_xml->width)) {
  5100. $missing .= ", width";
  5101. }
  5102. if (!isset($application_xml->height)) {
  5103. $missing .= ", height";
  5104. }
  5105. if (!isset($application_xml->evaluate)) {
  5106. $missing .= ", evaluate";
  5107. }
  5108. if (strlen($missing) > 2) {
  5109. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5110. return;
  5111. }
  5112. }
  5113. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5114. $typec = strtolower($application_xml->type);
  5115. require_once 'ilm_handlers/' . $typec . '.php';
  5116. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5117. } // static function import_ilm($itemid)
  5118. /// Function for list iLM defaults
  5119. // @return string Return an string with a table of iLM
  5120. static function list_ilm () {
  5121. global $DB, $OUTPUT;
  5122. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5123. $str = '';
  5124. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5125. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5126. if ($iassign_ilm) {
  5127. foreach ($iassign_ilm as $ilm) {
  5128. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5129. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5130. $str .= '<tr><td>';
  5131. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5132. $str .= '<tr>';
  5133. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5134. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5135. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5136. $str .= '</tr>';
  5137. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5138. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5139. $str .= '</table>';
  5140. $str .= '</td></tr>';
  5141. }
  5142. }
  5143. $str .= '</table>';
  5144. return $str;
  5145. }
  5146. /// Function for download and install an upgrade of an iLM
  5147. // @param int $ilm_id Id of iLM
  5148. static function upgrade_ilm ($ilm_id) {
  5149. global $DB, $CFG, $USER;
  5150. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5151. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5152. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5153. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5154. if (!$result)
  5155. print_error('error_upgrade_ilm', 'iassign');
  5156. else {
  5157. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5158. $extension = explode(".", $zip_filename);
  5159. if ($extension[count($extension) - 1] != 'ipz') {
  5160. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5161. die;
  5162. }
  5163. $zip = new zip_packer();
  5164. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5165. $contextuser = context_user::instance($USER->id);
  5166. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5167. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5168. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5169. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5170. if (file_exists($zip_filename))
  5171. unlink($zip_filename);
  5172. if (empty($file_jar)) {
  5173. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5174. print_error($msg_error);
  5175. //xx print_error('error_add_ilm', 'iassign');
  5176. }
  5177. else {
  5178. $newentry = new stdClass();
  5179. $newentry->name = (String) $application_xml->name;
  5180. $newentry->version = (String) $application_xml->version;
  5181. $newentry->url = (String) $application_xml->url;
  5182. $newentry->description = $description_str;
  5183. $newentry->extension = strtolower((String) $application_xml->extension);
  5184. $newentry->file_jar = implode(",", $file_jar);
  5185. $newentry->file_class = (String) $application_xml->file_class;
  5186. $newentry->width = (String) $application_xml->width;
  5187. $newentry->height = (String) $application_xml->height;
  5188. $newentry->enable = 0;
  5189. $newentry->timemodified = time();
  5190. $newentry->author = $USER->id;
  5191. $newentry->timecreated = time();
  5192. $newentry->evaluate = (String) $application_xml->evaluate;
  5193. $newentry->parent = $ilm_id;
  5194. }
  5195. }
  5196. return $iassign_ilm->id;
  5197. } // static function upgrade_ilm($ilm_id)
  5198. //MOOC2014 -- inicio
  5199. //TODO: REVIEW
  5200. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5201. // static function move_iassign($ilm_id)
  5202. //MOOC2014 -- final
  5203. /// Function for list iLM versions with all informations
  5204. // @return string Return an string with a table of iLM
  5205. static function view_ilm ($ilmid, $from) {
  5206. global $DB;
  5207. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5208. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5209. $typec = strtolower($iassign_ilm->type);
  5210. require_once 'ilm_handlers/' . $typec . '.php';
  5211. $retorno = $typec::view_ilm($ilmid, $from);
  5212. return $retorno;
  5213. }
  5214. /// Function for get form variables for add, edit, or copy iLM params
  5215. // @param int $ilm_param_id Id of iLM param
  5216. // @param string $action String with the action
  5217. // @return object Return an object with forms variables
  5218. static function add_edit_copy_param ($ilm_param_id, $action) {
  5219. global $DB;
  5220. require_once('params_form.php');
  5221. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5222. $param = new stdClass();
  5223. $param->action = $action;
  5224. $param->ilm_param_id = $ilm_param_id;
  5225. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5226. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5227. $type = $iassign_ilm_config->param_type;
  5228. if ($action == 'add') {
  5229. $param->title = get_string('add_ilm', 'iassign');
  5230. $param->iassign_ilmid = $ilm_param_id;
  5231. $param->param_name = "";
  5232. $param->param_value = "";
  5233. $param->description = "";
  5234. $param->visible = 1;
  5235. }
  5236. elseif ($action == 'edit') {
  5237. if ($iassign_ilm_config) {
  5238. $param->title = get_string('edit_ilm', 'iassign');
  5239. $param->id = $iassign_ilm_config->id;
  5240. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5241. $param->param_type = $type; //MOOC2014
  5242. $param->param_name = $iassign_ilm_config->param_name;
  5243. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5244. $param->param_value = $iassign_ilm_config->param_value;
  5245. else //MOOC2014
  5246. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5247. $param->param_value = $iassign_ilm_config->param_value;
  5248. $param->description = $iassign_ilm_config->description;
  5249. $param->visible = $iassign_ilm_config->visible;
  5250. }
  5251. }
  5252. elseif ($action == 'copy') {
  5253. if ($iassign_ilm_config) {
  5254. $param->title = get_string('copy_ilm', 'iassign');
  5255. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5256. $param->param_type = $type; //MOOC2014
  5257. $param->param_name = $iassign_ilm_config->param_name;
  5258. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5259. $param->param_value = $iassign_ilm_config->param_value;
  5260. else //MOOC2014
  5261. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5262. $param->description = $iassign_ilm_config->description;
  5263. $param->visible = $iassign_ilm_config->visible;
  5264. }
  5265. }
  5266. return $param;
  5267. } // static function add_edit_copy_param($ilm_param_id, $action)
  5268. /// Function for change visibility of iLM param
  5269. // @param int $ilm_param_id Id of iLM param
  5270. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5271. static function visible_param ($ilm_param_id, $status) {
  5272. global $DB, $CFG;
  5273. if ($status == 0)
  5274. $visible = 1;
  5275. else
  5276. $visible = 0;
  5277. $newentry = new stdClass();
  5278. $newentry->id = $ilm_param_id;
  5279. $newentry->visible = $visible;
  5280. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5281. error(get_string('error_edit_param', 'iassign'));
  5282. }
  5283. /// Function for save in database an new iLM param
  5284. // @param object $param An object with iLM params
  5285. static function add_param ($param) {
  5286. global $DB;
  5287. $newentry = new stdClass();
  5288. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5289. //MOOC2014 $newentry->param_name = $param->param_name;
  5290. $newentry->param_type = $param->param_type; //MOOC2014
  5291. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5292. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5293. $newentry->param_value = $param->param_value;
  5294. else //MOOC2014
  5295. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5296. $newentry->description = $param->description;
  5297. $newentry->visible = $param->visible;
  5298. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5299. if (!$newentry->id) {
  5300. print_error('error_add_param', 'iassign');
  5301. }
  5302. }
  5303. /// Function for save in database a iLM param edit
  5304. // @param object $param An object with iLM params
  5305. static function edit_param ($param) {
  5306. global $DB;
  5307. $updentry = new stdClass();
  5308. $updentry->id = $param->id;
  5309. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5310. $updentry->param_type = $param->param_type; //MOOC2014
  5311. // $updentry->param_name = $param->param_name;
  5312. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5313. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5314. $updentry->param_value = $param->param_value;
  5315. else //MOOC2014
  5316. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5317. $updentry->description = $param->description;
  5318. $updentry->visible = $param->visible;
  5319. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5320. error(get_string('error_edit_param', 'iassign'));
  5321. }
  5322. }
  5323. /// Function for save in database a iLM param copy
  5324. // @param object $param An object with iLM params
  5325. static function copy_param ($param) {
  5326. global $DB;
  5327. $newentry = new stdClass();
  5328. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5329. //$newentry->param_name = $param->param_name;
  5330. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5331. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5332. $newentry->param_value = $param->param_value;
  5333. else //MOOC2014
  5334. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5335. $newentry->description = $param->description;
  5336. $newentry->visible = $param->visible;
  5337. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5338. if (!$newentry->id) {
  5339. print_error('error_add_param', 'iassign');
  5340. }
  5341. }
  5342. /// Function for delete iLM param of database
  5343. // @param int $param_id Id of iLM param
  5344. static function delete_param ($param_id) {
  5345. global $DB;
  5346. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5347. print_error('error_delete_param', 'iassign');
  5348. }
  5349. }
  5350. } // class ilm_settings
  5351. /// Class for manage iLM files (editor).
  5352. class ilm_manager {
  5353. var $id; // course id
  5354. var $url;
  5355. var $from;
  5356. /// Constructor for the base ilm_manager class
  5357. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5358. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5359. function __construct ($id, $url, $from) {
  5360. $this->id = $id; // course id
  5361. $this->url = $url;
  5362. $this->from = $from;
  5363. }
  5364. /// Function to get iAssign content file in Moodle data (exercise)
  5365. // @calledby x function preview_ilm($iassign_ilm) :
  5366. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5367. function get_file_ilm () {
  5368. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5369. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5370. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5371. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5372. $md_file = $fs->get_file_by_id($fileid);
  5373. $ilm_content_file = $md_file->get_content();
  5374. return $ilm_content_file;
  5375. }
  5376. /// Function for creating a new file from the iLM online editor
  5377. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5378. function ilm_editor_new () {
  5379. global $CFG, $DB, $OUTPUT, $PAGE;
  5380. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5381. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5382. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5383. $context = context_course::instance($this->id);
  5384. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5385. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5386. if (!$iassign) {
  5387. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5388. die();
  5389. }
  5390. $temp = explode(",", $iassign->extension);
  5391. $extension = $temp[0]; // default extension for this iLM
  5392. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5393. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5394. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5395. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5396. if ($stringArchiveContent != NULL) {
  5397. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5398. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5399. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5400. $filename = optional_param('filename', NULL, PARAM_RAW);
  5401. //Leo $filename = iassign_utils::format_filename($filename); //
  5402. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5403. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5404. //2019/02 $arrayfilename = explode(".", $filename);
  5405. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5406. //2019/02 $count_dots = count($arrayfilename);
  5407. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5408. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5409. //2019/02 if ($last_name != $extension)
  5410. //2019/02 $filename = $filename . '.' . $extension;
  5411. //2019/02 }
  5412. //2019/02 else { // no extension...
  5413. //2019/02 $filename = $filename . '.' . $extension;
  5414. //2019/02 }
  5415. // Store the name of recent created file
  5416. $_SESSION['file_name'] = $filename;
  5417. //$this->write_file_iassign($string, $filename);
  5418. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5419. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5420. die();
  5421. }
  5422. else { // if ($stringArchiveContent != NULL)
  5423. // iLM On-line editor
  5424. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5425. $str_get_iLM = "window.frames.iLM";
  5426. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5427. }
  5428. else { // otherwise it is JAR named 'iLM'
  5429. $str_get_iLM = "document.iLM";
  5430. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5431. }
  5432. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5433. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5434. $files_array = '';
  5435. foreach ($files as $value) {
  5436. if ($value->get_filename() != ".")
  5437. $files_array .= "'" . $value->get_filename() . "',";
  5438. }
  5439. $files_array .= "''";
  5440. $file = null;
  5441. $ia_content = "";
  5442. $filename = "";
  5443. $error_files_exists = get_string('error_file_exists', 'iassign');
  5444. $output = "<script type='text/javascript'>
  5445. //<![CDATA[
  5446. //D alert('locallib.php: ilm_editor_new');
  5447. function submit_iLM_Answer () {
  5448. var docFormOnLineEditor = document.formEnvio;
  5449. var resposta_exerc = new Array(3);
  5450. var valor_resposta = new Array(3);
  5451. var sessao = new Array(3);
  5452. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5453. resposta_exerc[0] = doc_iLM.getAnswer();
  5454. valor_resposta[0] = doc_iLM.getEvaluation();
  5455. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5456. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5457. var files = new Array(" . $files_array . ");
  5458. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5459. if (docFormOnLineEditor.filename.value=='') {
  5460. // ERROR: the file name is empty
  5461. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5462. return false;
  5463. }
  5464. // }
  5465. for (i=0; i<files.length; i++) {
  5466. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5467. alert('" . $error_files_exists . "');
  5468. return false;
  5469. }
  5470. }
  5471. docFormOnLineEditor.submit();
  5472. return true;
  5473. }
  5474. //]]>
  5475. </script>\n";
  5476. $output .= "
  5477. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5478. $output .= $OUTPUT->box_start();
  5479. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5480. $output .= "
  5481. <table width='100%' cellpadding='20'>
  5482. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5483. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5484. </tr>
  5485. </table>\n";
  5486. $output .= $OUTPUT->box_end();
  5487. $output .= "<center>\n";
  5488. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5489. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5490. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5491. $output .= $output_ilm;
  5492. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5493. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5494. </center>
  5495. </form>\n";
  5496. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5497. $PAGE->navbar->add($title);
  5498. $PAGE->set_title($title);
  5499. $PAGE->set_heading($title); // insert title above the navigation bar
  5500. print $OUTPUT->header();
  5501. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5502. print $output;
  5503. print $OUTPUT->footer();
  5504. }
  5505. die();
  5506. } // function ilm_editor_new()
  5507. /// Function for editing an file in online editor
  5508. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5509. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5510. global $CFG, $DB, $OUTPUT, $PAGE;
  5511. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5512. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5513. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5514. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5515. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5516. // If iLM is not registered, error!
  5517. if (!$iassign) {
  5518. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5519. die;
  5520. }
  5521. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5522. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5523. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5524. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5525. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5526. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5527. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5528. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5529. if ($stringArchiveContent != NULL) {
  5530. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5531. die();
  5532. } else { // if ($stringArchiveContent != NULL)
  5533. $end_file = '';
  5534. if ($content_file) {
  5535. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5536. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5537. }
  5538. $temp = explode(",", $iassign->extension);
  5539. $extension = $temp[0]; // default extension for this iLM
  5540. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5541. $str_get_iLM = "window.frames.iLM";
  5542. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5543. } else { // otherwise it is JAR named 'iLM'
  5544. $str_get_iLM = "document.iLM";
  5545. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5546. }
  5547. $output = "<script type='text/javascript'>
  5548. //<![CDATA[
  5549. function submit_iLM_Answer () {
  5550. var docFormEditor = document.formEnvio;
  5551. var activityAnswer; // to get activity answer (text)
  5552. var activityValue; // to get activity answer value (float)
  5553. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5554. //activityAnswer = doc_iLM.getAnswer();
  5555. //activityValue = doc_iLM.getEvaluation();
  5556. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5557. activityValue = " . $str_get_iLM . ".getEvaluation();
  5558. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5559. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5560. docFormEditor.submit();
  5561. return true;
  5562. }
  5563. //]]>
  5564. </script>\n";
  5565. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5566. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5567. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5568. // return true;
  5569. // }
  5570. $output .= "
  5571. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5572. $output .= $OUTPUT->box_start();
  5573. $output .= "
  5574. <table width='100%' cellpadding='20'>
  5575. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5576. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5577. <input type='hidden' name='filename' value='$filename'/></td>
  5578. <td>
  5579. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5580. </tr>
  5581. </table>\n";
  5582. $output .= $OUTPUT->box_end();
  5583. $output .= " <center>\n";
  5584. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5585. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5586. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5587. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5588. </center>
  5589. </form>\n";
  5590. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5591. $PAGE->navbar->add($title);
  5592. $PAGE->set_title($title);
  5593. $PAGE->set_heading($title); // insert title above the navigation bar
  5594. print $OUTPUT->header();
  5595. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5596. print $output;
  5597. print $OUTPUT->footer();
  5598. } // else if ($stringArchiveContent != NULL)
  5599. die();
  5600. } // function ilm_editor_update()
  5601. /// Function for write iAssign file in Moodle data (exercise)
  5602. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5603. // @param string $stringArchiveContent Content of iassign file
  5604. // @param string $filename Filename of iassign file
  5605. function write_file_iassign ($stringArchiveContent, $filename) {
  5606. global $USER;
  5607. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5608. $context = context_course::instance($this->id);
  5609. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5610. $dirid = $this->get_dir_ilm('dirid');
  5611. $dir = $fs->get_file_by_id($dirid);
  5612. $fileinfo = array('contextid' => $context->id, // ID of course
  5613. 'component' => 'mod_iassign', // usually = table name
  5614. 'filearea' => 'activity', // usually = table name
  5615. 'itemid' => 0, // usually = ID of row in table
  5616. 'filepath' => '/', // any path beginning and ending whith '/'
  5617. 'userid' => $USER->id,
  5618. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5619. 'filename' => $filename); // any filename
  5620. // Create file containing text. '$stringArchiveContent'
  5621. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5622. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5623. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5624. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5625. // 'Activité interactive enregistrée avec succès sous le nom:';
  5626. // 'Atividade interativa gravada com sucesso sob o nome:'
  5627. $output = "
  5628. <script type='text/javascript'>
  5629. //<![CDATA[
  5630. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5631. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5632. //]]>
  5633. </script>";
  5634. print $output;
  5635. die();
  5636. }
  5637. /// Function for write iAssign file in Moodle data (exercise)
  5638. // @param string $stringArchiveContent Content of iassign file
  5639. // @param string $filename Filename of iassign file
  5640. // @param int $itemid Itemid of iassign file
  5641. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5642. global $OUTPUT, $USER;
  5643. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5644. $context = context_course::instance($this->id);
  5645. $dirid = $this->get_dir_ilm('dirid');
  5646. if ($stringArchiveContent != (-1)) {
  5647. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5648. $file = $fs->get_file_by_id($fileid);
  5649. if (!$file) {
  5650. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5651. die;
  5652. }
  5653. $fileinfo = array('contextid' => $context->id, // ID of context
  5654. 'component' => 'mod_iassign', // usually = table name
  5655. 'filearea' => 'activity', // usually = table name
  5656. 'itemid' => 0, // usually = ID of row in table
  5657. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5658. 'userid' => $USER->id,
  5659. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5660. 'license' => 'allrightsreserved', // allrightsreserved
  5661. 'timecreated' => $file->get_timecreated(),
  5662. 'filename' => $file->get_filename()); // any filename
  5663. $file->delete();
  5664. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5665. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5666. }
  5667. $output = "<script type='text/javascript'>
  5668. //<![CDATA[
  5669. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5670. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5671. //]]>
  5672. </script>";
  5673. print $output;
  5674. die();
  5675. }
  5676. /// Function for create an tag for iAssign filter
  5677. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5678. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5679. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5680. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5681. // @param int $fileid Id of file
  5682. // @return string Return an string with an tag of iassign filter
  5683. function tag_ilm ($fileid) {
  5684. global $DB;
  5685. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5686. $width = '600';
  5687. $height = '400';
  5688. $file = $fs->get_file_by_id($fileid);
  5689. $filetype = explode(".", $file->get_filename());
  5690. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5691. foreach ($iassign_ilm as $value) {
  5692. $extensions = explode(",", $value->extension);
  5693. if (in_array($filetype[1], $extensions)) {
  5694. $width = $value->width;
  5695. $height = $value->height;
  5696. }
  5697. }
  5698. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5699. }
  5700. /// Function for delete iAssign file in Moodle data (exercise)
  5701. function delete_file_ilm () {
  5702. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5703. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5704. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5705. $file = $fs->get_file_by_id($fileid);
  5706. if ($file)
  5707. $file->delete();
  5708. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5709. die();
  5710. }
  5711. /// Function for delete selected iAssign file in Moodle data (exercise)
  5712. function delete_selected_ilm () {
  5713. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5714. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5715. $context = context_course::instance($this->id);
  5716. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5717. $dirid = $this->get_dir_ilm('dirid');
  5718. foreach ($files_id as $file_id) {
  5719. $file = $fs->get_file_by_id($file_id);
  5720. if ($file) {
  5721. if (!$file->is_directory())
  5722. $file->delete();
  5723. else {
  5724. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5725. foreach ($files_delete as $value)
  5726. $value->delete();
  5727. $file->delete();
  5728. }
  5729. }
  5730. }
  5731. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5732. die();
  5733. }
  5734. /// Function for duplicate iAssign file from "online" edition
  5735. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5736. function duplicate_file_ilm () {
  5737. global $USER, $COURSE;
  5738. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5739. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5740. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5741. $filename = optional_param('filename', NULL, PARAM_RAW);
  5742. $file = $fs->get_file_by_id($fileid);
  5743. $context = context_course::instance($this->id);
  5744. $fileinfo = array(
  5745. 'contextid' => $context->id, // ID of context
  5746. 'component' => 'mod_iassign', // usually = table name
  5747. 'filearea' => 'activity', // usually = table name
  5748. 'itemid' => 0, // usually = ID of row in table
  5749. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5750. 'userid' => $USER->id,
  5751. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5752. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5753. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5754. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5755. die();
  5756. }
  5757. /// Function for rename iAssign file
  5758. function rename_file_ilm () {
  5759. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5760. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5761. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5762. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5763. $file = $fs->get_file_by_id($fileid);
  5764. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5765. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5766. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5767. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5768. die();
  5769. }
  5770. /// Function for get iassign file for iassign form
  5771. function add_ilm () {
  5772. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5773. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5774. $output = "
  5775. <script type='text/javascript'>
  5776. //<![CDATA[
  5777. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5778. iassign_file_link.innerHTML = '$filename';
  5779. window.opener.document.forms['mform1'].file.value='$fileid';
  5780. window.opener.document.forms['mform1'].filename.value='$filename';
  5781. window.close();
  5782. //]]>
  5783. </script>";
  5784. print $output;
  5785. die();
  5786. }
  5787. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5788. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5789. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5790. function preview_ilm ($courseid, $iassign_ilm) {
  5791. global $OUTPUT, $CFG, $USER;
  5792. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5793. $title = get_string('modulename', 'iassign'); // iAssign
  5794. print $OUTPUT->header();
  5795. print $OUTPUT->box_start();
  5796. $javascript = "
  5797. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5798. <script type='text/javascript'>
  5799. //<![CDATA[
  5800. function submit_close () {
  5801. window.opener.location.reload();
  5802. window.close();
  5803. }
  5804. //]]>
  5805. </script>\n";
  5806. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5807. // to the complete "applet" tag
  5808. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5809. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5810. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5811. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5812. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5813. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5814. if ($ilm_name != "ivprog") {
  5815. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5816. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5817. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5818. } else {
  5819. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5820. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5821. $timecreated = time();
  5822. $token = md5($timecreated);
  5823. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5824. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5825. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5826. $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)
  5827. }
  5828. $html = "
  5829. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5830. <table border='1'>
  5831. <tr><td>
  5832. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5833. <!-- iLM calls : end -->
  5834. </td></tr>
  5835. </table>
  5836. <table>
  5837. <tr>
  5838. <td align='center'>
  5839. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5840. </td></tr>
  5841. </table>
  5842. </form>\n";
  5843. print $javascript . $html;
  5844. print $OUTPUT->box_end();
  5845. //NAO echo format_string($html); // Moodle 3.X
  5846. die();
  5847. } // function preview_ilm($courseid, $iassign_ilm)
  5848. //r_ function preview_ilm ($iassign_ilm)
  5849. //r_ /// Function for preview iassign file from iassign filter.
  5850. //r_ function preview_ilm() {
  5851. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5852. //r_ $tag_filter = $this->tag_ilm($fileid);
  5853. //r_ $javascript = "<script type='text/javascript'>
  5854. //r_ //<![CDATA[
  5855. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5856. //r_ //]]>
  5857. //r_ </script>";
  5858. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5859. //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>
  5860. //r_ </table></form></body></html>";
  5861. //r_ echo $javascript . format_text($html);
  5862. //r_ die;
  5863. //r_ }
  5864. /// Function for export an package (zip) of iassign files
  5865. function export_files_ilm () {
  5866. global $CFG;
  5867. $context = context_course::instance($this->id);
  5868. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5869. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5870. $zip = new zip_archive();
  5871. $zip->open($zip_filename);
  5872. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5873. foreach ($files_id as $file_id) {
  5874. $file = $fs->get_file_by_id($file_id);
  5875. if (!$file->is_directory())
  5876. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5877. else {
  5878. $zip->add_directory($file->get_filepath());
  5879. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5880. foreach ($files_zip as $value) {
  5881. if (!$value->is_directory())
  5882. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5883. else
  5884. $zip->add_directory($value->get_filepath());
  5885. }
  5886. }
  5887. }
  5888. $zip->close();
  5889. header("Pragma: public");
  5890. header("Expires: 0");
  5891. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5892. header("Cache-Control: private", false);
  5893. header("Content-Type: application/zip");
  5894. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5895. header("Content-Transfer-Encoding: binary");
  5896. header("Content-Length: " . @filesize($zip_filename));
  5897. set_time_limit(0);
  5898. @readfile("$zip_filename") || die("File not found.");
  5899. unlink($zip_filename);
  5900. exit;
  5901. }
  5902. /// Function of execute a command in button editor tinymce
  5903. // @param int $fileid Id of file
  5904. function tinymce_ilm ($fileid) {
  5905. $tag_filter = $this->tag_ilm($fileid);
  5906. $output = "<script type='text/javascript'>
  5907. //<![CDATA[
  5908. var tag_filter = '$tag_filter';
  5909. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5910. // all right, insert it
  5911. } else {
  5912. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5913. }
  5914. // window.close();
  5915. //]]>
  5916. </script>\n";
  5917. print $output;
  5918. die();
  5919. }
  5920. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5921. /// Function to add content to the Editor Window
  5922. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5923. // @param int $fileid Id of file
  5924. function editor_ilm ($fileid, $editor) {
  5925. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5926. $output1 = "<script type='text/javascript'>
  5927. //<![CDATA[
  5928. var tag_filter = '$tag_filter';\n";
  5929. if ($editor == 'atto') {
  5930. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5931. } elseif ($editor == 'tinyMCE') {
  5932. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5933. } else
  5934. $output2 = "";
  5935. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5936. window.close();
  5937. //]]>
  5938. </script>\n";
  5939. //D var_dump($output);
  5940. print $output1 . $output2 . $output3;
  5941. die();
  5942. }
  5943. /// Function to add content to the Atto Editor Window
  5944. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5945. // @param int $fileid Id of file
  5946. function atto_ilm ($fileid) {
  5947. global $CFG, $DB;
  5948. $tag_filter = $this->tag_ilm($fileid);
  5949. $output = "<script type='text/javascript'>
  5950. //<![CDATA[
  5951. var tag_filter = '$tag_filter';
  5952. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5953. // all right, insert iLM tag to this editor
  5954. } else {
  5955. // error trying to insert
  5956. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5957. }
  5958. //window.close();
  5959. //]]>
  5960. </script>\n";
  5961. print $output;
  5962. die();
  5963. }
  5964. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5965. // @param string $key Key for return information
  5966. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5967. function get_dir_ilm ($key) {
  5968. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5969. $context = context_course::instance($this->id);
  5970. $dirid = optional_param('dirid', 0, PARAM_INT);
  5971. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5972. if ($dirid == 0) {
  5973. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5974. $dirid = $dir->get_id();
  5975. }
  5976. else {
  5977. $dir = $fs->get_file_by_id($dirid);
  5978. $dir_base = $dir->get_filepath();
  5979. }
  5980. $dir_parent = $dir->get_parent_directory();
  5981. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5982. return $data[$key];
  5983. }
  5984. /// Function for create an new dir
  5985. function new_dir_ilm () {
  5986. global $USER;
  5987. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5988. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5989. $dir_base = $this->get_dir_ilm('dir_base');
  5990. $context = context_course::instance($this->id);
  5991. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5992. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5993. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5994. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5995. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5996. }
  5997. /// Function for delete an dir
  5998. function delete_dir_ilm () { //
  5999. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6000. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6001. $context = context_course::instance($this->id);
  6002. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6003. $dir_parent = $this->get_dir_ilm('dir_parent');
  6004. if ($dir) {
  6005. if ($dir->is_directory()) {
  6006. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6007. foreach ($files_delete as $value)
  6008. $value->delete();
  6009. $dir->delete();
  6010. }
  6011. }
  6012. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6013. die();
  6014. }
  6015. /// Function for rename an dir
  6016. function rename_dir_ilm () {
  6017. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6018. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6019. $context = context_course::instance($this->id);
  6020. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6021. $dir_parent = $this->get_dir_ilm('dir_parent');
  6022. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6023. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6024. if ($dir->is_directory()) {
  6025. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6026. foreach ($files_rename_path as $value)
  6027. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6028. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6029. }
  6030. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6031. die();
  6032. }
  6033. /// Function for move an dir and your content for other dir
  6034. function selected_move_ilm () {
  6035. global $PAGE, $OUTPUT, $CFG;
  6036. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6037. $context = context_course::instance($this->id);
  6038. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6039. $dirid = $this->get_dir_ilm('dirid');
  6040. $dir_base = $this->get_dir_ilm('dir_base');
  6041. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6042. $code_javascript_ilm = "
  6043. <script type='text/javascript'>
  6044. //<![CDATA[
  6045. function getRadiobutton () {
  6046. var radioButtons = document.getElementsByTagName('input');
  6047. var param = '';
  6048. for (var counter=0; counter < radioButtons.length; counter++) {
  6049. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6050. param = radioButtons[counter].value;
  6051. }
  6052. return param;
  6053. }
  6054. function move_selected_ilm () {
  6055. var msgAnswer;
  6056. if (getRadiobutton() != '') {
  6057. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6058. if (msgAnswer)
  6059. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6060. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6061. }
  6062. else
  6063. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6064. }
  6065. function cancel_selected_ilm () {
  6066. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6067. }
  6068. //]]>
  6069. </script>\n";
  6070. $title = get_string('move_files', 'iassign');
  6071. $PAGE->set_title($title);
  6072. $PAGE->set_pagelayout('base');
  6073. print $OUTPUT->header();
  6074. print $OUTPUT->heading($title);
  6075. $dir_paths = array();
  6076. print $OUTPUT->box_start();
  6077. print "<center>";
  6078. foreach ($files_id as $file_id) {
  6079. $file = $fs->get_file_by_id($file_id);
  6080. if ($file) {
  6081. if (!$file->is_directory())
  6082. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6083. else {
  6084. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6085. array_push($dir_paths, $file->get_filepath());
  6086. }
  6087. }
  6088. }
  6089. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6090. if ($dir_base != '/') {
  6091. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6092. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6093. }
  6094. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6095. foreach ($files_tree as $file) {
  6096. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6097. $is_parent = false;
  6098. foreach ($dir_paths as $dir) {
  6099. $path = explode("/", $dir);
  6100. array_pop($path);
  6101. $path[count($path) - 1] = '';
  6102. $path = implode("/", $path);
  6103. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6104. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6105. }
  6106. if ($is_parent == false) {
  6107. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6108. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6109. }
  6110. }
  6111. }
  6112. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6113. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6114. print "</center>";
  6115. print $OUTPUT->box_end();
  6116. print $OUTPUT->footer();
  6117. print $code_javascript_ilm;
  6118. die;
  6119. }
  6120. /// Function for move files for an dir
  6121. function move_files_ilm () {
  6122. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6123. $context = context_course::instance($this->id);
  6124. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6125. $dirid = $this->get_dir_ilm('dirid');
  6126. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6127. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6128. foreach ($files_id as $file_id) {
  6129. $file = $fs->get_file_by_id($file_id);
  6130. if ($file) {
  6131. if ($file->is_directory()) {
  6132. $pathname = explode("/", $file->get_filepath());
  6133. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6134. foreach ($files_move_path as $value) {
  6135. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6136. $value->rename($path_move, $value->get_filename());
  6137. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6138. }
  6139. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6140. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6141. $file->rename($path_move, $file->get_filename());
  6142. } else {
  6143. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6144. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6145. }
  6146. }
  6147. }
  6148. //die;
  6149. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6150. die();
  6151. } // function move_files_ilm()
  6152. /// Function for recover files in use on all activities of a course
  6153. function recover_files_ilm () {
  6154. global $DB, $USER;
  6155. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6156. $courseid = optional_param('id', NULL, PARAM_INT);
  6157. $dirid = $this->get_dir_ilm('dirid');
  6158. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6159. $contextfile = context_course::instance($this->id);
  6160. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6161. foreach ($iassigns as $iassign) {
  6162. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6163. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6164. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6165. $context = context_module::instance($cm->id);
  6166. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6167. if ($files) {
  6168. foreach ($files as $value) {
  6169. $extension = explode(".", $value->get_filename());
  6170. if (!$value->is_directory()) {
  6171. $fileinfo = array('contextid' => $contextfile->id,
  6172. 'component' => 'mod_iassign',
  6173. 'filearea' => 'activity',
  6174. 'itemid' => 0,
  6175. 'filepath' => $this->get_dir_ilm('dir_base'),
  6176. 'userid' => $USER->id,
  6177. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6178. 'license' => 'allrightsreserved',
  6179. 'timecreated' => time(),
  6180. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6181. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6182. }
  6183. }
  6184. } // if ($files)
  6185. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6186. } // foreach ($iassigns as $iassign)
  6187. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6188. die();
  6189. } // function recover_files_ilm()
  6190. /// Auxiliary function the get all files in a given context
  6191. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6192. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6193. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6194. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6195. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6196. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6197. // (NAO s_iassign_statement.file = s_files.id)
  6198. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6199. $dir_base = $this->get_dir_ilm('dir_base');
  6200. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6201. $countf = 0;
  6202. $array_files_id = array(); // all files from this context
  6203. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6204. //$filename = $item_fc->get_filename();
  6205. //$filepath = $item_fc->get_filepath();
  6206. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6207. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6208. // $array_files_aux[] = $item_fc;
  6209. $itemid = $item_fc->get_id();
  6210. if (!in_array($itemid, $array_files_id)) {
  6211. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6212. if ($fileuserid == $userid)
  6213. $filesfrommine[] = $item_fc;
  6214. else
  6215. $filesfromothers[] = $item_fc;
  6216. $array_files_id[] = $itemid;
  6217. $countf++;
  6218. }
  6219. }
  6220. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6221. return $countf;
  6222. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6223. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6224. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6225. function get_all_ilm_files_by_fileid ($fileid) {
  6226. global $DB, $USER;
  6227. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6228. //TODO Criar coluna 'authorid'
  6229. $str_query = "SELECT * FROM {iassign_statement} " .
  6230. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6231. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6232. return $array_iassign_ilm;
  6233. }
  6234. //NN
  6235. //NN
  6236. // Build string with JavaScript code with function to edit/remove/double iLM files
  6237. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6238. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6239. global $CFG;
  6240. $error_files_exists = get_string('error_file_exists', 'iassign');
  6241. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6242. $code_javascript_ilm = "
  6243. <script type='text/javascript'>
  6244. //<![CDATA[
  6245. function preview_ilm (fileid, ilmid) { //JavaScript function
  6246. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6247. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6248. }
  6249. function update_ilm (ilmid, fileid) { //JavaScript function
  6250. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6251. }
  6252. function delete_ilm (ilmid, fileid) { //JavaScript function
  6253. var msgAnswer;
  6254. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6255. if (msgAnswer) {
  6256. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6257. }
  6258. }
  6259. function delete_selected_ilm () { //JavaScript function
  6260. var msgAnswer;
  6261. var param = getCheckbox();
  6262. if (param.join() != '') {
  6263. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6264. if (msgAnswer)
  6265. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6266. }
  6267. else
  6268. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6269. }
  6270. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6271. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6272. }
  6273. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6274. var filenamecopy;
  6275. var i;
  6276. var files = new Array(" . $files_array . ");
  6277. do {
  6278. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6279. } while (filenamecopy == '');
  6280. if (filenamecopy == null)
  6281. return false;\n
  6282. else {
  6283. for (i=0;i<files.length;i++) {
  6284. if (files[i]==filenamecopy) {
  6285. alert('" . $error_files_exists . "');
  6286. return false;\n
  6287. }
  6288. }\n" .
  6289. // @see: function 'duplicate_file_ilm()' above
  6290. "
  6291. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6292. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6293. } // else
  6294. }
  6295. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6296. var filenamecopy;
  6297. var i;
  6298. var files = new Array($files_array);
  6299. do {
  6300. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6301. } while (filenamecopy == '');
  6302. if (filenamecopy == null)
  6303. return false;
  6304. else {
  6305. for (i=0;i<files.length;i++) {
  6306. if (files[i]==filenamecopy) {
  6307. alert('" . $error_files_exists . "');
  6308. return false;
  6309. }
  6310. }
  6311. 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;
  6312. }
  6313. }
  6314. function export_files_ilm () { //JavaScript function
  6315. var param = getCheckbox();
  6316. if (param.join() != '')
  6317. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6318. else
  6319. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6320. }
  6321. function select_all_ilm () { //JavaScript function
  6322. var checkBoxes = document.getElementsByTagName('input');
  6323. var selectAll = document.getElementById('select_all');
  6324. for (var counter=0; counter < checkBoxes.length; counter++) {
  6325. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6326. checkBoxes[counter].checked = selectAll.checked;
  6327. }
  6328. }
  6329. function getCheckbox () { //JavaScript function
  6330. var checkBoxes = document.getElementsByTagName('input');
  6331. var param = new Array();
  6332. for (var counter=0; counter < checkBoxes.length; counter++) {
  6333. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6334. param.push(checkBoxes[counter].value);
  6335. }
  6336. return param;
  6337. }
  6338. function new_dir_ilm () { //JavaScript function
  6339. var dirname = '';
  6340. var i;
  6341. var dirs = new Array(" . $dirs_array . ");
  6342. do {
  6343. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6344. } while (dirname == '');
  6345. if (dirname == null)
  6346. return false;\n
  6347. else {
  6348. for (i=0;i<dirs.length;i++) {
  6349. if (dirs[i]==dirname) {
  6350. alert('" . $error_dir_exists . "');
  6351. return false;\n
  6352. }
  6353. }
  6354. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6355. }
  6356. }
  6357. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6358. var msgAnswer;
  6359. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6360. if (msgAnswer) {
  6361. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6362. }
  6363. }
  6364. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6365. var dirnamecopy;
  6366. var i;
  6367. var dirs = new Array($dirs_array);
  6368. do {
  6369. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6370. } while (dirnamecopy == '');
  6371. if (dirnamecopy == null)
  6372. return false;\n
  6373. else {
  6374. for (i=0;i<dirs.length;i++) {
  6375. if (dirs[i]==dirnamecopy) {
  6376. alert('" . $error_dir_exists . "');
  6377. return false;\n
  6378. }
  6379. }
  6380. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6381. }
  6382. }
  6383. function move_selected_ilm (ilmid) { //JavaScript function
  6384. var param = getCheckbox();
  6385. if (param.join() != '')
  6386. 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();
  6387. else
  6388. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6389. }
  6390. function recover_files_ilm () { //JavaScript function
  6391. var msgAnswer;
  6392. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6393. if (msgAnswer) {
  6394. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6395. }
  6396. }
  6397. window.onload = function() { //JavaScript function
  6398. var xPosition = 0;
  6399. var yPosition = 0;
  6400. element=document.getElementById('new_file');
  6401. while(element) {
  6402. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6403. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6404. element = element.offsetParent;
  6405. }
  6406. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6407. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6408. location.hash = '#new_file';
  6409. };
  6410. //]]>
  6411. </script>\n"; // end of $code_javascript_ilm
  6412. return $code_javascript_ilm;
  6413. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6414. /// List iassign files from course directory
  6415. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6416. function view_files_ilm ($iassign_ilm_class, $extension) {
  6417. global $CFG, $DB, $USER, $OUTPUT;
  6418. $fs = get_file_storage();
  6419. $context = context_course::instance($this->id);
  6420. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6421. $dirid = $this->get_dir_ilm('dirid');
  6422. $dir_base = $this->get_dir_ilm('dir_base');
  6423. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6424. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6425. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6426. $files_array = '';
  6427. foreach ($files_course as $value) {
  6428. if (!$value->is_directory())
  6429. $files_array .= "'" . $value->get_filename() . "',";
  6430. }
  6431. $files_array .= "''";
  6432. $error_files_exists = get_string('error_file_exists', 'iassign');
  6433. $dirs_array = '';
  6434. foreach ($files_course as $value) {
  6435. if ($value->is_directory()) {
  6436. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6437. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6438. }
  6439. }
  6440. $dirs_array .= "''";
  6441. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6442. // TODO Rever o preview pois só deixar ver uma vez.
  6443. $code_javascript_ilm = "
  6444. <script type='text/javascript'>
  6445. //<![CDATA[
  6446. function preview_ilm (fileid, ilmid) {
  6447. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6448. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6449. }
  6450. function update_ilm (ilmid, fileid) {
  6451. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6452. }
  6453. function delete_ilm (ilmid, fileid) {
  6454. var msgAnswer;
  6455. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6456. if (msgAnswer) {
  6457. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6458. }
  6459. }
  6460. function delete_selected_ilm () {
  6461. var msgAnswer;
  6462. var param = getCheckbox();
  6463. if (param.join() != '') {
  6464. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6465. if (msgAnswer)
  6466. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6467. }
  6468. else
  6469. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6470. }
  6471. function add_ilm_iassign (ilmid, filename, fileid) {
  6472. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6473. }
  6474. function duplicate_ilm (ilmid, filename, fileid) {
  6475. var filenamecopy;
  6476. var i;
  6477. var files = new Array($files_array);
  6478. do {
  6479. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6480. } while (filenamecopy == '');
  6481. if (filenamecopy == null)
  6482. return false;\n
  6483. else {
  6484. for (i=0;i<files.length;i++) {
  6485. if (files[i]==filenamecopy) {
  6486. alert('$error_files_exists');
  6487. return false;\n
  6488. }
  6489. }\n" .
  6490. // @see: function 'duplicate_file_ilm()' above
  6491. "
  6492. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6493. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6494. } // else
  6495. }
  6496. function rename_ilm (ilmid, filename, fileid) {
  6497. var filenamecopy;
  6498. var i;
  6499. var files = new Array($files_array);
  6500. do {
  6501. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6502. } while (filenamecopy == '');
  6503. if (filenamecopy == null)
  6504. return false;
  6505. else {
  6506. for (i=0;i<files.length;i++) {
  6507. if (files[i]==filenamecopy) {
  6508. alert('$error_files_exists');
  6509. return false;
  6510. }
  6511. }
  6512. 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;
  6513. }
  6514. }
  6515. function export_files_ilm () {
  6516. var param = getCheckbox();
  6517. if (param.join() != '')
  6518. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6519. else
  6520. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6521. }
  6522. function select_all_ilm () {
  6523. var checkBoxes = document.getElementsByTagName('input');
  6524. var selectAll = document.getElementById('select_all');
  6525. for (var counter=0; counter < checkBoxes.length; counter++) {
  6526. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6527. checkBoxes[counter].checked = selectAll.checked;
  6528. }
  6529. }
  6530. function getCheckbox () {
  6531. var checkBoxes = document.getElementsByTagName('input');
  6532. var param = new Array();
  6533. for (var counter=0; counter < checkBoxes.length; counter++) {
  6534. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6535. param.push(checkBoxes[counter].value);
  6536. }
  6537. return param;
  6538. }
  6539. function new_dir_ilm () {
  6540. var dirname = '';
  6541. var i;
  6542. var dirs = new Array($dirs_array);
  6543. do {
  6544. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6545. } while (dirname == '');
  6546. if (dirname == null)
  6547. return false;\n
  6548. else {
  6549. for (i=0;i<dirs.length;i++) {
  6550. if (dirs[i]==dirname) {
  6551. alert('$error_dir_exists');
  6552. return false;\n
  6553. }
  6554. }
  6555. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6556. }
  6557. }
  6558. function delete_dir_ilm (ilmid, dirid) {
  6559. var msgAnswer;
  6560. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6561. if (msgAnswer) {
  6562. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6563. }
  6564. }
  6565. function rename_dir_ilm (ilmid, dirname, dirid) {
  6566. var dirnamecopy;
  6567. var i;
  6568. var dirs = new Array($dirs_array);
  6569. do {
  6570. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6571. } while (dirnamecopy == '');
  6572. if (dirnamecopy == null)
  6573. return false;\n
  6574. else {
  6575. for (i=0;i<dirs.length;i++) {
  6576. if (dirs[i]==dirnamecopy) {
  6577. alert('$error_dir_exists');
  6578. return false;\n
  6579. }
  6580. }
  6581. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6582. }
  6583. }
  6584. function move_selected_ilm (ilmid) {
  6585. var param = getCheckbox();
  6586. if (param.join() != '')
  6587. 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();
  6588. else
  6589. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6590. }
  6591. function recover_files_ilm () {
  6592. var msgAnswer;
  6593. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6594. if (msgAnswer) {
  6595. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6596. }
  6597. }
  6598. window.onload = function() {
  6599. var xPosition = 0;
  6600. var yPosition = 0;
  6601. element=document.getElementById('new_file');
  6602. while(element) {
  6603. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6604. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6605. element = element.offsetParent;
  6606. }
  6607. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6608. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6609. location.hash = '#new_file';
  6610. };
  6611. //]]>
  6612. </script>\n";
  6613. $output = "";
  6614. $select_all = "";
  6615. $count_files = 0;
  6616. $extensions_allow = array();
  6617. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6618. foreach ($iassign_ilm as $item_iassign_ilm)
  6619. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6620. foreach ($files_course as $value) {
  6621. $filename = $value->get_filename();
  6622. $filepath = $value->get_filepath();
  6623. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6624. $pathname = $pathname[count($pathname) - 1];
  6625. $fileid = $value->get_id();
  6626. $tmp = explode(".", $filename);
  6627. if (count($tmp)>1) // avoid error if the file has no extension
  6628. $filetype = $tmp[1];
  6629. else // probably error...
  6630. $filetype = '';
  6631. $author = $value->get_author();
  6632. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6633. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6634. $extensions = explode(",", $extension);
  6635. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6636. $count_files ++;
  6637. // buscar fileid nas tabelas do iassign
  6638. $list_filein_use = "";
  6639. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6640. if ($iassign_statement_activity_list) {
  6641. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6642. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6643. }
  6644. }
  6645. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6646. if (!$iassign_ilm) {
  6647. $iassign_ilm = new stdClass();
  6648. $iassign_ilm->id = $ilmid;
  6649. }
  6650. // Do not use $var inside "..." - problem with some "unusual" operational system
  6651. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6652. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6653. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6654. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6655. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6656. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6657. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6658. $check_select = "";
  6659. $link_rename = "";
  6660. $link_delete = "";
  6661. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6662. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6663. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6664. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6665. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6666. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6667. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6668. if ($value->get_userid() == $USER->id) {
  6669. if ($iassign_statement_activity_list) {
  6670. $check_select = "";
  6671. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6672. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6673. $link_rename = "";
  6674. } else {
  6675. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6676. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6677. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6678. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6679. }
  6680. }
  6681. if (!in_array($filetype, $extensions_allow)) {
  6682. $link_edit = "";
  6683. $link_add_ilm_iassign = "";
  6684. $link_add_ilm_tinymce = "";
  6685. $link_add_ilm_atto = "";
  6686. $link_filter = "";
  6687. }
  6688. if ($value->is_directory()) {
  6689. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6690. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6691. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6692. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6693. <td><center>$author</center></td>
  6694. <td><center>$timecreated</center></td>
  6695. <td><center>$timemodified</center></td></tr>\n";
  6696. }
  6697. else if ($this->from == 'iassign') {
  6698. $new_id = "";
  6699. $new_class = "";
  6700. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6701. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6702. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6703. }
  6704. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6705. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6706. <td><center>$author</center></td>
  6707. <td><center>$timecreated</center></td>
  6708. <td><center>$timemodified</center></td></tr>\n";
  6709. }
  6710. else if ($this->from == 'block') {
  6711. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6712. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6713. <td><center>$author</center></td>
  6714. <td><center>$timecreated</center></td>
  6715. <td><center>$timemodified</center></td></tr>\n";
  6716. }
  6717. else if ($this->from == 'tinymce') {
  6718. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6719. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6720. <td><center>$author</center></td>
  6721. <td><center>$timecreated</center></td>
  6722. <td><center>$timemodified</center></td></tr>\n";
  6723. }
  6724. else if ($this->from == 'atto') {
  6725. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6726. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6727. <td><center>$author</center></td>
  6728. <td><center>$timecreated</center></td>
  6729. <td><center>$timemodified</center></td></tr>\n";
  6730. }
  6731. }
  6732. }
  6733. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6734. $dir_base = "";
  6735. $header = "";
  6736. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6737. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6738. foreach ($basename as $value) {
  6739. $dir_base .= $value . "/";
  6740. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6741. if ($dir_id) {
  6742. if ($value == "") {
  6743. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6744. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6745. } else {
  6746. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6747. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6748. }
  6749. }
  6750. } // foreach ($basename as $value)
  6751. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6752. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6753. $html .= "
  6754. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6755. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6756. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6757. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6758. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6759. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6760. </table>\n";
  6761. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6762. $html .= "<table width='100%'><tr>\n";
  6763. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6764. if ($count_files != 0) {
  6765. $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";
  6766. $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";
  6767. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6768. }
  6769. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6770. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6771. $html .= "</form>\n";
  6772. print $code_javascript_ilm;
  6773. print $html;
  6774. } // function view_files_ilm($extension)
  6775. } // class ilm_manager
  6776. /// Class to insert of icons
  6777. class iassign_icons {
  6778. static function insert ($icon) {
  6779. global $CFG;
  6780. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6781. return $string;
  6782. }
  6783. }
  6784. /// Class with util functions for plugin manage
  6785. class iassign_utils {
  6786. /// Function to return the filename extension
  6787. // @param string The $filename as an string
  6788. // @return string Return an string (last group after '.')
  6789. static function filename_extension ($filename) {
  6790. if ($filename == null || $filename == '') {
  6791. return null;
  6792. }
  6793. $itens = explode('.', $filename);
  6794. $num = count($itens);
  6795. if ($num < 2) {
  6796. return null;
  6797. }
  6798. return $itens[$num - 1];
  6799. }
  6800. /// Use the PHP class/package ZipArchive to create a Zip file
  6801. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6802. // 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
  6803. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6804. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6805. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6806. $zip = new zip_archive(); //2
  6807. $res = $zip->open($full_path_zip_filename);
  6808. $total_vet = count($vet_student_filename);
  6809. for ($ii=0; $ii<$total_vet; $ii++) {
  6810. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6811. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6812. }
  6813. $ret = $zip->close();
  6814. iassign_utils::download_file($full_path_zip_filename);
  6815. $filenameZip = $zip->filename;
  6816. return array($ret, $zip);
  6817. }
  6818. static function download_file ($zip_filename) {
  6819. header("Pragma: public");
  6820. header("Expires: 0");
  6821. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6822. header("Cache-Control: private", false);
  6823. header("Content-Type: application/zip");
  6824. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6825. header("Content-Transfer-Encoding: binary");
  6826. header("Content-Length: " . @filesize($zip_filename));
  6827. set_time_limit(0);
  6828. @readfile("$zip_filename") || die("File not found.");
  6829. unlink($zip_filename);
  6830. }
  6831. /// Function for format filename remove special caracters
  6832. // @param string $text String for clean
  6833. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6834. // @return string Return an string in clean format
  6835. static function format_filename ($text) {
  6836. if ($text != '.') {
  6837. //D $text = htmlspecialchars(urldecode($text));
  6838. //D echo "locallib.php: format_filename: $text<br/>";
  6839. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6840. $text = json_decode($text)->{current_language()};
  6841. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6842. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6843. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6844. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6845. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6846. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6847. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6848. // E.g. text = "exerc_midpoint.course.geo"
  6849. // 0123456789012345678901234
  6850. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6851. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6852. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6853. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6854. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6855. //$ext = strrpos($text, ".");
  6856. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6857. //$text = str_replace($array1, $array2, $text);
  6858. }
  6859. return $text;
  6860. }
  6861. /// Function to filter characters to the file name to iLM content
  6862. // @param string $text String for clean
  6863. // @param string $ext String ot the extension of the iLM
  6864. // @return string Return an string in clean format
  6865. static function filter_filename_extension ($filename, $ext) {
  6866. if ($filename != '.') {
  6867. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6868. $arrTo = array("_","","","","","","","","","","","","");
  6869. $filename = str_replace($arrFrom, $arrTo, $filename);
  6870. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6871. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6872. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6873. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6874. $index_lastposition = strlen($filenameF);
  6875. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6876. $text = str_replace(".", "_", $text); // erase all other "."
  6877. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6878. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6879. }
  6880. else
  6881. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6882. return $filenameF;
  6883. }
  6884. /// Function for format pathname remove special caracters
  6885. // @param string $text String for clean
  6886. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6887. // @return string Return an string in clean format
  6888. static function format_pathname ($text, $is_lowercase = true) {
  6889. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6890. $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", "-", "_", "", "", "");
  6891. $text = str_replace($array1, $array2, $text);
  6892. if ($is_lowercase)
  6893. $text = strtolower($text);
  6894. return $text;
  6895. }
  6896. /// Function for format file name from iLM original name
  6897. // @param string $text String to build the file neam
  6898. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6899. // @return string Return an string in clean format
  6900. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6901. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6902. $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", "-", "_", "", "", "");
  6903. $index_firstposition_blank = strpos($ilm_name, " ");
  6904. if ($index_firstposition_blank) { // truncate the name!
  6905. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6906. }
  6907. $index_firstposition_dots = strpos($ilm_name, ":");
  6908. if ($index_firstposition_dots) { // truncate the name!
  6909. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6910. }
  6911. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6912. if ($is_lowercase)
  6913. $namefiltered = strtolower($namefiltered);
  6914. return $namefiltered;
  6915. }
  6916. /// Function for insert version in the filename
  6917. // @param string $filename Name of file
  6918. // @return string Return the filename with version
  6919. static function version_filename ($filename) {
  6920. $array_filename = explode('.', $filename);
  6921. if (count($array_filename) > 1)
  6922. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6923. else
  6924. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6925. return $filename;
  6926. }
  6927. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6928. static function remove_code_message ($string) {
  6929. $array = explode("&lt;ia_uc&gt;", $string);
  6930. return $array[0];
  6931. }
  6932. }
  6933. // class iassign_utils
  6934. /// Class with language functions for plugin manage
  6935. class iassign_language {
  6936. /// Function for return text in language or get default language (en)
  6937. // @param string $lang Code of language
  6938. // @param string $description JSON text content all languages
  6939. // @return string Return an string in the language selected
  6940. static function get_description_lang ($lang, $descriptions) {
  6941. $description_lang = "";
  6942. $description = json_decode($descriptions);
  6943. if ($description == null) {
  6944. $description_lang = $descriptions;
  6945. }
  6946. else {
  6947. if (isset($description->{$lang}))
  6948. $description_lang = $description->{$lang};
  6949. else
  6950. if (isset($description->en)) //MOOC2014
  6951. $description_lang = $description->en;
  6952. else //MOOC2014
  6953. $description_lang = "en"; //MOOC2014
  6954. }
  6955. return $description_lang;
  6956. }
  6957. /// Function for return all language supported by iLM
  6958. // @param string $descriptions JSON text content all languages
  6959. // @return string Return as string with all languages
  6960. static function get_all_lang ($descriptions) {
  6961. $langs = "";
  6962. $description = json_decode($descriptions);
  6963. if ($description) {
  6964. foreach ($description as $key => $value) {
  6965. $langs .= $key . " ; ";
  6966. }
  6967. $langs = substr($langs, 0, strlen($langs) - 3);
  6968. }
  6969. return $langs;
  6970. }
  6971. /// Function for convert json in xml //MOOC2014
  6972. // @param string $json JSON text
  6973. // @return string Return as string with xml tags
  6974. static function json_to_xml ($json) {
  6975. $xml = "";
  6976. $json = json_decode($json);
  6977. foreach ($json as $key => $value) {
  6978. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6979. }
  6980. return $xml;
  6981. }
  6982. }
  6983. // class iassign_language
  6984. /// Class with log functions for plugin manage.
  6985. class iassign_log {
  6986. /// Function for insert log event
  6987. // @param string $action Code action of event
  6988. // @param string $information Text for describe action of event
  6989. // @param int $cmid Id of context module
  6990. // @param int $ilmid Id of iLM
  6991. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6992. global $COURSE, $CFG, $USER, $DB;
  6993. $newentry = new stdClass();
  6994. $newentry->time = time();
  6995. $newentry->userid = $USER->id;
  6996. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6997. $newentry->course = $COURSE->id;
  6998. $newentry->cmid = $cmid;
  6999. $newentry->ilmid = $ilmid;
  7000. $newentry->action = $action;
  7001. $newentry->info = $information;
  7002. $newentry->language = current_language();
  7003. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7004. if (ini_get("browscap") && function_exists('get_browse')) {
  7005. $browser = get_browse(null, true);
  7006. $newentry->javascript = $browser['javascript'];
  7007. $newentry->java = $browser['javaapplets'];
  7008. }
  7009. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7010. print_error('error_add_log', 'iassign');
  7011. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7012. } // class iassign_log