locallib.php 400 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624
  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. 'notifications' => '$this->view_notifications();');
  254. $action_iassign_limit = array(
  255. 'view' => '$this->view_iassign_current();',
  256. //'newcomment' => '$this->get_answer();',
  257. 'viewsubmission' => '$this->view_iassign_current();',
  258. 'edit_status' => '$this->edit_status();',
  259. 'edit_grade' => '$this->edit_grade();',
  260. 'export_csv' => '$this->export_csv();',
  261. 'report' => '$this->report();',
  262. 'print' => '$this->report();',
  263. 'stats' => '$this->stats();',
  264. 'printstats' => '$this->stats();');
  265. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  266. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  267. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  268. 'visible' => '$this->activity->visible_iassign($this->return);',
  269. 'delete' => '$this->activity->delete($this->return);',
  270. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  271. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  272. 'add' => '$this->add_edit_iassign();',
  273. 'edit' => '$this->add_edit_iassign();',
  274. 'get_answer' => '$this->get_answer();',
  275. 'duplicate_activity' => '$this->duplicate_activity();',
  276. 'move_activity' => '$this->move_activity();',
  277. 'auto_evaluate' => '$this->auto_evaluate();',
  278. 'all_submissions' => '$this->all_submissions();',
  279. 'delete_submissions' => '$this->delete_submissions();',
  280. 'download_submissions' => '$this->download_submissions();',
  281. 'open_individual_submission' => '$this->open_individual_submission();',
  282. 'get_individual_submission' => '$this->get_individual_submission();',
  283. 'get_student_submission' => '$this->get_student_submission();',
  284. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  285. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  286. );
  287. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  288. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  289. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  290. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  291. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  292. }
  293. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  294. eval($action_iassign_limit[$this->action]);
  295. }
  296. else { // Student reaches this point
  297. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  298. // Arrive here with: "get_answer"; "view"
  299. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  300. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  301. }
  302. } // function action()
  303. /// This method prints the student submission to a specific exercise
  304. function get_student_submission () {
  305. global $DB;
  306. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  307. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  308. if (!$student || !$exercise) exit;
  309. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  310. if ($iassign_submission)
  311. print($iassign_submission->answer);
  312. die();
  313. }
  314. /// This method prints the teacher exercise
  315. function get_teacher_exercise () {
  316. global $DB, $COURSE;
  317. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  318. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  319. $fs = get_file_storage(); // Get reference to all files in Moodle data
  320. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  321. foreach ($files as $file) {
  322. if ($file->get_filename() != ".") {
  323. print($file->get_content());
  324. }
  325. }
  326. die();
  327. }
  328. /// This method receives the data from auto_eval event
  329. /// @see auto_evaluate()
  330. function post_auto_eval_result () {
  331. global $COURSE, $CFG, $USER, $DB;
  332. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  333. exit;
  334. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  335. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  336. $student = optional_param('student', -1, PARAM_INT);
  337. $grade = optional_param('grade', 0, PARAM_FLOAT);
  338. // 1: Recuperar a nota atual:
  339. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  340. // 2: Atualizar a tabela:
  341. $update_entry = new stdClass();
  342. $update_entry->id = $actual->id;
  343. $update_entry->previous_grade = $actual->grade;
  344. $update_entry->grade = $grade;
  345. // Update the iassign_submission
  346. $DB->update_record("iassign_submission", $update_entry);
  347. }
  348. /// Function to help download all_submissions files
  349. function download_submissions_help ($list) {
  350. global $DB, $CFG, $OUTPUT;
  351. // Get list of iLMs
  352. $ilm_list = $DB->get_records("iassign_ilm");
  353. // Get list of enrolled students:
  354. $params_temp = array('shortname' => 'student');
  355. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  356. $context = context_course::instance($this->course->id);
  357. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  358. $students_list = $DB->get_records_sql(
  359. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  360. $json_obj = new stdclass();
  361. $json_obj->submissions = [];
  362. $csvfields = [];
  363. $csvfields[] = 'submissionid';
  364. $csvfields[] = 'file';
  365. $csvfields[] = 'filesize';
  366. $csvfields[] = 'timestamp';
  367. $csvfields[] = 'humandate';
  368. $csvfields[] = 'grade';
  369. $csvfields[] = 'userid';
  370. $csvfields[] = 'exerciseid';
  371. $json_obj->submissions[] = $csvfields;
  372. $exercise_dir = [];
  373. $exercises_list = [];
  374. foreach ($list as $item) {
  375. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  376. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  377. $exercises_list[] = $temp;
  378. $exercise_dir[] = $temp->id;
  379. }
  380. }
  381. $student_dir = [];
  382. $students_list = [];
  383. foreach ($list as $item) {
  384. if (!in_array($item->userid, $student_dir)) {
  385. $temp = $DB->get_record("user", array("id" => $item->userid));
  386. $students_list[] = $temp;
  387. $student_dir[] = $temp->id;
  388. }
  389. }
  390. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  391. //TODO: tem que criar moodledata/temp/iassign_files
  392. // Create $CFG->dataroot/temp/iassign_files
  393. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  394. if (!file_exists($tempfilespath)) {
  395. mkdir($tempfilespath, 0777, true);
  396. }
  397. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  398. if (!file_exists($iassignfilespath)) {
  399. mkdir($iassignfilespath, 0777, true);
  400. }
  401. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  402. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  403. if (!file_exists($diretorio)) {
  404. echo 'Não foi possível criar o diretório para preparar o arquivo com as submissões. Possivelmente o caminho está bloqueado para escrita.';
  405. exit;
  406. }
  407. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  408. $zip = new zip_archive(); // create ZIP
  409. if (!$zip->open($zip_filename)) {
  410. echo 'Não foi possível criar o arquivo zip com as submissões dos alunos, pois o diretório no servidor está bloqueado para escrita: ' . $diretorio;
  411. exit;
  412. }
  413. ;
  414. foreach ($exercises_list as $exercise) {
  415. $dir_ex = iassign_utils::format_filename($exercise->name);
  416. $zip->add_directory($dir_ex);
  417. $extension_ilm = '';
  418. foreach ($ilm_list as $ilm) {
  419. if ($exercise->iassign_ilmid == $ilm->id) {
  420. $extension_ilm = $ilm->extension;
  421. break;
  422. }
  423. }
  424. foreach ($students_list as $student) {
  425. $individual_dir =
  426. $dir_ex . DIRECTORY_SEPARATOR .
  427. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  428. $zip->add_directory($individual_dir);
  429. $i = 1;
  430. foreach($list as $item) {
  431. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  432. $date = new DateTime();
  433. $date->setTimestamp($item->timecreated);
  434. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  435. $zip->add_file_from_string($new_file, $item->answer);
  436. $temp_json = [];
  437. $temp_json[] = intval($item->id);
  438. $temp_json[] = $new_file;
  439. $temp_json[] = strlen($new_file);
  440. $temp_json[] = intval($item->timecreated);
  441. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  442. $temp_json[] = doubleval($item->grade);
  443. $temp_json[] = intval($item->userid);
  444. $temp_json[] = intval($exercise->id);
  445. $json_obj->submissions[] = $temp_json;
  446. }
  447. }
  448. }
  449. }
  450. $csv_str = "";
  451. foreach($json_obj->submissions as $sub) {
  452. $csv_str .= $this->csvstr($sub) . "\n";
  453. }
  454. $zip->add_file_from_string('index.csv', $csv_str);
  455. $zip->close();
  456. iassign_utils::download_file($zip_filename);
  457. exit;
  458. }
  459. function csvstr(array $fields) : string {
  460. $f = fopen('php://memory', 'r+');
  461. if (fputcsv($f, $fields) === false) {
  462. return false;
  463. }
  464. rewind($f);
  465. $csv_line = stream_get_contents($f);
  466. return rtrim($csv_line);
  467. }
  468. /// Download submissions from table iassign_allsubmissions
  469. function download_submissions () {
  470. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  471. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  472. exit;
  473. $type = optional_param('type', NULL, PARAM_TEXT);
  474. $item = optional_param('item', NULL, PARAM_TEXT);
  475. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  476. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  477. $sub_list = [];
  478. if ($type == 'individual') {
  479. $sub_list[] = $DB->get_record(
  480. 'iassign_allsubmissions', array('id' => $item));
  481. } elseif ($type == 'student') {
  482. $sub_list = $DB->get_records(
  483. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  484. } elseif ($type == 'exercise') {
  485. $sub_list = $DB->get_records(
  486. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  487. } elseif ($type == 'block') {
  488. $exercises_in_block = $DB->get_records(
  489. 'iassign_statement', array('iassignid' => $iassign_id));
  490. foreach ($exercises_in_block as $exercise) {
  491. $temp = $DB->get_records(
  492. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  493. $sub_list = array_merge($sub_list, $temp);
  494. }
  495. }
  496. $this->download_submissions_help($sub_list);
  497. }
  498. /// Delete submissions in table iassign_allsubmissions
  499. function delete_submissions () {
  500. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  501. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  502. exit;
  503. $type = optional_param('type', NULL, PARAM_TEXT);
  504. $item = optional_param('item', NULL, PARAM_TEXT);
  505. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  506. if ($type == 'individual') {
  507. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  508. } elseif ($type == 'student') {
  509. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  510. } elseif ($type == 'exercise') {
  511. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  512. }
  513. }
  514. function get_individual_submission () {
  515. global $DB, $USER;
  516. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  517. exit;
  518. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  519. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  520. print $submission->answer;
  521. }
  522. /// Open individual submission
  523. function open_individual_submission () {
  524. global $DB, $USER, $CFG;
  525. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  526. exit;
  527. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  528. $id = $this->cm->id;
  529. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  530. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  531. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  532. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  533. $all_submissions = $DB->get_records('iassign_allsubmissions',
  534. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  535. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  536. $previous = null;
  537. $next = null;
  538. $i = 0;
  539. $found = false;
  540. foreach($all_submissions as $individual) {
  541. if (!$found && $individual->id != $submissionid) {
  542. $previous = $individual;
  543. }
  544. if ($found) {
  545. $next = $individual;
  546. break;
  547. }
  548. if ($individual->id === $submissionid) {
  549. $found = true;
  550. }
  551. $i ++;
  552. }
  553. print '<center>';
  554. print '<table cellpading=5 cellspacing=5 style="padding-bottom: 2rem;font-size: 1.1em;"><tr><td>' . get_string('exercise', 'iassign') . ':</td><td>' . $atual_statement->name . '</td></tr>';
  555. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>';
  556. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>';
  557. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>';
  558. print '</table>';
  559. if ($previous) {
  560. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  561. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  562. } else {
  563. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  564. }
  565. print ' (' . $i . '/' . count($all_submissions) . ')';
  566. if ($next) {
  567. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  568. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  569. } else {
  570. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  571. }
  572. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  573. print
  574. //array("type" => "editor_new", "notSEND" => "true")
  575. ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  576. print '</center>';
  577. }
  578. /// Manage all submissions in exercises to table iassign_allsubmissions
  579. function all_submissions () {
  580. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  581. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  582. exit;
  583. print $OUTPUT->header();
  584. $this->print_main_menu();
  585. $id = $this->cm->id;
  586. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  587. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  588. print '
  589. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  590. <div class="modal-dialog modal-dialog-centered" role="document">
  591. <div class="modal-content">
  592. <div class="modal-header">
  593. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  594. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  595. <span aria-hidden="true">&times;</span>
  596. </button>
  597. </div>
  598. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  599. <div class="modal-footer">
  600. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  601. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  602. </div>
  603. </div>
  604. </div>
  605. </div>'; // "
  606. print '
  607. <script>
  608. var sub_type;
  609. var sub_item;
  610. var sub_el;
  611. var sub_exercise;
  612. function delete_submission (type, item, el, exercise = 0) {
  613. sub_type = type;
  614. sub_item = item;
  615. sub_exercise = exercise;
  616. sub_el = el.closest("tr");
  617. if (!sub_el) sub_el = el.closest("a");
  618. $("#modalConfirm").modal();
  619. }
  620. function confirm_delete () {
  621. var url = "'.$enderecoPOST.'&action=delete_submissions";
  622. var xhttp = new XMLHttpRequest();
  623. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  624. xhttp.send();
  625. $("#modalConfirm").modal("hide");
  626. if ($(sub_el).attr("href"))
  627. $($(sub_el).attr("href")).remove();
  628. if (sub_el) sub_el.remove();
  629. }
  630. function download_submission(type, item, exercise = 0, iassign = 0) {
  631. var url = "'.$enderecoPOST.'&action=download_submissions";
  632. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  633. document.location = url;
  634. }
  635. function open_submission(item) {
  636. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  637. var poupup = window.open(url, "popup", "width=900,height=900");
  638. }
  639. </script>' . chr(13); // '
  640. // Get list of exercises in the instance:
  641. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  642. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  643. print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
  644. 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>';
  645. // Get list of enrolled students:
  646. $params_temp = array('shortname' => 'student');
  647. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  648. $context = context_course::instance($this->course->id);
  649. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  650. $students_list = $DB->get_records_sql(
  651. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  652. print '<div>';
  653. foreach ($exercises_list as $exercise) {
  654. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  655. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  656. print '
  657. <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> '
  658. . $exercise->name
  659. . ' - ' . $iassign_ilm->name
  660. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  661. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  662. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  663. . $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> '
  664. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  665. . '</a>';
  666. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  667. foreach ($students_list as $student) {
  668. $total = 0;
  669. $student_submissions = [];
  670. foreach ($submissions_list as $submission) {
  671. if ($submission->userid == $student->userid) {
  672. $student_submissions[] = $submission;
  673. $total ++;
  674. }
  675. }
  676. 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");\'>
  677. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  678. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  679. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  680. . '<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> '
  681. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  682. . ' </a>';
  683. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  684. print '<table class="table table-striped table-hover"><thead>
  685. <tr>
  686. <th scope="col">#</th>
  687. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  688. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  689. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  690. </tr>
  691. </thead><tbody>'; // "
  692. $i = 1;
  693. foreach ($student_submissions as $individual) {
  694. $date = new DateTime();
  695. $date->setTimestamp($individual->timecreated);
  696. print '<tr>';
  697. print '<td>'.$i++.'</td>';
  698. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  699. print '<td>'.$individual->grade.'</td>';
  700. print '<td>
  701. <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>
  702. <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>
  703. <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>';
  704. print " </tr>\n";
  705. }
  706. print '</tbody></table>';
  707. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  708. print '</div>';
  709. }
  710. print '</div>';
  711. }
  712. print '</div>';
  713. print $OUTPUT->footer();
  714. } // function all_submissions()
  715. /// This method runs activities auto evaluation in teacher area
  716. function auto_evaluate () {
  717. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  718. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  719. exit;
  720. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  721. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  722. // Get list of exercises in the instance:
  723. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  724. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  725. // Get list of enrolled students:
  726. $params_temp = array('shortname' => 'student');
  727. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  728. $context = context_course::instance($this->course->id);
  729. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  730. $students_list = $DB->get_records_sql(
  731. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  732. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  733. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  734. print $OUTPUT->header();
  735. $this->print_main_menu();
  736. print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  737. print '<ul style="list-style-type: none; margin: 1em;">';
  738. foreach ($exercises_list as $exercise) {
  739. $matches = [];
  740. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  741. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  742. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  743. if ($matches[0][0]) {
  744. 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>';
  745. } else {
  746. 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>';
  747. }
  748. } else {
  749. if ($matches[0][0]) {
  750. 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>';
  751. } else {
  752. 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>';
  753. }
  754. }
  755. }
  756. print '</ul>
  757. <center>
  758. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  759. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  760. <div id="evaluate_message" style="color: red"></div>
  761. <div id="evaluate_alerts"></div>
  762. <div>
  763. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  764. <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>
  765. </div>
  766. </center>'; // close "
  767. print ' </div>';
  768. print ' <script>';
  769. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  770. print ' var submissions = [';
  771. // Get list of student id have submit for each exercise:
  772. foreach ($exercises_list as $exercise) {
  773. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  774. print '
  775. {
  776. "exerciseid": "' . $exercise->id . '",
  777. "grade": ' . $exercise->grade . ',
  778. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  779. "submited": ['; // "
  780. $params_temp = array('iassign_statementid' => $exercise->id);
  781. $submited = $DB->get_records_sql( // Get userid and his grade
  782. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  783. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  784. foreach ($submited as $ss) {
  785. print($ss->userid . ',');
  786. }
  787. print '],';
  788. print '"allgrades": [';
  789. foreach ($submited as $ss) {
  790. print( $ss->grade . ',');
  791. }
  792. print ']
  793. },'; // close "
  794. } // foreach ($exercises_list as $exercise)
  795. print " ];\n";
  796. print '
  797. var total_submissions = 0;
  798. var selected_exercises;
  799. var count_steps;
  800. var value_by_step;
  801. var stoped = false;
  802. var time_interval = 5000;
  803. var var_interval;
  804. function add_hover_th (id_th, id_li) { //AJAX
  805. $("#" + id_th).hover(function() {
  806. $("#" + id_li).css("background-color", "#d9d8d8");
  807. $(this).css("background-color", "#d9d8d8");
  808. }, function() {
  809. $("#" + id_li).css("background-color", "");
  810. $(this).css("background-color", "");
  811. });
  812. }
  813. function start_evaluation () {
  814. stoped = false;
  815. //AJAX
  816. $("#progress_bar").css("display", "none");
  817. $("#evaluate_message").text("");
  818. $("#evaluate_alerts").text("");
  819. $(".added-col").remove();
  820. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  821. selected_exercises = [];
  822. var c = 0;
  823. for (var i = 0; i < exercises.length; i++) {
  824. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  825. selected_exercises[c++] = exercises[i];
  826. }
  827. }
  828. if (selected_exercises.length == 0) {
  829. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  830. return;
  831. } else {
  832. $("input:checkbox").attr("disabled", true); //AJAX
  833. for (var i = 0; i < selected_exercises.length; i++) {
  834. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  835. //AJAX
  836. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  837. $("#table-results tbody tr").each(function(e) {
  838. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  839. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  840. });
  841. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  842. }
  843. //AJAX
  844. $("#button_start").prop("disabled", true);
  845. $("#button_stop").prop("disabled", false);
  846. $("#progress_bar").css("display", "block");
  847. }
  848. total_submissions = selected_exercises.length * students.length;
  849. count_steps = 0;
  850. value_by_step = 100/total_submissions;
  851. actual_exercise = 0;
  852. actual_student = 0;
  853. actual_submission = 0;
  854. get_original_propositions();
  855. var_interval = setInterval(verifyBreak, time_interval);
  856. } // function start_evaluation()
  857. var actual_exercise;
  858. var actual_student;
  859. var actual_submission;
  860. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  861. function run_individual_evaluation () {
  862. if (stoped) return;
  863. // Verify if student really sent his answer
  864. var found = false;
  865. for (var j = 0; j < submissions.length; j++) {
  866. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  867. for (var k = 0; k < submissions[j].submited.length; k++) {
  868. if (students[actual_student] == submissions[j].submited[k]) {
  869. found = true;
  870. break;
  871. }
  872. }
  873. break;
  874. }
  875. }
  876. if (found == false) {
  877. postResultAutoEval();
  878. } else {
  879. // If it was sent, search it...
  880. var final_url = "";
  881. 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];
  882. for (var j = 0; j < submissions.length; j++) {
  883. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  884. final_url = submissions[j].ilm;
  885. break;
  886. }
  887. }
  888. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  889. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  890. window.frames["ifrm"].location=final_url;
  891. }
  892. } // function run_individual_evaluation()
  893. var break_student = -1;
  894. var break_exercise = -1;
  895. function verifyBreak () {
  896. if (actual_student == break_student && actual_exercise == break_exercise) {
  897. postResultAutoEval(-6);
  898. break_student = -1;
  899. break_exercise = -1;
  900. return;
  901. } else {
  902. break_student = actual_student;
  903. break_exercise = actual_exercise;
  904. }
  905. }
  906. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  907. function getStudentAnswerURL () {
  908. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  909. }
  910. // This function is called by the iLM!!!
  911. function getAutoEvalOriginalData () {
  912. return original_propositions[actual_exercise];
  913. }
  914. function updateProgressBar () {
  915. if (stoped) return;
  916. var temp = (count_steps * value_by_step)|0;
  917. count_steps ++;
  918. temp = temp > 100 ? 100 : temp;
  919. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  920. if (temp >= 100) {
  921. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  922. $("#button_start").prop("disabled", false);
  923. $("#button_stop").prop("disabled", true);
  924. $("input:checkbox").attr("disabled", false);
  925. clearInterval(var_interval);
  926. }
  927. }
  928. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  929. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  930. function postResultAutoEval (grade = null) {
  931. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  932. if (grade == null) {
  933. $("#"+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>\');
  934. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  935. } else {
  936. // Verify if the re-evaluation grade is the of that one registered:
  937. var actual_value = 0;
  938. var actual_student_grade = 0;
  939. for (var k = 0; k < submissions.length; k++) {
  940. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  941. actual_value = submissions[k].grade;
  942. for (var h = 0; h < submissions[k].submited.length; h++) {
  943. if (submissions[k].submited[h] == students[actual_student]) {
  944. actual_student_grade = submissions[k].allgrades[h];
  945. break;
  946. }
  947. }
  948. break;
  949. }
  950. }
  951. // @FeedbackConvention
  952. if (grade < 0) {
  953. switch (grade) {
  954. case -1:
  955. // Test-cases are empty:
  956. $("#"+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>\');
  957. var mm = actual_exercise;
  958. $("#"+id_t).find(".details-button").click(function(e) {
  959. $(".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>\');
  960. });
  961. break;
  962. case -2:
  963. // Test-cases were manually altered by the student (fraud!):
  964. $("#"+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>\');
  965. var mm = actual_exercise;
  966. $("#"+id_t).find(".details-button").click(function(e) {
  967. $(".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>");
  968. });
  969. //AJAX
  970. $.ajax({
  971. dataType: "html",
  972. 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",
  973. success: function(d) {} });
  974. break;
  975. case -5:
  976. // Execution failed:
  977. $("#"+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>\');
  978. var mm = actual_exercise;
  979. //AJAX
  980. $("#"+id_t).find(".details-button").click(function(e) {
  981. $(".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>\');
  982. });
  983. break;
  984. case -6: // iLM not answering was detected in "verifyBreak()"
  985. // The iLM are not answering:
  986. //AJAX
  987. $("#"+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>\');
  988. $("#"+id_t).find(".details-button").click(function(e) {
  989. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  990. });
  991. break;
  992. }
  993. //AJAX
  994. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  995. } else {
  996. console.log((grade), (actual_student_grade));
  997. if ((grade) == (actual_student_grade)) {
  998. $("#"+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>\');
  999. } else { // Notas diferem:
  1000. $("#"+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>\');
  1001. var mm = actual_exercise;
  1002. //AJAX
  1003. $("#"+id_t).find(".details-button").click(function(e) {
  1004. $(".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>\');
  1005. });
  1006. //AJAX
  1007. // Send to the endpoint the post_auto_eval_result to verify:
  1008. $.ajax({
  1009. dataType: "html",
  1010. 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),
  1011. success: function(d) {}
  1012. });
  1013. }
  1014. //AJAX
  1015. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1016. }
  1017. }
  1018. updateProgressBar();
  1019. // Does it must continue in the same exercise or stop?
  1020. if (actual_student < students.length) {
  1021. actual_student ++;
  1022. run_individual_evaluation();
  1023. } else {
  1024. actual_student = 0;
  1025. // Does it go to next exercise or is it finished?
  1026. if (actual_exercise < selected_exercises.length) {
  1027. actual_exercise++;
  1028. run_individual_evaluation();
  1029. } else {
  1030. //AJAX
  1031. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1032. }
  1033. }
  1034. }
  1035. var original_propositions;
  1036. function get_original_propositions () {
  1037. original_propositions = [];
  1038. var count = 0;
  1039. for (var i = 0; i < exercises.length; i++) {
  1040. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1041. //AJAX
  1042. $.ajax({
  1043. dataType: "html",
  1044. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1045. success: function(d) { // variable "d" has the iLM content
  1046. original_propositions[count] = d; // exercise original content
  1047. count ++;
  1048. if (count == selected_exercises.length) {
  1049. run_individual_evaluation();
  1050. }
  1051. }
  1052. });
  1053. }
  1054. }
  1055. }
  1056. function stop_evaluation () {
  1057. stoped = true;
  1058. //AJAX
  1059. $("#button_start").prop("disabled", false);
  1060. $("#button_stop").prop("disabled", true);
  1061. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1062. $("input:checkbox").attr("disabled", false);
  1063. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1064. clearInterval(var_interval);
  1065. }
  1066. var exercises = [ '; // '
  1067. foreach ($exercises_list as $exercise) {
  1068. print $exercise->id . ',';
  1069. }
  1070. print ' ];';
  1071. print ' var students = [ ';
  1072. foreach ($students_list as $student) {
  1073. print $student->userid . ',';
  1074. }
  1075. print '];';
  1076. print ' var ilms = [';
  1077. foreach ($exercises_list as $exercise) {
  1078. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1079. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1080. }
  1081. print ']';
  1082. print '</script>';
  1083. print '
  1084. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1085. <div class="modal-dialog modal-dialog-centered" role="document">
  1086. <div class="modal-content">
  1087. <div class="modal-header">
  1088. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1089. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1090. <span aria-hidden="true">&times;</span>
  1091. </button>
  1092. </div>
  1093. <div class="modal-body">
  1094. ...
  1095. </div>
  1096. <div class="modal-footer">
  1097. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1098. </div>
  1099. </div>
  1100. </div>
  1101. </div>'; //
  1102. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1103. print '<table id="table-results" class="table table-hover m-t-1">
  1104. <thead>
  1105. <tr id="cols-exercises">
  1106. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1107. </tr>
  1108. </thead>
  1109. <tbody>'; // "
  1110. foreach ($students_list as $student) {
  1111. $user = $DB->get_record('user', array('id' => $student->userid));
  1112. $avatar = new user_picture($user);
  1113. $avatar->courseid = $COURSE->id;
  1114. $avatar->link = true;
  1115. print ' <tr data-student="' . $student->userid . '">
  1116. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1117. </tr>' . "\n"; // "
  1118. }
  1119. print " </tbody>
  1120. </table>\n";
  1121. print $OUTPUT->footer();
  1122. } // function auto_evaluate()
  1123. /// This method moves an iAssign activity
  1124. function move_activity () {
  1125. global $USER, $CFG, $DB, $COURSE;
  1126. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1127. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1128. $update_entry_new_iassign = new stdClass();
  1129. $update_entry_new_iassign->id = $iassign_id;
  1130. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1131. // Update the iassign_statement
  1132. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1133. // Update file context
  1134. $c_i = context_module::instance($this->cm->id);
  1135. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1136. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1137. $path_module = context_course::instance($COURSE->id);
  1138. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1139. $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny);
  1140. if ($context_file) {
  1141. $id_context = $context_file->id;
  1142. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1143. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1144. $context = context_module::instance($USER->cm);
  1145. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  1146. foreach ($files as $value) {
  1147. if ($value->get_filename() != ".") {
  1148. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1149. $newfile = null;
  1150. $destiny_context = context_module::instance($course_module->id);
  1151. $newfile = $fs->create_file_from_string(array('contextid' => $destiny_context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id, 'filepath' => '/', 'filename' => $value->get_filename()), $value->get_content());
  1152. $updateentry = new stdClass();
  1153. $updateentry->id = $iassign_id;
  1154. $updateentry->filesid = $iassign_id;
  1155. $DB->update_record("iassign_statement", $updateentry);
  1156. break;
  1157. }
  1158. }
  1159. }
  1160. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
  1161. redirect($this->return, get_string('moved_activity', 'iassign').' <a href="'.$destiny_url.'">' . get_string('move_activity_access', 'iassign') . '\'' . $course_module->name . '\'</a>', null, \core\output\notification::NOTIFY_SUCCESS);
  1162. exit;
  1163. }
  1164. /// This method duplicates an iAssign activity
  1165. function duplicate_activity () {
  1166. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1167. $id = $this->cm->id;
  1168. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1169. $context = context_module::instance($this->cm->id);
  1170. $contextuser = context_user::instance($USER->id);
  1171. // Get the the iAssign acitivity to be duplicated
  1172. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1173. // Remove the current id of activity
  1174. $id_source_copy = $iassign_statement->id;
  1175. $iassign_statement->id=0;
  1176. // Include prefix (Copy of ...)
  1177. $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
  1178. // Get the information about current author, and add this information in author_modified field
  1179. $author = $DB->get_record("user", array('id' => $USER->id));
  1180. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1181. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1182. // Store the activity in the table
  1183. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1184. // Duplicate activity file
  1185. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1186. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
  1187. foreach ($files as $value) {
  1188. if ($value->get_filename() != ".") {
  1189. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1190. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
  1191. $updateentry = new stdClass();
  1192. $updateentry->id = $id_;
  1193. $updateentry->filesid = $id_;
  1194. // Update the duplicated iLM iAssign with new file id
  1195. $DB->update_record("iassign_statement", $updateentry);
  1196. }
  1197. }
  1198. }
  1199. // log event --------------------------------------------------------------------------------------
  1200. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1201. $this->return_home_course('duplicated_activity');
  1202. exit;
  1203. }
  1204. // / This method gets the content from comment and register it
  1205. function add_comment () {
  1206. global $USER, $DB;
  1207. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1208. $comment = false;
  1209. if ($submission_comment)
  1210. $comment = $this->write_comment_submission();
  1211. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1212. if (!$id_submission) {
  1213. $iassign_submission =
  1214. $DB->get_record("iassign_submission",
  1215. array(
  1216. "iassign_statementid" => $this->activity->get_activity()->id,
  1217. "userid" => $USER->id
  1218. )
  1219. );
  1220. if ($iassign_submission) {
  1221. $id_submission = $iassign_submission->id;
  1222. }
  1223. }
  1224. $content = $this->search_comment_submission($id_submission);
  1225. ob_end_clean();
  1226. header("Connection: close\r\n");
  1227. header("Content-Encoding: none\r\n");
  1228. header('Content-Type: text/html');
  1229. ob_start();
  1230. echo $this->search_comment_submission($id_submission);
  1231. $size = ob_get_length();
  1232. header("Content-Length: $size");
  1233. ob_end_flush();
  1234. flush();
  1235. ob_end_clean();
  1236. // Send email to users:
  1237. $iassign_submission =
  1238. $DB->get_record("iassign_submission",
  1239. array(
  1240. "id" => $id_submission
  1241. )
  1242. );
  1243. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1244. }
  1245. /// This method alerts envolved to new comment sent
  1246. function send_alert_new_comment ($comment, $student_id = -1) {
  1247. global $USER, $DB, $COURSE, $SITE;
  1248. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign');
  1249. $url_curso;
  1250. $url_submissao;
  1251. $text = "<p style='margin-top: 1rem;'>";
  1252. $text .= "<a href=\""
  1253. . new moodle_url('/course/view.php', array('id' => $COURSE->id))
  1254. . "\">" . $COURSE->shortname . "</a> "
  1255. . " &#8811; ";
  1256. $modinfo = get_fast_modinfo($COURSE);
  1257. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1258. if ($modinfo->get_section_info($i)
  1259. && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1260. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1261. $text .= "<a href=\""
  1262. . $url_curso . "#section-" . $modinfo->get_section_info($i)->section . "\">" . get_section_name($COURSE, $modinfo->get_section_info($i)->section)
  1263. . "</a> &#8811; ";
  1264. break;
  1265. }
  1266. }
  1267. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1268. $text .= "<a href=\""
  1269. . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id))
  1270. . "\">"
  1271. . $iassign->name
  1272. . "</a>";
  1273. $text .= " &#8811; ";
  1274. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1275. array(
  1276. 'id' => $this->cm->id,
  1277. 'action' => 'viewsubmission',
  1278. 'iassign_current' => $this->activity->get_activity()->id,
  1279. 'userid_iassign' => $USER->id));
  1280. $text .= "<a href=\""
  1281. . $url_submissao
  1282. . "\">"
  1283. . $this->activity->get_activity()->name
  1284. . "</a>";
  1285. $text .= "</p>";
  1286. $text .= "<div style='margin-left: .5rem;'>";
  1287. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>";
  1288. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>";
  1289. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>";
  1290. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>";
  1291. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': '
  1292. . "<a href=\"" . new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">"
  1293. . $USER->firstname . " " . $USER->lastname
  1294. . "</a>";
  1295. $text .= " - " . userdate(time());
  1296. $text .= "</div><div style='margin: 2rem;'>";
  1297. $text .= $comment;
  1298. $text .= "</div><div>";
  1299. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | ";
  1300. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>";
  1301. $text .= "</div>";
  1302. // Who has to receive?
  1303. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1304. $userfrom = \core_user::get_noreply_user();
  1305. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1306. // other teachers receive also: (excepts the sender)
  1307. foreach ($teachers as $teacher) {
  1308. if ($teacher->id != $USER->id) {
  1309. email_to_user(
  1310. $teacher,
  1311. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1312. $subject,
  1313. "",
  1314. $text,
  1315. '',
  1316. '',
  1317. false,
  1318. $userfrom->email,
  1319. 'Não responda a esta mensagem'
  1320. );
  1321. $message = new \core\message\message();
  1322. $message->component = 'mod_iassign';
  1323. $message->name = 'message';
  1324. $message->userfrom = core_user::get_noreply_user();
  1325. $message->userto = $teacher;
  1326. $message->subject = $subject;
  1327. $message->fullmessage = $text;
  1328. $message->fullmessageformat = FORMAT_MARKDOWN;
  1329. $message->fullmessagehtml = $text;
  1330. $message->smallmessage = $subject;
  1331. $message->notification = 1;
  1332. $message->contexturl = $url_submissao . '#comments';
  1333. $message->contexturlname = $this->activity->get_activity()->name;
  1334. $messageid = message_send($message);
  1335. }
  1336. }
  1337. // and student:
  1338. $student = $DB->get_record('user', array('id' => $student_id));
  1339. $formated_text = str_replace("viewsubmission", "view", $text);
  1340. email_to_user(
  1341. $student,
  1342. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1343. $subject,
  1344. "",
  1345. $formated_text,
  1346. '',
  1347. '',
  1348. false,
  1349. $userfrom->email,
  1350. 'Não responda a esta mensagem'
  1351. );
  1352. $url_student = new moodle_url('/mod/iassign/view.php',
  1353. array(
  1354. 'id' => $this->cm->id,
  1355. 'action' => 'view',
  1356. 'iassign_current' => $this->activity->get_activity()->id));
  1357. $message = new \core\message\message();
  1358. $message->component = 'mod_iassign';
  1359. $message->name = 'message';
  1360. $message->userfrom = core_user::get_noreply_user();
  1361. $message->userto = $student;
  1362. $message->subject = $subject;
  1363. $message->fullmessage = $formated_text;
  1364. $message->fullmessageformat = FORMAT_MARKDOWN;
  1365. $message->fullmessagehtml = $formated_text;
  1366. $message->smallmessage = $subject;
  1367. $message->notification = 1;
  1368. $message->contexturl = $url_student . '#comments';
  1369. $message->contexturlname = $this->activity->get_activity()->name;
  1370. $messageid = message_send($message);
  1371. } else { // a student has sent the comment:
  1372. foreach ($teachers as $teacher) {
  1373. email_to_user(
  1374. $teacher,
  1375. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1376. $subject,
  1377. "",
  1378. $text,
  1379. '',
  1380. '',
  1381. false,
  1382. $userfrom->email,
  1383. 'Não responda a esta mensagem'
  1384. );
  1385. $message = new \core\message\message();
  1386. $message->component = 'mod_iassign';
  1387. $message->name = 'message';
  1388. $message->userfrom = core_user::get_noreply_user();
  1389. $message->userto = $teacher;
  1390. $message->subject = $subject;
  1391. $message->fullmessage = $text;
  1392. $message->fullmessageformat = FORMAT_MARKDOWN;
  1393. $message->fullmessagehtml = $text;
  1394. $message->smallmessage = $subject;
  1395. $message->notification = 1;
  1396. $message->contexturl = $url_submissao . '#comments';
  1397. $message->contexturlname = $this->activity->get_activity()->name;
  1398. $messageid = message_send($message);
  1399. }
  1400. }
  1401. }
  1402. /// This method gets the content from the iLM and register it
  1403. // It could be the "exercise template" (teacher) or an answer (student)
  1404. function get_answer () {
  1405. global $USER, $CFG, $DB, $OUTPUT;
  1406. $id = $this->cm->id;
  1407. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1408. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1409. if ($submission_ajax == 1) ob_start();
  1410. $comment = false;
  1411. if ($submission_comment)
  1412. $comment = $this->write_comment_submission();
  1413. // receives data of iLM using the current activity
  1414. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1415. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1416. // receives data of submission of current activity
  1417. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1418. // receives post and get
  1419. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1420. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1421. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1422. $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)
  1423. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1424. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1425. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1426. $msg = '';
  1427. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1428. $newentry = new stdClass();
  1429. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1430. $newentry->userid = $this->userid_iassign;
  1431. $newentry->timecreated = time();
  1432. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1433. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1434. $DB->insert_record("iassign_allsubmissions", $newentry);
  1435. }
  1436. // Feedback
  1437. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1438. $str_action = "view"; // repeat
  1439. if (strtolower($iassign_ilm->name) == "igeom") {
  1440. }
  1441. $title = get_string('evaluate_iassign', 'iassign');
  1442. print $OUTPUT->header();
  1443. print $OUTPUT->box_start();
  1444. // Action = { view ; repeat ; viewsubmission }
  1445. // * '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")
  1446. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1447. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1448. $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;
  1449. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1450. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1451. print '<table width=100% >';
  1452. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1453. //TODO alterar aqui???
  1454. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1455. // empty_answer_post = No solution was posted.
  1456. if ($comment)
  1457. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1458. else
  1459. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1460. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1461. } else {
  1462. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1463. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1464. // Correct answer!!
  1465. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1466. $this->write_solution = 1; //
  1467. $status = 3;
  1468. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1469. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1470. // log record
  1471. $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;
  1472. // Trigger module viewed event.
  1473. $event = \mod_iassign\event\submission_created::create(array(
  1474. 'objectid' => $this->iassign->id,
  1475. 'context' => $this->context,
  1476. 'other' => $info
  1477. ));
  1478. $event->add_record_snapshot('course', $this->course);
  1479. $event->trigger();
  1480. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1481. // Wrong answer...: get_answer_incorrect
  1482. $status = 2;
  1483. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1484. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1485. // log record
  1486. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1487. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1488. // Trigger module viewed event.
  1489. $event = \mod_iassign\event\submission_created::create(array(
  1490. 'objectid' => $this->iassign->id,
  1491. 'context' => $this->context,
  1492. 'other' => $info
  1493. ));
  1494. $event->add_record_snapshot('course', $this->course);
  1495. $event->trigger();
  1496. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1497. // Presents to the learner the result of the automatic evaluate?
  1498. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1499. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1500. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1501. print '<tr>';
  1502. // log record
  1503. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1504. // Trigger module viewed event.
  1505. $event = \mod_iassign\event\submission_created::create(array(
  1506. 'objectid' => $this->iassign->id,
  1507. 'context' => $this->context,
  1508. 'other' => $info
  1509. ));
  1510. $event->add_record_snapshot('course', $this->course);
  1511. $event->trigger();
  1512. } else { // yes!!!
  1513. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1514. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1515. print '<tr>';
  1516. print $msg;
  1517. }
  1518. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1519. $status = 1;
  1520. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1521. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1522. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1523. print '<tr>';
  1524. // log record
  1525. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1526. $event = \mod_iassign\event\submission_created::create(array(
  1527. 'objectid' => $this->iassign->id,
  1528. 'context' => $this->context,
  1529. 'other' => $info
  1530. ));
  1531. $event->add_record_snapshot('course', $this->course);
  1532. $event->trigger();
  1533. } // if ($iassign_ilm->evaluate == 1)
  1534. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1535. print '</tr></table>';
  1536. print $OUTPUT->box_end();
  1537. // add or update evaluate
  1538. if ($this->write_solution == 1) {
  1539. $timenow = time();
  1540. // new record
  1541. if (!$iassign_submission) {
  1542. $newentry = new stdClass();
  1543. $newentry->userid = $this->userid_iassign;
  1544. // $newentry->userid = $USER->id;
  1545. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1546. $newentry->timecreated = $timenow;
  1547. $newentry->timemodified = $timenow;
  1548. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1549. $newentry->grade = round($grade_student, 2);
  1550. $newentry->status = $status;
  1551. $newentry->experiment = 1;
  1552. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1553. print_error('error_insert', 'iassign');
  1554. } else {
  1555. // Trigger module viewed event.
  1556. $event = \mod_iassign\event\submission_created::create(array(
  1557. 'objectid' => $this->iassign->id,
  1558. 'context' => $this->context
  1559. ));
  1560. $event->add_record_snapshot('course', $this->course);
  1561. $event->trigger();
  1562. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1563. }
  1564. } elseif ($iassign_submission->status != 3) {
  1565. $newentry = new stdClass();
  1566. $newentry->id = $iassign_submission->id;
  1567. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1568. $newentry->userid = $iassign_submission->userid;
  1569. $newentry->timecreated = $iassign_submission->timecreated;
  1570. $newentry->timemodified = $timenow;
  1571. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1572. $newentry->grade = round($grade_student, 2);
  1573. $newentry->status = $status;
  1574. $newentry->experiment = $iassign_submission->experiment + 1;
  1575. if (!$DB->update_record("iassign_submission", $newentry)) {
  1576. print_error('error_update', 'iassign');
  1577. //D depurar...
  1578. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1579. //D $fp = fopen("teste1.txt","w");
  1580. //D fwrite($fp,$stringAux);
  1581. } else {
  1582. // Trigger module viewed event.
  1583. $event = \mod_iassign\event\submission_updated::create(array(
  1584. 'objectid' => $this->iassign->id,
  1585. 'context' => $this->context
  1586. ));
  1587. $event->add_record_snapshot('course', $this->course);
  1588. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1589. }
  1590. } else {
  1591. if ($return_get_answer == 1) {
  1592. $newentry = new stdClass();
  1593. $newentry->id = $iassign_submission->id;
  1594. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1595. $newentry->userid = $iassign_submission->userid;
  1596. $newentry->timecreated = $iassign_submission->timecreated;
  1597. $newentry->timemodified = $timenow;
  1598. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1599. $newentry->grade = round($grade_student, 2);
  1600. $newentry->status = $status;
  1601. $newentry->experiment = $iassign_submission->experiment + 1;
  1602. if (!$DB->update_record("iassign_submission", $newentry))
  1603. print_error('error_update', 'iassign');
  1604. else {
  1605. $event = \mod_iassign\event\submission_updated::create(array(
  1606. 'objectid' => $this->iassign->id,
  1607. 'context' => $this->context
  1608. ));
  1609. $event->add_record_snapshot('course', $this->course);
  1610. $event->trigger();
  1611. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1612. print $OUTPUT->box_start();
  1613. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1614. print $OUTPUT->box_end();
  1615. }
  1616. } elseif ($return_get_answer == 2) {
  1617. print $OUTPUT->box_start();
  1618. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1619. print $OUTPUT->box_end();
  1620. } else {
  1621. print $OUTPUT->box_start();
  1622. print "
  1623. <script type='text/javascript'>
  1624. //<![CDATA[
  1625. function overwrite () {
  1626. document.formEnvio.return_get_answer.value = 1;
  1627. document.formEnvio.submit();
  1628. }
  1629. function nooverwrite () {
  1630. document.formEnvio.return_get_answer.value = 2;
  1631. document.formEnvio.submit();
  1632. }
  1633. //]]>
  1634. </script>";
  1635. $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;
  1636. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1637. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1638. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1639. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1640. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1641. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1642. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1643. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1644. <input type='hidden' name='return_get_answer'/> ";
  1645. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1646. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1647. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1648. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1649. print " </form>";
  1650. print $OUTPUT->box_end();
  1651. }
  1652. }
  1653. } // if ($this->write_solution == 1)
  1654. print $OUTPUT->footer();
  1655. if ($submission_ajax == 1) {
  1656. ob_end_clean();
  1657. print 'OK';
  1658. }
  1659. die();
  1660. } // function get_answer()
  1661. /// Export in file the answer of student.
  1662. function export_file_answer () {
  1663. global $DB;
  1664. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1665. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1666. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1667. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1668. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1669. $extensions = explode(",", $iassign_ilm->extension);
  1670. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1671. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1672. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1673. header("Pragma: public");
  1674. header("Expires: 0");
  1675. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1676. header("Cache-Control: private", false);
  1677. header("Content-Type: document/unknown");
  1678. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1679. set_time_limit(0);
  1680. print($iassign_submission->answer);
  1681. exit;
  1682. } // function export_file_answer()
  1683. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1684. // @calledby $this->export_package_answer()
  1685. //TODO Precisa terminar! //TODO_HTML
  1686. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1687. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1688. <head>
  1689. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1690. $str_html .= " </head>
  1691. <body>\n";
  1692. $tam = sizeof($array_iassign_name);
  1693. for ($ii=0; $ii<$tam; $ii++) {
  1694. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1695. }
  1696. $str_html .= "
  1697. </body>\n</html>";
  1698. return $str_html;
  1699. }
  1700. /// Export an package (zip) with all answer of students
  1701. // @calledby $this->action()
  1702. function export_package_answer () {
  1703. global $DB, $CFG, $OUTPUT;
  1704. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1705. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1706. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1707. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1708. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1709. $userid = optional_param('userid', NULL, PARAM_INT);
  1710. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1711. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1712. //TODO_HTML echo "username=$username<br/>"; exit;
  1713. $current_date = date('Y_m_d_H');
  1714. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1715. // If temporary directory under Moodle data does not exists => create it
  1716. if (!is_dir($diretorio)) {
  1717. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1718. // created directory with permissions to be seen by everyone
  1719. }
  1720. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1721. if (!is_writable($diretorio)) { // send a highlighted message!
  1722. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1723. exit; // just in case
  1724. }
  1725. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1726. $zip = new zip_archive(); // create ZIP
  1727. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1728. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1729. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1730. $vet_student_filename = array();
  1731. $vet_student_content = array();
  1732. foreach ($iassign_statements as $iassign_statement) {
  1733. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1734. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1735. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1736. $extensions = explode(",", $iassign_ilm->extension);
  1737. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1738. if ($iassign_submission) {
  1739. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1740. $student_content = $iassign_submission->answer;
  1741. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1742. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1743. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1744. if ($resp) {
  1745. $vet_student_filename[] = $student_filename;
  1746. $vet_student_content[] = $student_content;
  1747. }
  1748. else { // send a highlighted message!
  1749. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1750. exit; // just in case
  1751. }
  1752. }
  1753. }
  1754. $zip->close(); // close the ZIP file
  1755. if (count($vet_student_filename)>0) {
  1756. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1757. $result_tf = $vet_result[0];
  1758. $filenameZip = $vet_result[1]->filename;
  1759. }
  1760. iassign_utils::download_file($zip_filename); // download the ZIP file
  1761. exit;
  1762. } // function export_package_answer()
  1763. /// Editing status of interactive activities
  1764. function edit_status () {
  1765. global $USER, $DB, $OUTPUT;
  1766. $newentry = new stdClass();
  1767. $newentry->id = $this->iassign_submission_current;
  1768. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1769. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1770. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1771. $newentry->status = $iassign_submission->status;
  1772. $newentry->teacher = $USER->id;
  1773. if (!$DB->update_record('iassign_submission', $newentry))
  1774. print_error('error_update', 'iassign');
  1775. else {
  1776. // Trigger module viewed event.
  1777. $event = \mod_iassign\event\submission_updated::create(array(
  1778. 'objectid' => $this->iassign->id,
  1779. 'context' => $this->context
  1780. ));
  1781. $event->add_record_snapshot('course', $this->course);
  1782. $event->trigger();
  1783. $this->action = 'viewsubmission';
  1784. $this->view_iassign_current();
  1785. } // if (!$DB->update_record('iassign_submission', $newentry))
  1786. } // function edit_status()
  1787. /// Editing grade of interactive activities
  1788. function edit_grade () {
  1789. global $USER, $DB, $OUTPUT;
  1790. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1791. if ($newgrade && $newgrade >= 0) {
  1792. $newentry = new stdClass();
  1793. $newentry->id = $this->iassign_submission_current;
  1794. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1795. $newentry->teacher = $USER->id;
  1796. if (!$DB->update_record('iassign_submission', $newentry))
  1797. print_error('error_update', 'iassign');
  1798. else {
  1799. // Trigger module viewed event.
  1800. $event = \mod_iassign\event\submission_updated::create(array(
  1801. 'objectid' => $this->iassign->id,
  1802. 'context' => $this->context
  1803. ));
  1804. $event->add_record_snapshot('course', $this->course);
  1805. $event->trigger();
  1806. }
  1807. } // if ($newgrade >= 0)
  1808. $this->action = 'viewsubmission';
  1809. $this->view_iassign_current();
  1810. }
  1811. /// Add or Edit interactive activities
  1812. // Get here when editing form and and submitted form data
  1813. // @calledby $this->action()
  1814. function add_edit_iassign () {
  1815. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1816. require_once('iassign_form.php');
  1817. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1818. $iassignid = $this->iassign->id;
  1819. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1820. $param->action = $this->action; // hidden
  1821. $param->id = $id; // hidden
  1822. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1823. $COURSE->cm = $id;
  1824. $COURSE->iassignid = $iassignid;
  1825. $COURSE->iassign_file_id = NULL;
  1826. $context = context_module::instance($this->cm->id);
  1827. $contextuser = context_user::instance($USER->id);
  1828. $component = 'mod_iassign';
  1829. $filearea = 'exercise';
  1830. if (!empty($this->iassign_current))
  1831. $COURSE->iassign_id = $this->iassign_current;
  1832. else
  1833. $COURSE->iassign_id = 0;
  1834. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1835. if ($this->action == 'add') {
  1836. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1837. $params_temp = array('iassignid' => $iassignid);
  1838. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1839. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1840. $total_of_activities = count($iassign_statement);
  1841. $param->iassignid = $iassignid;
  1842. $param->name = "";
  1843. $param->oldname = "";
  1844. $param->type_iassign = 3;
  1845. $param->proposition = "";
  1846. $author = $DB->get_record("user", array("id" => $USER->id));
  1847. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1848. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1849. $param->author = $param->author_name;
  1850. $param->author_modified = $param->author_modified_name;
  1851. $COURSE->iassign_list = array();
  1852. $param->iassign_list = array();
  1853. if ($iassign_statement) {
  1854. foreach ($iassign_statement as $iassign) {
  1855. $iassignid = $iassign->id;
  1856. $param->iassign_list[$iassignid] = 0;
  1857. $COURSE->iassign_list[$iassignid] = new stdClass();
  1858. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1859. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1860. $COURSE->iassign_list[$iassignid]->enable = 1;
  1861. } // foreach ($iassign_statement as $iassign)
  1862. }
  1863. $param->iassign_ilmid = 0;
  1864. $param->file = 0;
  1865. $param->fileold = 0;
  1866. $param->filename = "";
  1867. $param->grade = $iassign_data->grade;
  1868. $param->timemodified = time();
  1869. $param->timecreated = time();
  1870. $param->timeavailable = $iassign_data->timeavailable;
  1871. $param->timedue = $iassign_data->timedue;
  1872. $param->preventlate = $iassign_data->preventlate;
  1873. $param->test = $iassign_data->test;
  1874. $param->special_param1 = 0;
  1875. $param->visible = 1;
  1876. $param->max_experiment = $iassign_data->max_experiment;
  1877. $param->dependency = 0;
  1878. $param->automatic_evaluate = 1;
  1879. $param->show_answer = 1;
  1880. } // if ($this->action == 'add')
  1881. elseif ($this->action == 'edit') {
  1882. $COURSE->iassign_list = array();
  1883. $this_activity = $this->activity->get_activity();
  1884. if ($this_activity != null) { // first enter here: fill form data
  1885. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1886. $param->iassign_id = $iassign_statement_current->id; // oculto
  1887. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1888. $param->name = $iassign_statement_current->name;
  1889. $param->oldname = $iassign_statement_current->name;
  1890. $param->type_iassign = $iassign_statement_current->type_iassign;
  1891. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1892. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1893. $param->author_name = $iassign_statement_current->author_name; // oculto
  1894. $param->author = $iassign_statement_current->author_name;
  1895. $author = $DB->get_record("user", array('id' => $USER->id));
  1896. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1897. $param->author_modified = $param->author_modified_name;
  1898. $dependency = explode(';', $iassign_statement_current->dependency);
  1899. $param->iassign_list = array();
  1900. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1901. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1902. $array_dependency = array();
  1903. $subdependency = "";
  1904. $sub_subdependency = "";
  1905. // Dependents on this exercise
  1906. if ($iassign_statement_dependency) {
  1907. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1908. // to whom this exercise depends
  1909. foreach ($inter as $tmp)
  1910. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1911. $list_dependency = $subdependency . $sub_subdependency;
  1912. $array_dependency = explode(";", $list_dependency);
  1913. }
  1914. // Get all activities in the same iAssigment block:
  1915. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  1916. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1917. $total_of_activities = count($all_others_iassign_statement) + 1;
  1918. $inter = array();
  1919. if ($all_others_iassign_statement) {
  1920. foreach ($all_others_iassign_statement as $iassign)
  1921. if (in_array($iassign->id, $dependency))
  1922. $inter[] = $iassign->id;
  1923. }
  1924. if ($all_others_iassign_statement) {
  1925. foreach ($all_others_iassign_statement as $iassign) {
  1926. $iassignid = $iassign->id;
  1927. $COURSE->iassign_list[$iassignid] = new stdClass();
  1928. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1929. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1930. if (in_array($iassignid, $dependency))
  1931. $param->iassign_list[$iassignid] = 1;
  1932. else
  1933. $param->iassign_list[$iassignid] = 0;
  1934. if (in_array($iassignid, $array_dependency))
  1935. $COURSE->iassign_list[$iassignid]->enable = 0;
  1936. else
  1937. $COURSE->iassign_list[$iassignid]->enable = 1;
  1938. } // foreach ($all_others_iassign_statement as $iassign)
  1939. } // if ($all_others_iassign_statement)
  1940. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  1941. $param->fileold = 0;
  1942. $param->filesid = 0;
  1943. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1944. $param->filename = '';
  1945. $param->grade = $iassign_statement_current->grade;
  1946. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  1947. $param->timeavailable = $iassign_statement_current->timeavailable;
  1948. $param->timedue = $iassign_statement_current->timedue;
  1949. $param->preventlate = $iassign_statement_current->preventlate;
  1950. $param->test = $iassign_statement_current->test;
  1951. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  1952. $param->position = $iassign_statement_current->position; // hidden
  1953. $param->visible = $iassign_statement_current->visible;
  1954. $param->max_experiment = $iassign_statement_current->max_experiment;
  1955. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1956. $param->show_answer = $iassign_statement_current->show_answer;
  1957. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1958. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id);
  1959. if ($files) {
  1960. foreach ($files as $file) {
  1961. if ($file->get_filename() != '.') {
  1962. $param->filename = $file->get_filename();
  1963. $param->file = $file->get_id();
  1964. $param->fileold = $file->get_id();
  1965. $COURSE->iassign_file_id = $file->get_id();
  1966. }
  1967. }
  1968. }
  1969. //TODO //MOOC2014 -- inicio
  1970. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1971. //D if ($iassign_ilm_configs) {
  1972. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1973. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1974. //D } //MOOC2014 -- fim
  1975. } // if ($this_activity != null)
  1976. } // elseif ($this->action == 'edit')
  1977. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1978. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1979. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1980. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1981. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1982. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1983. $param->position = $total_of_activities;
  1984. // Create form and associate its data
  1985. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  1986. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  1987. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  1988. if (isset($param->iassign_ilmid)) {
  1989. // array is additional atributes to 'form'
  1990. // 'special_param1 == 1' => script of iGeom : <select class="custom-select" name="special_param1" id="id_special_param1"> "Assignment with script(algorithm)? (Applicable only to iGeom iLM)"
  1991. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  1992. }
  1993. else {
  1994. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  1995. }
  1996. $mform->set_data($param); // define data in the form
  1997. if ($mform->is_cancelled()) {
  1998. $this->return_home_course('iassign_cancel');
  1999. exit;
  2000. }
  2001. else { // else if ($mform->is_cancelled())
  2002. $result = $mform->get_data();
  2003. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  2004. if ($result) {
  2005. $result->context = $context;
  2006. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  2007. $result->grade = 0;
  2008. if ($result->type_iassign == 1) {
  2009. $result->automatic_evaluate = 0;
  2010. $result->show_answer = 0;
  2011. }
  2012. elseif ($result->automatic_evaluate == 0)
  2013. $result->show_answer = 0;
  2014. // $_POST['iassign_list']
  2015. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  2016. if ($result->iassign_list) {
  2017. foreach ($result->iassign_list as $key => $value)
  2018. $result->dependency .= $key . ';';
  2019. }
  2020. else
  2021. $result->dependency = 0;
  2022. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  2023. //TODO Then get it directly from the form data $_POST!
  2024. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  2025. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  2026. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  2027. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  2028. if ($this->action == 'add') {
  2029. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  2030. if ($iassign_statement_name) {
  2031. $this->return_home_course('error_iassign_name');
  2032. die();
  2033. }
  2034. // Really insert the new iActivity in table '*_iassign_statement'
  2035. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  2036. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  2037. // Trigger module viewed event.
  2038. $event = \mod_iassign\event\iassign_created::create(array(
  2039. 'objectid' => $iassignid,
  2040. 'context' => $context
  2041. ));
  2042. $event->add_record_snapshot('course', $this->course);
  2043. $event->trigger();
  2044. $this->return_home_course('iassign_add');
  2045. } // if ($this->action == 'add')
  2046. elseif ($this->action == 'edit') {
  2047. $iassignid = $this->activity->update_iassign($result);
  2048. $this->activity->update_calendar($iassignid, $result->oldname);
  2049. // Trigger module viewed event.
  2050. $event = \mod_iassign\event\iassign_updated::create(array(
  2051. 'objectid' => $iassignid,
  2052. 'context' => $context
  2053. ));
  2054. $event->add_record_snapshot('course', $this->course);
  2055. $event->trigger();
  2056. $this->return_home_course('iassign_update');
  2057. } // elseif ($this->action == 'edit')
  2058. die();
  2059. } // if ($result)
  2060. } // else if ($mform->is_cancelled())
  2061. print $OUTPUT->header();
  2062. $mform->display();
  2063. print $OUTPUT->footer();
  2064. die();
  2065. } // function add_edit_iassign()
  2066. /// Search for dependencies
  2067. function search_dependency ($search_iassing_id, $iassign_statement) {
  2068. global $DB, $OUTPUT;
  2069. $dependency = "";
  2070. if ($iassign_statement)
  2071. foreach ($iassign_statement as $iassign) {
  2072. $inter_dependency = explode(';', $iassign->dependency);
  2073. if (in_array($search_iassing_id, $inter_dependency)) {
  2074. $dependency .= $iassign->id . ";";
  2075. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2076. } // if (in_array($search_iassing_id, $inter_dependency))
  2077. } // foreach ($iassign_statement as $iassign)
  2078. return $dependency;
  2079. }
  2080. /// Search for "sub"dependency
  2081. function search_sub_dependency ($search_iassing_id) {
  2082. global $DB, $OUTPUT;
  2083. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2084. $dependency = "";
  2085. if ($iassign_statement) {
  2086. $inter_dependency = explode(';', $iassign_statement->dependency);
  2087. foreach ($inter_dependency as $tmp) {
  2088. if ($tmp != 0)
  2089. $dependency .= $tmp . ";";
  2090. $dependency .= $this->search_sub_dependency($tmp);
  2091. } // foreach ($inter_dependency as $tmp)
  2092. } // if ($iassign_statement)
  2093. return $dependency;
  2094. }
  2095. // Warning message
  2096. static function warning_message_iassign ($strcode) {
  2097. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2098. }
  2099. /// Update grade of iAssign
  2100. // Called always any iAssign activity is created
  2101. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2102. static function update_grade_iassign ($iassignid) {
  2103. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2104. require_once($CFG->libdir . '/gradelib.php');
  2105. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2106. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2107. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2108. // Each iAssign item is associated with one item on the "gradebook"
  2109. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2110. //$sum_grade = 0;
  2111. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2112. //foreach($grade as $tmp) {
  2113. // $sum_grade += $tmp->grade;
  2114. // }
  2115. //1 Solution 1
  2116. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2117. //1 $sum_grade = 0; //1
  2118. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2119. //2 Solution 2
  2120. $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
  2121. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2122. if (key($array_sum_grade))
  2123. $sum_grade = key($array_sum_grade); //2
  2124. else
  2125. $sum_grade = 0; //2
  2126. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2127. $grades = NULL;
  2128. $params_temp = array('itemname' => $grade_iassign->name);
  2129. $params_temp['iteminstance'] = $iassignid;
  2130. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2131. //2016 if ($sum_grade != 0) {
  2132. $params_temp['grademax'] = $sum_grade;
  2133. $params_temp['rawgrademax'] = $sum_grade;
  2134. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2135. $params_temp['grademin'] = 0;
  2136. // @calls /lib/gradelib.php: call to grade_item->insert()
  2137. //TODO: is there any error here in Moodle version 3.0?
  2138. //TODO: Incorrect property 'grademax' found when inserting grade object
  2139. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2140. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2141. }
  2142. /// Update grade of student
  2143. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2144. global $CFG, $DB, $OUTPUT;
  2145. require_once($CFG->libdir . '/gradelib.php');
  2146. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2147. // Review all the student submission for this iAssign activity
  2148. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2149. $total_grade = 0;
  2150. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2151. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2152. if ($iassign_submission)
  2153. $total_grade += $iassign_submission->grade;
  2154. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2155. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2156. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2157. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2158. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2159. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2160. $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
  2161. if (key($array_sum_grade))
  2162. $sum_grade = key($array_sum_grade); //2
  2163. else
  2164. $sum_grade = 0; //2
  2165. $grades['userid'] = $userid;
  2166. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2167. $params_temp = array('itemname' => $grade_iassign->name);
  2168. $params_temp['iteminstance'] = $iassignid;
  2169. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2170. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2171. $params_temp['grademax'] = $sum_grade;
  2172. $params_temp['rawgrademax'] = $sum_grade;
  2173. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2174. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2175. }
  2176. /// Display caption of icons
  2177. function view_legend_icons () {
  2178. global $USER, $CFG, $DB, $OUTPUT;
  2179. $id = $this->cm->id;
  2180. if ($this->action == 'print')
  2181. print '<table border=1 width=100%><tr>';
  2182. else
  2183. print '<table width=100%><tr>';
  2184. print '<td >';
  2185. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2186. if ($this->action != 'print') {
  2187. $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>";
  2188. $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>";
  2189. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2190. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2191. } // if ($this->action != 'print')
  2192. print '</tr></table>' . "\n";
  2193. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2194. print '</td></tr></table>' . "\n";
  2195. } // function view_legend_icons()
  2196. /// Display activity current
  2197. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2198. function view_iassign_current () {
  2199. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2200. $id = $this->cm->id;
  2201. $iassignid = $this->iassign->id;
  2202. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2203. $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
  2204. // 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 ...
  2205. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2206. if (!$iassign_statement_activity_item) {
  2207. print $OUTPUT->header();
  2208. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2209. print $OUTPUT->footer();
  2210. exit;
  2211. }
  2212. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2213. $ilm_name = '';
  2214. if ($ilm->ilm)
  2215. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2216. // 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
  2217. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2218. // log record
  2219. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2220. //Trigger module viewed event.
  2221. $event = \mod_iassign\event\submission_viewed::create(array(
  2222. 'objectid' => $iassign->id,
  2223. 'context' => $this->context,
  2224. 'other' => $info
  2225. ));
  2226. $event->add_record_snapshot('course', $this->course);
  2227. $event->trigger();
  2228. // Search of iLM data used in the current activity
  2229. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2230. // Add actual activity to navbar:
  2231. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2232. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2233. print $OUTPUT->header();
  2234. if ($this->action == 'viewsubmission') {
  2235. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2236. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2237. else
  2238. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2239. } else {
  2240. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2241. }
  2242. if ($iassign_submission)
  2243. $this->update_comment($iassign_submission->id);
  2244. $file = $iassign_statement_activity_item->id;
  2245. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2246. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2247. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2248. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2249. $this->bottonPost = 0; // hide submit button
  2250. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2251. $this->view_iassign = false; // disable visualization of activity
  2252. $repeat = "";
  2253. $last_iassign = "";
  2254. $student_answer = "";
  2255. $comment = "";
  2256. // *** Teacher access (view learner's submission)
  2257. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2258. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2259. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2260. // ---> access teacher for test
  2261. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2262. $this->bottonPost = 1;
  2263. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2264. $this->activity->view_dates();
  2265. $USER->iassignEdit = $this->bottonPost;
  2266. $this->activity->show_info_iassign();
  2267. if ($iassign_submission) {
  2268. //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;
  2269. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2270. } else {
  2271. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2272. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2273. }
  2274. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2275. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2276. // Prepare tags to present the iLM
  2277. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2278. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2279. // *** (end) Teacher access (view the activity)
  2280. // *** Teacher access (view learner's submission to the activity)
  2281. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2282. // It is teacher or 'nonediting teacher' that can evaluate
  2283. // ----> area teacher evaluate
  2284. $row = optional_param('row', 0, PARAM_INT);
  2285. $column = optional_param('column', 0, PARAM_INT);
  2286. $link_next = iassign_icons::insert('right_disable');
  2287. $link_previous = iassign_icons::insert('left_disable');
  2288. $link_up = iassign_icons::insert('up_disable');
  2289. $link_down = iassign_icons::insert('down_disable');
  2290. // next_activity
  2291. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2292. $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);
  2293. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2294. }
  2295. // previous_activity
  2296. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2297. $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);
  2298. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2299. }
  2300. // previous_student
  2301. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2302. $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);
  2303. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2304. }
  2305. // next_student
  2306. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2307. $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);
  2308. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2309. }
  2310. if ($iassign_submission) {
  2311. $student_answer = $iassign_submission->answer;
  2312. }
  2313. $last_iassign = get_string('last_iassign', 'iassign');
  2314. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2315. // Messages related to due date (and user role)
  2316. $this->activity->view_dates();
  2317. print $OUTPUT->box_start();
  2318. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2319. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2320. print $OUTPUT->user_picture($user_data);
  2321. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2322. print '</td>' . "\n";
  2323. print '<td width=20% align=right>' . "\n";
  2324. print '<table width=50 cellpadding="0">';
  2325. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2326. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2327. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2328. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2329. print '</table>' . "\n";
  2330. print '</td></tr></table>' . "\n";
  2331. print $OUTPUT->box_end();
  2332. print $OUTPUT->box_start();
  2333. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2334. print '<td width=60% valign="top">' . "\n";
  2335. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2336. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2337. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2338. $resp = get_string('yes');
  2339. else
  2340. $resp = get_string('no');
  2341. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2342. if ($iassign_statement_activity_item->show_answer == 1)
  2343. $resp = get_string('yes');
  2344. else
  2345. $resp = get_string('no');
  2346. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2347. print '</td>';
  2348. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2349. print '<td width=40% valign="top" align="left">';
  2350. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2351. // check status of solution sent by the student
  2352. if ($iassign_submission) {
  2353. switch ($iassign_submission->status) {
  2354. case 3 :
  2355. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2356. break;
  2357. case 2 :
  2358. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2359. break;
  2360. case 1 :
  2361. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2362. break;
  2363. default :
  2364. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2365. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2366. } // switch ($iassign_submission->status)
  2367. }
  2368. else { // if ($iassign_submission)
  2369. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2370. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2371. }
  2372. // update_status
  2373. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2374. $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);
  2375. print " <script type='text/javascript'>
  2376. //<![CDATA[
  2377. function overwriteStatus (newstatus) {
  2378. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2379. document.formEditStatus.return_status.value=newstatus;
  2380. document.formEditStatus.submit();
  2381. }
  2382. else
  2383. document.formEditStatus.return_status.value=-1;
  2384. }
  2385. //]]>
  2386. </script>";
  2387. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2388. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2389. 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";
  2390. print " <input type='hidden' name='return_status'>\n";
  2391. print "</form>\n";
  2392. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2393. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2394. $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);
  2395. print "
  2396. <script type='text/javascript'>
  2397. //<![CDATA[
  2398. function overwriteGrade (newgrade,maxgrade) {
  2399. if (newgrade<0 || newgrade>maxgrade) {
  2400. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2401. document.formEditGrade.return_grade.value=-1;
  2402. document.formEditGrade.submit();
  2403. }
  2404. else {
  2405. document.formEditGrade.return_grade.value=newgrade;
  2406. document.formEditGrade.submit();
  2407. }
  2408. }
  2409. //]]>
  2410. </script>";
  2411. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2412. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2413. print " <input type='text' name='grade' size='6'>";
  2414. print " <input type='hidden' name='return_grade'> ";
  2415. 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";
  2416. print "</form>";
  2417. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2418. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2419. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2420. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2421. if ($teacher)
  2422. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2423. } // if ($iassign_submission->experiment > 0)
  2424. print '</td>';
  2425. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2426. print '</tr></table>';
  2427. print $OUTPUT->box_end();
  2428. $USER->iassignEdit = $this->bottonPost;
  2429. print activity::toggle_columns_script();
  2430. if ($iassign_submission && $allow_resubmission) {
  2431. // Put the iLM to
  2432. print $OUTPUT->box_start();
  2433. print '<p><strong>' . $last_iassign . '</strong></p>';
  2434. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2435. $enderecoPOST = "";
  2436. // Prepare tags to present the iLM
  2437. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2438. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2439. print $OUTPUT->box_end();
  2440. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2441. // ATTENTION: exception used by iGeom (exercise with "script")
  2442. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2443. if (substr($ilm_name, 0, 5)=="igeom") {
  2444. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2445. $loadTeacherActivity = true;
  2446. }
  2447. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2448. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2449. print activity::toggle_columns_script();
  2450. // Prepare tags to present the iLM
  2451. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2452. }
  2453. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2454. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2455. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2456. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2457. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2458. // *** (end) Teacher access (view learner's submission to the activity)
  2459. // *** Student access (view the activity)
  2460. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2461. // It could be the learner (he could send or resend the activity)
  2462. // ---> access student
  2463. $time_now = time();
  2464. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2465. // activity of type example - not submit button for submission
  2466. $this->view_iassign = true;
  2467. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2468. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2469. // activity of type test - iLM automatic evaluator - submit button for submission
  2470. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2471. $this->bottonPost = 1;
  2472. $this->view_iassign = true;
  2473. } else
  2474. $this->view_iassign = false;
  2475. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2476. // activity of type exercise (learner can send his answer, if yet open...)
  2477. $this->view_iassign = true;
  2478. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2479. $this->view_iassign = false;
  2480. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2481. $this->bottonPost = 1; // allow the submit button
  2482. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2483. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2484. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2485. if (!$iassign_submission) {
  2486. $str_iassign_submission_id = '';
  2487. $str_iassign_submission_answer = '';
  2488. }
  2489. else {
  2490. $str_iassign_submission_id = $iassign_submission->id;
  2491. $str_iassign_submission_answer = $iassign_submission->answer;
  2492. }
  2493. if ($this->action != 'repeat') {
  2494. $repeat = "<a href='view.php?action=repeat&id="
  2495. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2496. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2497. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2498. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2499. }
  2500. $this->bottonPost = 1;
  2501. $this->write_solution = 1; // can register his submission
  2502. $student_answer = $str_iassign_submission_answer;
  2503. }
  2504. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2505. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2506. $last_iassign = get_string('last_iassign', 'iassign');
  2507. if ($iassign_submission) {
  2508. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2509. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2510. $student_answer = $iassign_submission->answer;
  2511. } else {
  2512. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2513. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2514. }
  2515. }
  2516. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2517. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2518. $this->bottonPost = 1;
  2519. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2520. } else {
  2521. $last_iassign = get_string('last_iassign', 'iassign');
  2522. if ($iassign_submission) {
  2523. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2524. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2525. $student_answer = $iassign_submission->answer;
  2526. } else {
  2527. // Symbol of "redo activity"
  2528. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2529. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2530. }
  2531. }
  2532. } // elseif ($iassign_statement_activity_item->test == 1)
  2533. elseif ($iassign_statement_activity_item->test == 0)
  2534. $this->view_iassign = false;
  2535. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2536. if ($iassign_submission)
  2537. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2538. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2539. else
  2540. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2541. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2542. $this->activity->view_dates();
  2543. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2544. print $OUTPUT->box_start();
  2545. print '<table width=100% border=0 valign="top">' . "\n";
  2546. print '<tr><td width=60% valign="top">' . "\n";
  2547. $flag_dependency = true;
  2548. if ($iassign_statement_activity_item->type_iassign == 3) {
  2549. if ($iassign_statement_activity_item->dependency == 0) {
  2550. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2551. } else {
  2552. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2553. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2554. foreach ($dependencys as $dependency) {
  2555. if ($dependency) {
  2556. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2557. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2558. if ($dependencysubmissions) {
  2559. if ($dependencysubmissions->status == 3)
  2560. $icon = iassign_icons::insert('correct');
  2561. elseif ($dependencysubmissions->status == 2) {
  2562. $icon = iassign_icons::insert('incorrect');
  2563. $flag_dependency = false;
  2564. } elseif ($dependencysubmissions->status == 1) {
  2565. $icon = iassign_icons::insert('post');
  2566. $flag_dependency = false;
  2567. } elseif ($dependencysubmissions->status == 0) {
  2568. $icon = iassign_icons::insert('not_post');
  2569. $flag_dependency = false;
  2570. }
  2571. } else {
  2572. $icon = iassign_icons::insert('not_post');
  2573. $flag_dependency = false;
  2574. } // if ($dependencysubmissions)
  2575. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2576. } // if ($dependency)
  2577. } // foreach ($dependencys as $dependency)
  2578. } // if ($iassign_statement_activity_item->dependency == 0)
  2579. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2580. if ($flag_dependency == false) {
  2581. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2582. $this->view_iassign = false;
  2583. print '</tr></table>' . "\n";
  2584. }
  2585. else {
  2586. $this->view_iassign = true;
  2587. print '</td>' . "\n";
  2588. } // if ($flag_dependency == false)
  2589. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2590. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2591. // receiver=1 - message to teacher
  2592. // receiver=2 - message to student
  2593. if ($iassign_submission) {
  2594. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2595. if ($verify_message)
  2596. $comment = iassign_icons::insert('comment_unread');
  2597. }
  2598. print '<td width=40% valign="top" align="left">';
  2599. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2600. if ($iassign_statement_activity_item->show_answer == 1) {
  2601. // check status of solution sent by the student
  2602. if ($iassign_submission) {
  2603. switch ($iassign_submission->status) {
  2604. case 3 :
  2605. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2606. break;
  2607. case 2 :
  2608. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2609. break;
  2610. case 1 :
  2611. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2612. break;
  2613. default :
  2614. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2615. $repeat = "";
  2616. $last_iassign = "";
  2617. } // switch ($iassign_submission->status)
  2618. } else {
  2619. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2620. $repeat = "";
  2621. $last_iassign = "";
  2622. }
  2623. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2624. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2625. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2626. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2627. if ($iassign_statement_activity_item->max_experiment == 0)
  2628. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2629. else {
  2630. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2631. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2632. $repeat = "";
  2633. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2634. $this->bottonPost = 0;
  2635. $this->write_solution = 0;
  2636. }
  2637. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2638. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2639. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2640. if ($teacher)
  2641. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2642. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2643. } // if ($iassign_statement_activity_item->show_answer==1)
  2644. else {
  2645. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2646. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2647. $repeat = "";
  2648. $last_iassign = "";
  2649. } elseif ($iassign_submission->status == 1) {
  2650. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2651. }
  2652. }
  2653. print '</td>';
  2654. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2655. print '</tr></table>' . "\n";
  2656. // Presents the iLM
  2657. print '<table width=100% border=0 valign="top">' . "\n";
  2658. print '<td width=80% align="left">';
  2659. 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\".
  2660. print '<td width=20% align="rigth">';
  2661. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2662. print $repeat; // symbol of "redo activity"
  2663. print '</td></tr></table>' . "\n";
  2664. //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)'
  2665. print activity::toggle_columns_script();
  2666. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2667. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2668. $output = '';
  2669. if (!$iassign_ilm) {
  2670. $iassign_ilm = new stdClass();
  2671. $iassign_ilm->file_jar = "";
  2672. }
  2673. $output .= $OUTPUT->box_start();
  2674. $USER->iassignEdit = $this->bottonPost;
  2675. // ---
  2676. // Presents the iLM
  2677. // Prepare tags to present the iLM
  2678. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2679. $student_answer = ""; //?
  2680. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2681. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2682. $student_answer = "";
  2683. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2684. } else {
  2685. // When student is redoing his activity
  2686. // ATTENTION: exception used by iGeom (exercise with "script")
  2687. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2688. if (substr($ilm_name, 0, 5)=="igeom") {
  2689. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2690. $loadTeacherActivity = true;
  2691. }
  2692. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2693. }
  2694. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2695. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2696. //1 $history_comment = '';
  2697. //1 if ($iassign_submission) {
  2698. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2699. //1 }
  2700. //1 if (!empty($history_comment)) {
  2701. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2702. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2703. //1 $output .= $history_comment;
  2704. //1 $output .= "</table>\n";
  2705. //1 }
  2706. //1 $output .= "</form></center>\n";
  2707. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2708. //1 }
  2709. $output .= $OUTPUT->box_end();
  2710. print $output;
  2711. } // if ($this->view_iassign)
  2712. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2713. } // if ($this->view_iassign)
  2714. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2715. else
  2716. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2717. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2718. print '<table width=100% border=0 valign="top">' . "\n";
  2719. print '<tr><td width=60% valign="top">' . "\n";
  2720. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2721. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2722. print '</tr></table>' . "\n";
  2723. $student_answer = "";
  2724. $enderecoPOST = "";
  2725. // Prepare tags to present the iLM
  2726. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2727. print $output;
  2728. }
  2729. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2730. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2731. 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
  2732. // Put a block with area to sent/answer comments
  2733. $output = '';
  2734. $history_comment = '';
  2735. $row = optional_param('row', 0, PARAM_INT);
  2736. $column = optional_param('column', 0, PARAM_INT);
  2737. if ($iassign_submission) {
  2738. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2739. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2740. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2741. }
  2742. else {
  2743. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2744. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2745. }
  2746. $output .= $OUTPUT->box_start();
  2747. //if (!empty($history_comment)) {
  2748. $output .= "<a id='comments'></a>";
  2749. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2750. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2751. $output .= "</table>";
  2752. print " <script type='text/javascript'>
  2753. //<![CDATA[
  2754. function submit_comment(url) {
  2755. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2756. var formData = new FormData();
  2757. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2758. var request = new XMLHttpRequest();
  2759. request.open('POST', url);
  2760. document.getElementById('comments_history').innerHTML = '';
  2761. request.onload = function (e) {
  2762. if (request.readyState === 4) {
  2763. if (request.status === 200) {
  2764. document.getElementById('comments_history').innerHTML = request.responseText;
  2765. document.getElementById('check-message-success').style.visibility = 'visible';
  2766. setTimeout(function(){
  2767. document.getElementById('check-message-success').style.visibility = 'hidden';
  2768. }, 3000);
  2769. }
  2770. }
  2771. };
  2772. document.formEnvioComment.submission_comment.value = '';
  2773. request.send(formData);
  2774. }
  2775. //]]>
  2776. </script>";
  2777. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2778. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2779. $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";
  2780. $output .= "</form> </center>\n";
  2781. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2782. // }
  2783. $output .= $OUTPUT->box_end();
  2784. print $output;
  2785. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2786. // final block 'studant'
  2787. print $OUTPUT->footer();
  2788. die();
  2789. } // function view_iassign_current()
  2790. /// Export the data from performance report into CSV file format
  2791. function export_csv () {
  2792. global $USER, $CFG, $DB, $OUTPUT;
  2793. $str = "";
  2794. $fields = "student_id, student_name";
  2795. // Finding all iassign activities for the iassign:
  2796. $id = $this->cm->id;
  2797. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2798. $c = 1;
  2799. foreach ($iassign_list as $iassign) {
  2800. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2801. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2802. $c ++;
  2803. }
  2804. // Finding enrolled students:
  2805. $params_temp = array('shortname' => 'student');
  2806. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2807. $context = context_course::instance($this->course->id);
  2808. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2809. $students = $DB->get_records_sql(
  2810. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2811. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2812. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2813. foreach ($students as $student) {
  2814. $str .= $student->userid . ',';
  2815. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2816. foreach ($iassign_list as $iassign) {
  2817. $str .= ',' . $iassign->id . ',';
  2818. $str .= '"' . $iassign->name . '",';
  2819. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2820. if ($student_submissions) {
  2821. $str .= $student_submissions->experiment . ',';
  2822. $str .= $student_submissions->grade . ',';
  2823. switch ($student_submissions->status) {
  2824. case 3:
  2825. $str .= '"correct",';
  2826. break;
  2827. case 2:
  2828. $str .= '"incorrect",';
  2829. break;
  2830. case 1:
  2831. $str .= '"post",';
  2832. break;
  2833. case 0:
  2834. $str .= '"not_post",';
  2835. break;
  2836. }
  2837. }
  2838. else {
  2839. $str .= ',,"not_post",';
  2840. }
  2841. $str .= $iassign->iassign_ilmid . ',';
  2842. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2843. $str .= '"' . $ilm_activity->name . '"';
  2844. }
  2845. $str .= "\n";
  2846. }
  2847. $str = $fields . "\n" . $str;
  2848. header("Content-type: text/csv");
  2849. header("Content-disposition: attachment; filename=report.csv");
  2850. header("Pragma: no-cache");
  2851. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2852. header('Content-Length: ' . strlen($str));
  2853. header('Connection: close');
  2854. print $str;
  2855. flush();
  2856. } // function export_csv()
  2857. /// Display report of performance
  2858. function report () {
  2859. global $USER, $CFG, $DB, $OUTPUT;
  2860. $id = $this->cm->id;
  2861. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2862. if ($this->action != 'print') {
  2863. $title = get_string('report', 'iassign');
  2864. print $OUTPUT->header();
  2865. } // if ($this->action != 'print')
  2866. $this->print_main_menu();
  2867. print $OUTPUT->box_start();
  2868. $this->view_legend_icons();
  2869. print $OUTPUT->box_end();
  2870. if ($this->action == 'print')
  2871. print '<table border=1 width="100%">' . "\n";
  2872. else
  2873. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
  2874. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2875. // $num = array();
  2876. $i = 1;
  2877. $num = array();
  2878. $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;";
  2879. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2880. $test_exercise = "";
  2881. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2882. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2883. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2884. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2885. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2886. $num[$i] = new stdClass();
  2887. $num[$i]->name = $iassign->name;
  2888. $num[$i]->id = $i;
  2889. $num[$i]->iassignid = $iassign->id;
  2890. print ' <tr >' . "\n";
  2891. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2892. print "<td class=\"cell c0 actvity\">";
  2893. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2894. print ' </tr>' . "\n";
  2895. $i++;
  2896. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2897. } // foreach ($iassign_list as $iassign)
  2898. $num_exerc = $i; // total of exercises
  2899. print "</table>";
  2900. print "<p></p>";
  2901. if ($this->action == 'print')
  2902. print '<table border=1 width="100%">' . "\n";
  2903. else // ./theme/boost/style/moodle.css: .generaltable
  2904. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  2905. $context = context_course::instance($this->course->id);
  2906. if ($num_exerc > 1) {
  2907. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2908. $params_temp = array('shortname' => 'student');
  2909. $role = $DB->get_record_sql(
  2910. "SELECT s.id, s.shortname FROM {role} s " .
  2911. " WHERE s.shortname = :shortname", $params_temp);
  2912. // $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");
  2913. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2914. $students = $DB->get_records_sql(
  2915. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2916. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2917. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2918. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2919. $width = 90/$num_exerc;
  2920. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  2921. $sum_iassign_correct[$j] = 0;
  2922. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2923. }
  2924. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2925. $sum_iassign = $j - 1;
  2926. print '</tr>' . "\n";
  2927. $total = 0;
  2928. $sum_student = 0;
  2929. $comment = iassign_icons::insert('comment_read');
  2930. $sum_comment = 0;
  2931. $sum_correct_iassign = array();
  2932. $sum_correct_student = array();
  2933. $USER->matrix_iassign = array();
  2934. if ($students) {
  2935. $w = 0;
  2936. foreach ($students as $tmp) { // count students
  2937. $users_array[$w] = $tmp;
  2938. $w++;
  2939. }
  2940. for ($x=0; $x<$w; $x++) { // for all students
  2941. print '<tr>' . "\n";
  2942. $sum_student ++;
  2943. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2944. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  2945. $total_student = 0;
  2946. $tentativas = 0;
  2947. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  2948. $sum_comment = $sum_verify_message = 0;
  2949. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2950. if ($student_submissions) {
  2951. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2952. $tentativas = $student_submissions->experiment;
  2953. // Get student comments
  2954. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2955. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  2956. $student_submissions_comment = $DB->get_record_sql(
  2957. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2958. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  2959. if ($student_submissions_comment) // student has comment
  2960. foreach ($student_submissions_comment as $tmp)
  2961. $sum_comment = $tmp;
  2962. // informations to previous activities
  2963. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  2964. else $iassign_previous = $num[$j - 1]->iassignid;
  2965. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2966. else $user_previous = $users_array[$x - 1]->userid;
  2967. // next
  2968. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2969. else $iassign_next = "-1";
  2970. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2971. else $user_next = "-1";
  2972. $position = "&row= $x&column=$j";
  2973. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2974. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2975. $url .= $position;
  2976. // receiver=1 - message to teacher
  2977. // receiver=2 - message to student
  2978. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2979. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2980. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2981. $verify_message = $DB->get_record_sql(
  2982. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2983. "WHERE iassign_submissionid = :iassign_submissionid " .
  2984. " AND return_status= :return_status " .
  2985. " AND receiver= :receiver", $params_temp);
  2986. if ($verify_message)
  2987. foreach ($verify_message as $tmp)
  2988. $sum_verify_message = $tmp;
  2989. if ($sum_verify_message > 0)
  2990. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  2991. else
  2992. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  2993. if ($student_submissions->status == 3) {
  2994. $sum_iassign_correct[$j] ++;
  2995. $total_student ++;
  2996. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  2997. }
  2998. elseif ($student_submissions->status == 2) {
  2999. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  3000. }
  3001. elseif ($student_submissions->status == 1) {
  3002. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3003. }
  3004. elseif ($student_submissions->status == 0) {
  3005. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3006. }
  3007. if ($this->action != 'print') {
  3008. if ($tentativas > 0)
  3009. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3010. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3011. . $feedback
  3012. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3013. . $tentativas
  3014. . '</span> </button>'
  3015. . '</a>' . "\n";
  3016. else
  3017. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3018. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3019. . $feedback
  3020. .'</button>'
  3021. . '</a>' . "\n";
  3022. if ($sum_comment > 0 && $sum_verify_message > 0)
  3023. print '<a href="' . $url . '"> '
  3024. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3025. . $comment
  3026. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3027. . $sum_verify_message . '/' . $sum_comment
  3028. . '</span> </button>'
  3029. . '</a>';
  3030. else if ($sum_comment > 0)
  3031. print '<a href="' . $url . '"> '
  3032. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  3033. . $comment
  3034. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3035. . $sum_comment
  3036. . '</span> </button>'
  3037. . '</a>';
  3038. print '</td>' . "\n";
  3039. }
  3040. if ($this->action == 'print')
  3041. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3042. } // if ($student_submissions)
  3043. else { // if ($student_submissions)
  3044. // Student does not have any submission
  3045. // informations to browse previous activities
  3046. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3047. else $iassign_previous = $num[$j - 1]->iassignid;
  3048. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3049. else $user_previous = $users_array[$x - 1]->userid;
  3050. // next
  3051. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3052. else $iassign_next = "-1";
  3053. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3054. else $user_next = "-1";
  3055. $position = "&row= $x&column=$j";
  3056. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3057. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3058. $url .= $position;
  3059. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3060. if ($this->action == 'print')
  3061. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3062. else {
  3063. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3064. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3065. . $feedback
  3066. .'</button>'
  3067. . '</a>' . "\n";
  3068. // print '<td> &nbsp;</td>';
  3069. if ($sum_comment > 0)
  3070. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3071. // else print '<td> &nbsp;</td>';
  3072. print '</td>';
  3073. }
  3074. } // else if ($student_submissions)
  3075. $USER->matrix_iassign[$x][$j] = new stdClass();
  3076. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3077. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3078. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3079. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3080. if ($student_submissions)
  3081. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3082. else
  3083. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3084. //print '</td>' . "\n";
  3085. } // for ($j=1; $j<$num_exerc; $j++)
  3086. $total = $total + $total_student;
  3087. $porcentagem = ($total_student / ($j - 1)) * 100;
  3088. if ($tentativas != 0 && $tentativas != null) {
  3089. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3090. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3091. }
  3092. else {
  3093. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3094. }
  3095. print '</tr>' . "\n";
  3096. $sum_correct_student[$sum_student] = new stdClass();
  3097. $sum_correct_student[$sum_student]->name = $name;
  3098. $sum_correct_student[$sum_student]->sum = $total_student;
  3099. } // for ($x = 0; $x < $w; $x ++)
  3100. for ($i = 1; $i < $j; $i ++) {
  3101. if (is_null($sum_iassign_correct[$i]))
  3102. $sum_iassign_correct[$i] = 0;
  3103. $sum_correct_iassign[$i] = new stdClass();
  3104. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3105. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3106. }
  3107. // print '</tr></table>' . "\n";
  3108. }
  3109. } // if ($i>1)
  3110. else {
  3111. print_string('no_activity', 'iassign');
  3112. }
  3113. print "</table>\n";
  3114. print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . '</p>';
  3115. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  3116. if ($this->action != 'print')
  3117. print $OUTPUT->footer();
  3118. die();
  3119. } // function report()
  3120. /// Display graphics of performance
  3121. function stats () {
  3122. global $USER, $CFG, $DB, $OUTPUT;
  3123. $id = $this->cm->id;
  3124. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3125. if ($this->action != 'printstats')
  3126. $title = get_string('graphic', 'iassign');
  3127. $num = array();
  3128. $sum_correct_iassign = array();
  3129. $sum_correct_student = array();
  3130. $sum_student = 0;
  3131. $i = 1;
  3132. foreach ($iassign_list as $iassign) {
  3133. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3134. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3135. $sum_iassign_correct[$i] = 0;
  3136. $num[$i] = new stdClass();
  3137. $num[$i]->name = $iassign->name;
  3138. $num[$i]->id = $i;
  3139. $num[$i]->iassignid = $iassign->id;
  3140. $i ++;
  3141. } // if ($iassign->type_iassign == 3)
  3142. } // foreach ($iassign_list as $iassign)
  3143. $sum_iassign = $i - 1;
  3144. $context = context_course::instance($this->course->id);
  3145. if ($i > 1) {
  3146. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3147. $params_temp = array('shortname' => 'student');
  3148. $role = $DB->get_record_sql(
  3149. "SELECT s.id, s.shortname FROM {role} s " .
  3150. " WHERE s.shortname = :shortname", $params_temp);
  3151. // $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");
  3152. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3153. $students = $DB->get_records_sql(
  3154. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3155. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3156. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3157. $total = 0;
  3158. $sum_student = 0;
  3159. $j = 0;
  3160. $sum_correct_iassign = array();
  3161. $sum_correct_student = array();
  3162. $sum_experiment = array();
  3163. if ($students) {
  3164. foreach ($students as $users) {
  3165. $sum_student ++;
  3166. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3167. // rows
  3168. $total_student = 0;
  3169. for ($j = 1; $j < $i; $j ++) {
  3170. $total_experiment = 0;
  3171. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3172. if ($student_submissions) {
  3173. if ($student_submissions->status == 3) {
  3174. $sum_iassign_correct[$j] ++;
  3175. $total_student ++;
  3176. } // if ($student_submissions->status == 3)
  3177. $total_experiment += $student_submissions->experiment;
  3178. }
  3179. $sum_experiment[$j] = $total_experiment;
  3180. } // for ($j=1; $j<$i; $j++)
  3181. $total = $total + $total_student;
  3182. $sum_correct_student[$sum_student] = new stdClass();
  3183. $sum_correct_student[$sum_student]->name = $name;
  3184. $sum_correct_student[$sum_student]->sum = $total_student;
  3185. } // foreach ($students as $users)
  3186. }
  3187. for ($i = 1; $i < $j; $i ++) {
  3188. if (is_null($sum_iassign_correct[$i]))
  3189. $sum_iassign_correct[$i] = 0;
  3190. $sum_correct_iassign[$i] = new stdClass();
  3191. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3192. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3193. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3194. } // for ($i = 1; $i < $j; $i++)
  3195. } // if ($i > 1)
  3196. print $OUTPUT->header();
  3197. $this->print_main_menu();
  3198. if ($this->action != 'printstats') {
  3199. $title = get_string('graphic', 'iassign');
  3200. $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>";
  3201. $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>";
  3202. print '<table width=100%><tr>';
  3203. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3204. print '<td width=15% align="right">' . $link_report . '</td>';
  3205. print '</td></tr></table>' . "\n";
  3206. print "<br><br>";
  3207. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3208. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3209. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3210. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3211. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3212. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3213. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3214. print '</tr>' . "\n";
  3215. $sum_correct = 0;
  3216. if ($sum_correct_iassign) {
  3217. foreach ($sum_correct_iassign as $iassign) {
  3218. if (is_null($iassign->experiment))
  3219. $iassign->experiment = 0;
  3220. $bar = "";
  3221. $sum = $iassign->sum;
  3222. $percent = ($sum / $sum_student) * 100;
  3223. $text = number_format($percent, 1) . '%';
  3224. $sum_correct += $sum;
  3225. if ($sum > 0) {
  3226. for ($i = 1; $i < $percent * 2; $i ++)
  3227. $bar .= iassign_icons::insert('hbar_blue');
  3228. $bar .= iassign_icons::insert('hbar_blue_r');
  3229. } // if ($sum > 0)
  3230. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3231. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3232. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3233. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3234. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3235. print '</tr>' . "\n";
  3236. } // foreach ($sum_correct_iassign as $iassign)
  3237. }
  3238. print "</table>";
  3239. print "<br><br>";
  3240. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3241. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3242. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3243. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3244. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3245. print '</tr>' . "\n";
  3246. $sum_correct = 0;
  3247. foreach ($sum_correct_student as $student) {
  3248. $bar = "";
  3249. $sum = $student->sum;
  3250. $percent = ($sum / $sum_iassign) * 100;
  3251. $text = number_format($percent, 1) . '%';
  3252. $sum_correct += $sum;
  3253. if ($sum > 0) {
  3254. for ($i = 1; $i < $percent * 2; $i ++)
  3255. $bar .= iassign_icons::insert('hbar_blue');
  3256. $bar .= iassign_icons::insert('hbar_blue_r');
  3257. } // if ($sum > 0)
  3258. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3259. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3260. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3261. print '</tr>' . "\n";
  3262. } // foreach ($sum_correct_student as $student)
  3263. print "</table>\n";
  3264. print "<br><br>\n";
  3265. $var = 0;
  3266. $cv = 0;
  3267. $dv = 0;
  3268. $avg = 0;
  3269. if ($sum_correct_student) {
  3270. $avg = $sum_correct / $sum_student;
  3271. if ($avg > 0) {
  3272. foreach ($sum_correct_student as $student)
  3273. $var += pow($student->sum - $avg, 2);
  3274. $var = $var / $sum_student;
  3275. $dv = sqrt($var);
  3276. $cv = ($dv / $avg) * 100;
  3277. }
  3278. }
  3279. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3280. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3281. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3282. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3283. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3284. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3285. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3286. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3287. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3288. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3289. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3290. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3291. print "</table>\n";
  3292. print $OUTPUT->footer();
  3293. } else {
  3294. print "<STYLE TYPE='text/css'>
  3295. <!--
  3296. .boldtable {
  3297. font-family:sans-serif;
  3298. font-size:10pt;
  3299. }
  3300. -->
  3301. </STYLE>\n";
  3302. print '<table border=1 width=100%>' . "\n";
  3303. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3304. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3305. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3306. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3307. print '</tr>' . "\n";
  3308. $sum_correct = 0;
  3309. foreach ($sum_correct_iassign as $iassign) {
  3310. $bar = "";
  3311. $sum = $iassign->sum;
  3312. $percent = ($sum / $sum_student) * 100;
  3313. $text = number_format($percent, 1) . '%';
  3314. $sum_correct += $sum;
  3315. if ($sum > 0) {
  3316. for ($i = 1; $i < $percent * 2; $i ++)
  3317. $bar .= iassign_icons::insert('hbar_blue');
  3318. $bar .= iassign_icons::insert('hbar_blue_r');
  3319. } // if ($sum > 0)
  3320. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3321. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3322. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3323. print '</tr>' . "\n";
  3324. } // foreach ($sum_correct_iassign as $iassign)
  3325. print "</table>";
  3326. print "<br><br>";
  3327. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3328. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3329. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3330. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3331. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3332. print '</tr>' . "\n";
  3333. $sum_correct = 0;
  3334. foreach ($sum_correct_student as $student) {
  3335. $bar = "";
  3336. $sum = $student->sum;
  3337. $percent = ($sum / $sum_iassign) * 100;
  3338. $text = number_format($percent, 1) . '%';
  3339. $sum_correct += $sum;
  3340. if ($sum > 0) {
  3341. for ($i = 1; $i < $percent * 2; $i ++)
  3342. $bar .= iassign_icons::insert('hbar_blue');
  3343. $bar .= iassign_icons::insert('hbar_blue_r');
  3344. } // if ($sum > 0)
  3345. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3346. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3347. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3348. print '</tr>' . "\n";
  3349. } // foreach ($sum_correct_student as $student)
  3350. print "</table>\n";
  3351. print "<br/><br/>\n";
  3352. $var = 0;
  3353. $cv = 0;
  3354. $dv = 0;
  3355. $avg = 0;
  3356. if ($sum_correct_student) {
  3357. $avg = $sum_correct / $sum_student;
  3358. if ($avg > 0) {
  3359. foreach ($sum_correct_student as $student)
  3360. $var += pow($student->sum - $avg, 2);
  3361. $var = $var / $sum_student;
  3362. $dv = sqrt($var);
  3363. $cv = ($dv / $avg) * 100;
  3364. }
  3365. }
  3366. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3367. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3368. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3369. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3370. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3371. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3372. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3373. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3374. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3375. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3376. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3377. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3378. print "</table>\n";
  3379. } // if ($this->action != 'printstats')
  3380. die();
  3381. }
  3382. /// Display graphics of performance for students
  3383. function stats_students () {
  3384. global $USER, $CFG, $DB, $OUTPUT;
  3385. $id = $this->cm->id;
  3386. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3387. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3388. $title = get_string('results', 'iassign');
  3389. $sum_correct = 0;
  3390. $sum_incorrect = 0;
  3391. $sum_post = 0;
  3392. $sum_nopost = 0;
  3393. $sum_iassign = count($iassign_statement_list);
  3394. $bar_nopost = "";
  3395. $bar_correct = "";
  3396. $bar_incorrect = "";
  3397. $bar_post = "";
  3398. $text_nopost = "";
  3399. $text_correct = "";
  3400. $text_incorrect = "";
  3401. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3402. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3403. if ($iassign_submission) {
  3404. if ($iassign_submission->status == 3)
  3405. $sum_correct ++;
  3406. elseif ($iassign_submission->status == 2)
  3407. $sum_incorrect ++;
  3408. elseif ($iassign_submission->status == 1)
  3409. $sum_post ++;
  3410. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3411. $sum_nopost ++;
  3412. } // if ($iassign_submission)
  3413. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3414. if ($sum_iassign > 0) {
  3415. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3416. $text_correct = number_format($percent_correct, 1) . '%';
  3417. }
  3418. if ($sum_correct > 0) {
  3419. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3420. $bar_correct .= iassign_icons::insert('hbar_green');
  3421. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3422. } // if ($sum_correct > 0)
  3423. if ($sum_iassign > 0) {
  3424. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3425. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3426. }
  3427. if ($sum_incorrect > 0) {
  3428. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3429. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3430. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3431. } // if ($sum_incorrect > 0)
  3432. if ($sum_iassign > 0) {
  3433. $percent_post = ($sum_post / $sum_iassign) * 100;
  3434. $text_post = number_format($percent_post, 1) . '%';
  3435. }
  3436. if ($sum_post > 0) {
  3437. for ($i = 1; $i < $percent_post * 2; $i ++)
  3438. $bar_post .= iassign_icons::insert('hbar_blue');
  3439. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3440. } // if ($sum_post > 0)
  3441. if ($sum_iassign > 0) {
  3442. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3443. $text_nopost = number_format($percent_nopost, 1) . '%';
  3444. }
  3445. if ($sum_nopost > 0) {
  3446. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3447. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3448. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3449. } // if ($sum_nopost > 0)
  3450. print $OUTPUT->header();
  3451. $this->print_main_menu();
  3452. print "<br/><br/>\n";
  3453. print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
  3454. print '<tr><th colspan=3 class="header c1">' . "\n";
  3455. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3456. // $imagetext = '');
  3457. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3458. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3459. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3460. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3461. print '</tr>' . "\n";
  3462. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3463. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3464. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3465. print '</tr>' . "\n";
  3466. if ($sum_post) {
  3467. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3468. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3469. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3470. print '</tr>' . "\n";
  3471. } // if ($sum_post)
  3472. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3473. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3474. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3475. print '</tr>' . "\n";
  3476. print "</table>";
  3477. print "<br><br>";
  3478. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3479. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3480. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3481. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3482. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3483. $sum_grade = 0;
  3484. $sum_grade_student = 0;
  3485. $avg = 0;
  3486. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3487. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3488. if (!$iassign_submission) {
  3489. $iassign_submission = new stdClass();
  3490. $iassign_submission->grade = 0;
  3491. }
  3492. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3493. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3494. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3495. print '</tr>' . "\n";
  3496. $sum_grade += $iassign_statement_activity_item->grade;
  3497. $sum_grade_student += $iassign_submission->grade;
  3498. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3499. if ($sum_grade > 0)
  3500. $avg = $sum_grade_student / $sum_grade * 100;
  3501. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3502. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3503. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3504. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3505. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3506. print "</table>";
  3507. print $OUTPUT->footer();
  3508. die();
  3509. } // function stats_students()
  3510. function get_total_notifications () {
  3511. global $DB, $USER, $COURSE;
  3512. $total_messages = 0;
  3513. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3514. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3515. $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3516. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3517. }
  3518. else {
  3519. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3520. $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3521. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3522. }
  3523. return $total_messages->total;
  3524. }
  3525. function view_notifications () {
  3526. global $OUTPUT;
  3527. print $OUTPUT->header();
  3528. $this->print_main_menu();
  3529. print $OUTPUT->footer();
  3530. }
  3531. function print_main_menu () {
  3532. global $USER;
  3533. $id = $this->cm->id;
  3534. $actual_action = optional_param('action', '', PARAM_TEXT);
  3535. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3536. $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
  3537. $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
  3538. $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
  3539. $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
  3540. $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
  3541. $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
  3542. $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
  3543. $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
  3544. print '<div class="btn-group" role="group" aria-label="">';
  3545. print '<a href="'.$url_home.'" class="btn btn-outline-primary '.($actual_action == '' ? 'active' : '').'">
  3546. <i class="fa fa-home" aria-hidden="true"></i> '.get_string('activities_page', 'iassign').'
  3547. </a>';
  3548. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3549. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3550. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3551. // Has capability to see "report": teacher or up
  3552. print '<a href="'.$url_help.'" class="btn btn-outline-primary"><i class="fa fa-question-circle" aria-hidden="true"></i> '.get_string('help_ilm', 'iassign').'</a>';
  3553. print '<div class="btn-group">
  3554. <a href="'.$url_report.'" class="btn btn-outline-primary '.($actual_action == 'report' || $actual_action == 'stats' || $actual_action == 'all_submissions' ? 'active' : '').' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  3555. <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
  3556. <div class="dropdown-menu">
  3557. <a href="'.$url_report.'" class=" '.($actual_action == 'report' ? 'active' : ''). ' dropdown-item"><i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('home', 'iassign').'</a>
  3558. <div class="dropdown-divider"></div>
  3559. <a href="'.$url_sub_stats.'" class="dropdown-item '.($actual_action == 'stats' ? 'active' : '').'"><i class="fa fa-pie-chart" aria-hidden="true"></i> '.get_string('graphic', 'iassign') .'</a>
  3560. <div class="dropdown-divider"></div>
  3561. <a href="'.$url_all_submissions.'" class="dropdown-item '.($actual_action == 'all_submissions' ? 'active' : '').'"><i class="fa fa-files-o" aria-hidden="true"></i> '.get_string('all_submissions_manager', 'iassign') .'</a>
  3562. </div>
  3563. </div>
  3564. ';
  3565. print '<a href="'.$url_stats.'" class="btn btn-outline-primary '.($actual_action == 'stats_student' ? 'active' : '').'"><i class="fa fa-list" aria-hidden="true"></i> '.get_string('results', 'iassign').'</a>';
  3566. print '<a href="'.$url_auto_evaluate.'" class="btn btn-outline-primary '.($actual_action == 'auto_evaluate' ? 'active' : '').'"><i class="fa fa-check-square-o" aria-hidden="true"></i> '.get_string('auto_evaluate_name_config', 'iassign').'</a>';
  3567. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3568. $notifications = $this->get_total_notifications();
  3569. print '<a href="'.$url_notifications.'" class="btn btn-outline-primary '.($actual_action == 'notifications' ? 'active' : '').'">
  3570. <i class="fa fa-bell" aria-hidden="true"></i> '.get_string('notifications', 'iassign');
  3571. if ($notifications > 0)
  3572. print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
  3573. print '</a>';
  3574. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3575. print '<a href="'.$url_add.'" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i> '.get_string('add_iassign', 'iassign').'</a>';
  3576. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3577. print '</div>' . "\n";
  3578. }
  3579. /// Display page of iAssign's activity
  3580. function view_iassigns () {
  3581. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3582. $id = $this->cm->id;
  3583. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3584. $notice = optional_param('notice', '', PARAM_TEXT);
  3585. if (strpos($notice, 'error'))
  3586. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3587. else if ($notice != '')
  3588. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3589. $this->print_main_menu();
  3590. print $OUTPUT->box_start();
  3591. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3592. print '<div class="border float-right">';
  3593. if ($iassign_list) {
  3594. // $USER->iassignEdit == 0 view 'Turn editing off'
  3595. // $USER->iassignEdit == 1 view 'Turn editing on'
  3596. if (!isset($USER->iassignEdit))
  3597. $USER->iassignEdit = 0;
  3598. if ($USER->iassignEdit == 0) {
  3599. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3600. $botton = 1;
  3601. } // if ($USER->iassignEdit == 0)
  3602. elseif ($USER->iassignEdit == 1) {
  3603. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3604. $botton = 0;
  3605. } // elseif ($USER->iassignEdit == 1)
  3606. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3607. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3608. print " <input class='btn btn-primary' type=submit value='$bottonEdit_message'/>\n";
  3609. print "</form>\n";
  3610. } // if ($iassign_list)
  3611. print '</div>';
  3612. }
  3613. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3614. // $this->view_legend_icons();
  3615. print $OUTPUT->box_end();
  3616. $iassign_array_exercise = array();
  3617. $i_exercise = 0;
  3618. $iassign_array_test = array();
  3619. $i_test = 0;
  3620. $iassign_array_example = array();
  3621. $i_example = 0;
  3622. $iassign_array_general = array();
  3623. $i_general = 0;
  3624. if ($iassign_list) {
  3625. if ($this->iassign->activity_group == 0) {
  3626. foreach ($iassign_list as $iassign) {
  3627. $iassign_array_general[$i_general] = $iassign;
  3628. $i_general ++;
  3629. }
  3630. } // if ($this->iassign->activity_group == 0)
  3631. else {
  3632. foreach ($iassign_list as $iassign) {
  3633. if ($iassign->type_iassign == 3) {
  3634. $iassign_array_exercise[$i_exercise] = $iassign;
  3635. $i_exercise ++;
  3636. } // if ($iassign->type_iassign == 3)
  3637. if ($iassign->type_iassign == 2) {
  3638. $iassign_array_test[$i_test] = $iassign;
  3639. $i_test ++;
  3640. } // if ($iassign->type_iassign == 2)
  3641. if ($iassign->type_iassign == 1) {
  3642. $iassign_array_example[$i_example] = $iassign;
  3643. $i_example ++;
  3644. } // if ($iassign->type_iassign == 1)
  3645. }
  3646. }
  3647. if ($iassign_array_exercise) {
  3648. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3649. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3650. }
  3651. if ($iassign_array_test) {
  3652. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3653. $this->show_iassign($title, $iassign_array_test, $i_test);
  3654. }
  3655. if ($iassign_array_example) {
  3656. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3657. $this->show_iassign($title, $iassign_array_example, $i_example);
  3658. }
  3659. if ($iassign_array_general) {
  3660. $title = "";
  3661. $this->show_iassign($title, $iassign_array_general, $i_general);
  3662. }
  3663. } else { // if ($iassign_list)
  3664. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3665. }
  3666. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3667. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3668. print $OUTPUT->box_start();
  3669. print '<table width=100% border=0><tr>' . "\n";
  3670. print '<td width=10% align="left">' . "\n";
  3671. print $link_report;
  3672. print '</td>' . "\n";
  3673. print '</tr></table>' . "\n";
  3674. print $OUTPUT->box_end();
  3675. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3676. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3677. print $OUTPUT->box_start();
  3678. print '<table width=100% border=0><tr>' . "\n";
  3679. print '<td align="left">' . "\n";
  3680. print $link_add;
  3681. print '</td>' . "\n";
  3682. print '</tr></table>' . "\n";
  3683. print $OUTPUT->box_end();
  3684. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3685. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3686. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3687. // $this->view_legend_icons();
  3688. } // function view_iassigns()
  3689. /// Display all iAssigns
  3690. function show_iassign ($title, $iassign_array, $i) {
  3691. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3692. $id = $this->cm->id;
  3693. print $OUTPUT->box_start();
  3694. print " <script type='text/javascript'>
  3695. //<![CDATA[
  3696. function validate_move () {
  3697. var radios = document.getElementsByName('iassign_destiny');
  3698. var formValid = false;
  3699. //alert('aqui validate_move()');
  3700. var i = 0;
  3701. while (!formValid && i < radios.length) {
  3702. if (radios[i].checked) formValid = true;
  3703. i++;
  3704. }
  3705. if (!formValid) {
  3706. document.getElementById('move_dest').classList.add('alert-danger');
  3707. }
  3708. return formValid;
  3709. }
  3710. var modal;
  3711. function load_move(id_ias) {
  3712. document.form_move_activity.iassign_current.value = id_ias;
  3713. modal.style.display = 'block';
  3714. var radios = document.getElementsByName('iassign_destiny');
  3715. var i = 0;
  3716. while (i < radios.length) {
  3717. radios[i].checked = false;
  3718. i++;
  3719. }
  3720. document.getElementById('move_dest').classList.remove('alert-danger');
  3721. }
  3722. function closeModal() {
  3723. modal.style.display = 'none';
  3724. }
  3725. function load_modal_elements() {
  3726. modal = document.getElementById('myModal');
  3727. var span = document.getElementById('close_modal');
  3728. span.onclick = function() {
  3729. modal.style.display = 'none';
  3730. }
  3731. window.onclick = function(event) {
  3732. if (event.target == modal) {
  3733. modal.style.display = 'none';
  3734. }
  3735. }
  3736. }
  3737. window.onload = load_modal_elements;
  3738. //]]>
  3739. </script>\n";
  3740. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3741. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3742. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3743. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3744. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3745. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "'>
  3746. <input type='hidden' name='iassign_current' value='' />";
  3747. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3748. $section = $course_sections[0];
  3749. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3750. for ($k = 0; $k < count($ids_sections); $k++) {
  3751. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3752. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3753. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3754. if ($c_cm) {
  3755. if ($ccm->instance == $c_cm->instance) {
  3756. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3757. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3758. }
  3759. else {
  3760. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3761. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3762. }
  3763. }
  3764. }
  3765. $radio_buttons .= "</ul>";
  3766. }
  3767. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3768. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
  3769. </form>
  3770. </div></div> </div></div>\n";
  3771. print " <style>.modal {
  3772. display: none;
  3773. position: fixed;
  3774. z-index: 1;
  3775. left: 0;
  3776. top: 0;
  3777. width: 100%;
  3778. height: 100%;
  3779. overflow: scroll;
  3780. background-color: rgb(0,0,0);
  3781. background-color: rgba(0,0,0,0.4);
  3782. }
  3783. .modal-content {
  3784. background-color: #fefefe;
  3785. margin: 15% auto;
  3786. padding: 10px 10px;
  3787. border: 1px solid #888;
  3788. width: 50%;
  3789. }
  3790. #close_modal {
  3791. color: #aaa;
  3792. float: right;
  3793. font-size: 28px;
  3794. font-weight: bold;
  3795. margin-top: -15px;
  3796. margin-right: -3px;
  3797. }
  3798. #close_modal:hover,
  3799. #close_modal:focus {
  3800. color: black;
  3801. text-decoration: none;
  3802. cursor: pointer;
  3803. }
  3804. #modal_title {
  3805. min-height: 3rem;
  3806. color: initial;
  3807. background: initial;
  3808. font-size: 1.5rem;
  3809. line-height: 1.5;
  3810. padding: 15px;
  3811. border-bottom: 1px solid #e5e5e5;
  3812. }
  3813. .input_move {
  3814. width: 90%;
  3815. padding: 2px;
  3816. }
  3817. .input_move:hover {
  3818. background: #eff0ef;
  3819. }
  3820. </style>";
  3821. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3822. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>";
  3823. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">';
  3824. for ($j = 0; $j < $i; $j ++) {
  3825. $iassign_current = $iassign_array[$j]->id;
  3826. // receiver=1 - message to teacher
  3827. // receiver=2 - message to student
  3828. $sum_comment = 0;
  3829. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3830. foreach ($iassign_submissions as $iassign_submission) {
  3831. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3832. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3833. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  3834. if ($verify_message)
  3835. foreach ($verify_message as $tmp)
  3836. $sum_comment += $tmp;
  3837. } // foreach ($iassign_submissions as $iassign_submission)
  3838. if ($sum_comment == 0)
  3839. $comment_unread = "";
  3840. else {
  3841. $comment_unread_message = get_string('comment_unread', 'iassign');
  3842. if ($sum_comment == 1)
  3843. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3844. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3845. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3846. }
  3847. if ($j == $i - 1)
  3848. $iassign_down = $iassign_array[$j]->id;
  3849. else
  3850. $iassign_down = $iassign_array[$j + 1]->id;
  3851. if ($j > 0)
  3852. $iassign_up = $iassign_array[$j - 1]->id;
  3853. else
  3854. $iassign_up = $iassign_array[$j]->id;
  3855. if ($iassign_array[$j]->visible == 0)
  3856. $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>";
  3857. else
  3858. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3859. $links .= $comment_unread;
  3860. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3861. $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>";
  3862. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3863. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3864. $link_up = "<li class='page-item'><a href='view.php?action=up$str_aux' class='page-link' title='".get_string('move_up_iassign', 'iassign')."'><i class='fa fa-arrow-up' aria-hidden='true'></i></a></li>";
  3865. if ($j==0) // first activity
  3866. $link_down = "<li class='page-item'><a href='view.php?action=firstdown$str_aux' class='page-link' title='".get_string('move_down_iassign', 'iassign')."'><i class='fa fa-arrow-down' aria-hidden='true'></i></a></li>";
  3867. else
  3868. $link_down = "<li class='page-item'><a href='view.php?action=down$str_aux' class='page-link' title='".get_string('move_up_iassign', 'iassign')."'><i class='fa fa-arrow-down' aria-hidden='true'></i></a></li>";
  3869. $link_delete = "<li class='page-item'><a href='view.php?action=delete$str_aux' class='page-link' title='".get_string('delete_iassign', 'iassign')."'><i class='fa fa-trash-o' aria-hidden='true'></i></a></li>";
  3870. $link_visible_hide = "<li class='page-item'><a href='view.php?action=visible$str_aux' class='page-link' title='".get_string('hide_iassign', 'iassign')."'><i class='fa fa-eye' aria-hidden='true'></i></a></li>";
  3871. $link_visible_show = "<li class='page-item'><a href='view.php?action=visible$str_aux' class='page-link' title='".get_string('show_iassign', 'iassign')."'><i class='fa fa-eye-slash' aria-hidden='true'></i></a></li>";
  3872. $link_edit = "<li class='page-item'><a href='view.php?action=edit$str_aux' class='page-link' title='".get_string('edit_iassign', 'iassign')."'><i class='fa fa-pencil-square-o' aria-hidden='true'></i></a></li>";
  3873. $link_duplicate_activity = "<li class='page-item'><a href='view.php?action=duplicate_activity$str_aux' class='page-link' title='".get_string('duplicate_iassign', 'iassign')."'><i class='fa fa-clone' aria-hidden='true'></i></a></li>";
  3874. $link_move_activity = "<li class='page-item'><a href='#' onclick='load_move($iassign_current); return false;' class='page-link' title='".get_string('move_activity', 'iassign')."'><i class='fa fa-sign-out' aria-hidden='true'></i></a></li>";
  3875. if (count($iassign_array) > 1) {
  3876. if ($j == 0)
  3877. $action_links .= $link_down;
  3878. elseif ($j == $i - 1)
  3879. $action_links .= $link_up;
  3880. else
  3881. $action_links .= $link_up . $link_down;
  3882. } // if (count($iassign_array) > 1)
  3883. $action_links .= $link_edit . $link_delete;
  3884. if ($iassign_array[$j]->visible == 0)
  3885. $action_links .= $link_visible_show;
  3886. else
  3887. $action_links .= $link_visible_hide;
  3888. $action_links .= $link_duplicate_activity . $link_move_activity;
  3889. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3890. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle"></td></tr>' . "\n";
  3891. }
  3892. print '</tbody></table>';
  3893. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3894. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3895. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>";
  3896. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">';
  3897. for ($j = 0; $j < $i; $j ++) {
  3898. $icon_status = "";
  3899. $icon_comment = "";
  3900. if ($iassign_array[$j]->visible == 1) {
  3901. $iassign_current = $iassign_array[$j]->id;
  3902. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3903. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3904. $icon_status = "";
  3905. $icon_comment = "";
  3906. if ($iassign_submission) {
  3907. // receiver=1 - message to teacher
  3908. // receiver=2 - message to student
  3909. // $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");
  3910. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3911. $verify_message = $DB->get_record_sql(
  3912. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3913. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  3914. if ($verify_message)
  3915. foreach ($verify_message as $tmp)
  3916. $sum_comment = $tmp;
  3917. if ($sum_comment > 0) {
  3918. $comment_unread_message = get_string('comment_unread', 'iassign');
  3919. if ($sum_comment == 1)
  3920. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3921. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3922. }
  3923. // $icon_comment = iassign_icons::insert('comment_unread');
  3924. if ($iassign_array[$j]->type_iassign == 3) {
  3925. if ($iassign_array[$j]->show_answer == 1) {
  3926. if ($iassign_submission->status == 3)
  3927. $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="'.get_string('correct', 'iassign').'"></i>';
  3928. elseif ($iassign_submission->status == 2)
  3929. $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="'.get_string('incorrect', 'iassign').'"></i>';
  3930. elseif ($iassign_submission->status == 1)
  3931. $icon_status = iassign_icons::insert('post');
  3932. elseif ($iassign_submission->status == 0)
  3933. $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="'.get_string('not_post', 'iassign').'"></i>';
  3934. } // if ($iassign_array[$j]->show_answer==1)
  3935. else {
  3936. if ($iassign_submission->status == 0)
  3937. $icon_status = iassign_icons::insert('not_post');
  3938. else
  3939. $icon_status = iassign_icons::insert('post');
  3940. }
  3941. } // if ($iassign_array[$j]->type_iassign == 3)
  3942. } // if ($iassign_submission)
  3943. elseif ($iassign_array[$j]->type_iassign == 3) {
  3944. $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="'.get_string('not_post', 'iassign').'"></i>';
  3945. } // if ($iassign_array[$j]->type_iassign == 3)
  3946. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 0; text-align: center;">'. $icon_status .'</td><td style="white-space: nowrap; width: 1%; padding-right: 2rem; padding-left: 0.2rem;">' . $links . '</td><td>'. $icon_comment.'</td></tr>' . "\n";
  3947. //print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3948. } // if ($iassign_array[$j]->visible == 1)
  3949. } // for ($j = 0; $j < $i; $j++)
  3950. } else if (isguestuser()) {
  3951. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3952. print '<table width=100% ><tr>' . "\n";
  3953. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3954. print '</tr></table>' . "\n";
  3955. for ($j = 0; $j < $i; $j ++) {
  3956. $icon_status = "";
  3957. $icon_comment = "";
  3958. if ($iassign_array[$j]->visible == 1) {
  3959. $iassign_current = $iassign_array[$j]->id;
  3960. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3961. print '<p>' . $links . '</p>' . "\n";
  3962. } // if ($iassign_array[$j]->visible == 1)
  3963. }
  3964. }
  3965. print '</table>';
  3966. print $OUTPUT->box_end();
  3967. } // function show_iassign($title, $iassign_array, $i)
  3968. /// Show message of return
  3969. function return_home_course ($message) {
  3970. //D global $DB, $OUTPUT;
  3971. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3972. //D echo $OUTPUT->box_start();
  3973. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3974. //D echo '<tr><td align="left"><strong>' . "\n";
  3975. //D print_string($message, 'iassign');
  3976. //D echo '</strong></td>' . "\n";
  3977. //D echo '<td width=20% align="right">' . "\n";
  3978. //D echo $link_return;
  3979. //D echo '</td></tr></table>' . "\n";
  3980. //D echo $OUTPUT->box_end();
  3981. //D // echo $OUTPUT->footer();
  3982. redirect(new moodle_url($this->return . '&notice=' . $message));
  3983. exit;
  3984. }
  3985. /// Search comment of activity
  3986. function search_comment_submission ($iassign_submissionid) {
  3987. global $USER, $DB, $OUTPUT, $COURSE;
  3988. // $context = context_course::instance($COURSE->id);
  3989. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3990. $colorEdit2 = "#d2e5fc";
  3991. $has_capability = 0;
  3992. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3993. $text = "";
  3994. if ($comments) {
  3995. $even = 1;
  3996. foreach ($comments as $tmp) {
  3997. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3998. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3999. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  4000. // $text .= $tmp->comment . "</td></tr>";
  4001. //} else {
  4002. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  4003. $avatar = new user_picture($user_data);
  4004. $avatar->courseid = $COURSE->id;
  4005. $avatar->link = true;
  4006. $user_picture = $OUTPUT->render($avatar);
  4007. $user_picture = str_replace('"35"', '"45"', $user_picture);
  4008. if ($even) {
  4009. $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";
  4010. $even = 0;
  4011. } else {
  4012. $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";
  4013. $even = 1;
  4014. }
  4015. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  4016. } // foreach ($comments as $tmp)
  4017. }
  4018. return $text;
  4019. }
  4020. /// Update comment of activity
  4021. function update_comment ($iassign_submissionid) {
  4022. global $USER, $DB, $OUTPUT;
  4023. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  4024. $receiver = 1; // student message to teacher
  4025. else
  4026. $receiver = 2; // teacher message to student
  4027. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  4028. if ($verify_message) {
  4029. foreach ($verify_message as $message) {
  4030. if ($message->receiver == $receiver) {
  4031. $newentry = new stdClass();
  4032. $newentry->id = $message->id;
  4033. $newentry->return_status = 1;
  4034. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  4035. print_error('error_update', 'iassign');
  4036. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  4037. } // if ($message->receiver == $receiver)
  4038. // Trigger module viewed event.
  4039. $event = \mod_iassign\event\submission_comment_updated::create(array(
  4040. 'objectid' => $this->iassign->id,
  4041. 'context' => $this->context
  4042. ));
  4043. $event->add_record_snapshot('course', $this->course);
  4044. $event->trigger();
  4045. } // foreach ($verify_message as $message)
  4046. }
  4047. }
  4048. /// Record comment of activity
  4049. function write_comment_submission () {
  4050. global $USER, $CFG, $DB;
  4051. $id = $this->cm->id;
  4052. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  4053. $row = optional_param('row', 0, PARAM_INT);
  4054. $column = optional_param('column', 0, PARAM_INT);
  4055. $sum_comment = 0;
  4056. $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);
  4057. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  4058. $str1 = trim($submission_comment);
  4059. $str2 = trim(get_string('box_comment_message', 'iassign'));
  4060. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  4061. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  4062. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  4063. $receiver = 1; // student message to teacher
  4064. $this->action = 'view';
  4065. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  4066. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  4067. } else {
  4068. $receiver = 2; // teacher message to student
  4069. $this->action = 'viewsubmission';
  4070. //D $tousers = array(); //MOOC 2016
  4071. //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
  4072. }
  4073. //MOOC 2016: foi p/ 15 linhas acima:
  4074. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  4075. // verificar se existe uma submissão para o exercício e aluno informados
  4076. if (!$iassign_submission) {
  4077. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  4078. }
  4079. if (!$iassign_submission) {
  4080. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  4081. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  4082. $this->iassign_submission_current = $id_submission;
  4083. }
  4084. else {
  4085. $id_submission = $iassign_submission->id;
  4086. } // if (!$iassign_submission)
  4087. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4088. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4089. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4090. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4091. $comments = $DB->get_record_sql(
  4092. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4093. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4094. if ($comments)
  4095. foreach ($comments as $tmp)
  4096. $sum_comment = $tmp;
  4097. if ($sum_comment == 0) {
  4098. $newentry = new stdClass();
  4099. $newentry->iassign_submissionid = $id_submission;
  4100. $newentry->comment_authorid = $USER->id;
  4101. $newentry->timecreated = time();
  4102. $newentry->comment = $submission_comment;
  4103. $newentry->receiver = $receiver;
  4104. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4105. $event = \mod_iassign\event\submission_comment_created::create(array(
  4106. 'objectid' => $this->iassign->id,
  4107. 'context' => $this->context
  4108. ));
  4109. $event->add_record_snapshot('course', $this->course);
  4110. $event->trigger();
  4111. }
  4112. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4113. // if ($this->action=='viewsubmission') {
  4114. // echo $OUTPUT->header();
  4115. // $this->return_last('confirm_add_comment', $link_return);
  4116. // die;
  4117. // }
  4118. return true;
  4119. } // function write_comment_submission()
  4120. /// Writes a new submission
  4121. // The first student answer is under 'function get_answer()'
  4122. function new_submission ($iassignid, $id_user, $receiver) {
  4123. global $USER, $DB, $OUTPUT;
  4124. $newentry = new stdClass();
  4125. $newentry->iassign_statementid = $iassignid;
  4126. $newentry->userid = $id_user;
  4127. $newentry->timecreated = time();
  4128. $newentry->timemodified = time();
  4129. $newentry->answer = 0; // student only submit message
  4130. if ($receiver == 2) // teacher message to student (write id teacher)
  4131. $newentry->teacher = $USER->id;
  4132. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4133. return_home_course('error_insert_submissions');
  4134. else {
  4135. // Trigger module view event
  4136. $event = \mod_iassign\event\submission_created::create(array(
  4137. 'objectid' => $this->iassign->id,
  4138. 'context' => $this->context
  4139. ));
  4140. $event->add_record_snapshot('course', $this->course);
  4141. $event->trigger();
  4142. }
  4143. return $newentry->id;
  4144. }
  4145. /// Return to a specific address of page
  4146. function return_last ($message, $link_return) {
  4147. global $DB, $OUTPUT;
  4148. print $OUTPUT->box_start();
  4149. print '<table width=100% border=0 valign="top">' . "\n";
  4150. print '<tr><td align="left"><strong>' . "\n";
  4151. print_string($message, 'iassign');
  4152. print '</strong></td>' . "\n";
  4153. print '<td width=20% align="right">' . "\n";
  4154. print $link_return;
  4155. print '</td></tr></table>' . "\n";
  4156. print $OUTPUT->box_end();
  4157. print $OUTPUT->footer();
  4158. die();
  4159. } // function return_last($message, $link_return)
  4160. } // class iassign
  4161. /// Class for manage activities
  4162. class activity {
  4163. var $activity;
  4164. /// Constructor of class.
  4165. // @param int $id Id of activity
  4166. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4167. //D public function activity($id) { self::__construct($id); }
  4168. function __construct ($id) {
  4169. global $DB;
  4170. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4171. if (empty($this->activity))
  4172. $this->activity = null;
  4173. }
  4174. /// Get an activity
  4175. // @return NULL
  4176. function get_activity () {
  4177. if ($this->activity != null)
  4178. return $this->activity;
  4179. else
  4180. return null;
  4181. }
  4182. /// Delete interactive activities
  4183. function delete ($return) {
  4184. global $USER, $CFG, $DB, $OUTPUT;
  4185. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4186. print $OUTPUT->header();
  4187. $output .= $OUTPUT->box_start();
  4188. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4189. if ($iassign_submission_currents) {
  4190. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4191. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4192. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4193. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4194. $output .= $OUTPUT->box_end();
  4195. $output .= $OUTPUT->footer();
  4196. print $output;
  4197. die();
  4198. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4199. } // if ($iassign_submission_currents)
  4200. else
  4201. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  4202. $output .= '<table width=50% border=0>';
  4203. $output .= '<tr valign="top"><td>';
  4204. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  4205. $output .= '</td><td>';
  4206. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4207. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4208. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  4209. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4210. $output .= "</form>\n";
  4211. $output .= '</td><td>';
  4212. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4213. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4214. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4215. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4216. $output .= "</form>\n";
  4217. $output .= '</td></tr></table>' . "\n";
  4218. $output .= $OUTPUT->box_end();
  4219. $output .= $OUTPUT->footer();
  4220. print $output;
  4221. } // function delete($return)
  4222. /// Function for confirm the delete of activity
  4223. // @param String $return Url of return
  4224. // @param Object $iassign Object content an activity
  4225. function deleteyes ($return, $iassign) {
  4226. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4227. $msg = '';
  4228. if (!empty($this->activity->id)) {
  4229. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4230. if ($iassign_submission_currents) {
  4231. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4232. foreach ($iassign_submission_currents as $iassign_submission)
  4233. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4234. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4235. } // if ($iassign_submission_currents)
  4236. }
  4237. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4238. // Remove all files associated to this activity:
  4239. $fs = get_file_storage();
  4240. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4241. $this->delete_calendar($this->activity->id);
  4242. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4243. iassign::update_grade_iassign($this->activity->iassignid);
  4244. if ($delete_iassign_current) {
  4245. $iassign->return_home_course('confirm_delete_iassign');
  4246. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4247. } else {
  4248. $iassign->return_home_course('error_confirm_delete_iassign');
  4249. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4250. }
  4251. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4252. }
  4253. }
  4254. /// Changes position of activities (between those inside a group of interactive activities)
  4255. // @param $move_action = must be "up" or "down"
  4256. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4257. function move_iassign ($move_action, $target, $return) {
  4258. global $DB, $OUTPUT;
  4259. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4260. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4261. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4262. if ($move_action=="firstdown") {
  4263. $final_position_source = 2;
  4264. $final_position_target = 1;
  4265. }
  4266. else
  4267. if ($move_action=="down") {
  4268. $final_position_target = $this->activity->position;
  4269. $final_position_source = $final_position_target + 1;
  4270. }
  4271. else
  4272. if ($move_action=="up") {
  4273. $final_position_target = $this->activity->position;
  4274. $final_position_source = $final_position_target - 1;
  4275. }
  4276. else { // error:
  4277. print_error('error_update_move_iassign', 'iassign');
  4278. exit;
  4279. }
  4280. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4281. $newentry->id = $this->activity->id; // ID of the "source activity"
  4282. $newentry->position = $final_position_source;
  4283. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4284. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4285. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4286. print_error('error_update_move_iassign', 'iassign');
  4287. }
  4288. else { // first update performed successfully
  4289. $newentry->id = $iassign_target->id;
  4290. $newentry->position = $final_position_target;
  4291. if (!$DB->update_record('iassign_statement', $newentry))
  4292. print_error('error_update_move_iassign', 'iassign');
  4293. }
  4294. redirect($return);
  4295. }
  4296. /// Enable or disable the display of interactive activities
  4297. function visible_iassign ($return) {
  4298. global $DB;
  4299. $newentry = new stdClass();
  4300. $newentry->id = $this->activity->id;
  4301. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4302. if (!$DB->update_record('iassign_statement', $newentry))
  4303. print_error('error_update_visible_iassign', 'iassign');
  4304. redirect($return);
  4305. }
  4306. /// Add news interactive activities (register in table 'iassign_statement')
  4307. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4308. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4309. function new_iassign ($param) {
  4310. global $DB;
  4311. $newentry = new stdClass();
  4312. $newentry->iassignid = $param->iassignid;
  4313. $newentry->name = $param->name;
  4314. $newentry->type_iassign = $param->type_iassign;
  4315. $newentry->store_all_submissions = $param->store_all_submissions;
  4316. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4317. $proposition = $param->proposition;
  4318. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4319. else $proposition_text = $proposition;
  4320. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4321. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4322. //TODO Then get it directly from the form data $_POST!
  4323. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4324. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4325. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4326. $newentry->author_name = $param->author_name;
  4327. $newentry->author_modified_name = $param->author_modified_name;
  4328. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4329. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4330. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4331. $newentry->grade = $param->grade;
  4332. $newentry->timemodified = time();
  4333. $newentry->timecreated = time();
  4334. if ($param->type_iassign == 1) {
  4335. $newentry->timedue = 0;
  4336. $newentry->timeavailable = 0;
  4337. } // if ($param->type_iassign == 1)
  4338. else {
  4339. $newentry->timedue = $param->timedue;
  4340. $newentry->timeavailable = $param->timeavailable;
  4341. }
  4342. $newentry->preventlate = $param->preventlate;
  4343. $newentry->test = $param->test;
  4344. $newentry->special_param1 = $param->special_param1;
  4345. $newentry->visible = $param->visible;
  4346. $newentry->position = $param->position;
  4347. $newentry->max_experiment = $param->max_experiment;
  4348. $newentry->dependency = $param->dependency;
  4349. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4350. $newentry->show_answer = $param->show_answer;
  4351. $id = $DB->insert_record("iassign_statement", $newentry);
  4352. if ($id) {
  4353. $component = 'mod_iassign';
  4354. $filearea = 'exercise';
  4355. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4356. $file = $fs->get_file_by_id($param->file);
  4357. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4358. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4359. //$itemid = $id;
  4360. // File already inserted in other context!
  4361. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4362. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4363. $updateentry = new stdClass();
  4364. $updateentry->id = $id;
  4365. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4366. $updateentry->filesid = $newfile->get_itemid();
  4367. if (!$DB->update_record("iassign_statement", $updateentry))
  4368. print_error('error_add', 'iassign');
  4369. if ($param->type_iassign == 3)
  4370. iassign::update_grade_iassign($param->iassignid);
  4371. //TODO iLM_HTML5 :: //MOOC2014
  4372. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4373. //D if ($iassign_ilm_configs) {
  4374. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4375. //D if ($iassign_ilm_config->param_type != 'static') {
  4376. //D $newentry = new stdClass();
  4377. //D $newentry->iassign_statementid = $id;
  4378. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4379. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4380. //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});
  4381. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4382. //D print_error('error_add_param', 'iassign');
  4383. //D }
  4384. //D }
  4385. //D }
  4386. // log event --------------------------------------------------------------------------------------
  4387. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4388. // log event --------------------------------------------------------------------------------------
  4389. return $id;
  4390. }
  4391. else
  4392. print_error('error_add', 'iassign');
  4393. } // function new_iassign($param)
  4394. /// Add the calendar entries for this iassign
  4395. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4396. // @return bool
  4397. static function add_calendar ($iassignid) {
  4398. global $DB, $CFG;
  4399. require_once($CFG->dirroot . '/calendar/lib.php');
  4400. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4401. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4402. $event = new stdClass();
  4403. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4404. $event->description = $iassign_statement_activity_item->name;
  4405. $event->courseid = $iassign->course;
  4406. $event->groupid = 0;
  4407. $event->userid = 0;
  4408. $event->modulename = 'iassign';
  4409. $event->instance = $iassign->id;
  4410. $event->eventtype = 'due';
  4411. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4412. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4413. calendar_event::create($event);
  4414. }
  4415. /// Update the calendar entries for this iassign
  4416. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4417. // @return bool
  4418. function update_calendar ($iassignid, $olddescription) {
  4419. global $DB, $CFG;
  4420. require_once($CFG->dirroot . '/calendar/lib.php');
  4421. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4422. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4423. $event = new stdClass();
  4424. $event->id = 0;
  4425. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4426. if ($events) {
  4427. foreach ($events as $value) {
  4428. if ($value->description == $olddescription) {
  4429. $event->id = $value->id;
  4430. }
  4431. }
  4432. }
  4433. if ($event->id != 0) {
  4434. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4435. $event->description = $iassign_statement_activity_item->name;
  4436. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4437. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4438. $calendarevent = calendar_event::load($event->id);
  4439. $calendarevent->update($event);
  4440. } else
  4441. $this->add_calendar($iassignid);
  4442. }
  4443. /// Update the calendar entries for this iassign
  4444. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4445. // @return bool
  4446. function delete_calendar ($iassignid) {
  4447. global $DB, $CFG;
  4448. require_once($CFG->dirroot . '/calendar/lib.php');
  4449. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4450. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4451. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4452. if ($events) {
  4453. foreach ($events as $value) {
  4454. if ($value->description == $iassign_statement_activity_item->name) {
  4455. $DB->delete_records('event', array('id' => $value->id));
  4456. }
  4457. }
  4458. }
  4459. }
  4460. /// Update interactive activities
  4461. function update_iassign ($param) {
  4462. global $DB;
  4463. $component = 'mod_iassign';
  4464. $filearea = 'exercise';
  4465. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4466. $file = $fs->get_file_by_id($param->file);
  4467. $fileold = $fs->get_file_by_id($param->fileold);
  4468. if ($param->file != $param->fileold) {
  4469. if ($fileold) {
  4470. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4471. foreach ($fileoldarea as $value) {
  4472. $value->delete();
  4473. }
  4474. }
  4475. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4476. $itemid = $file->get_itemid() + $param->iassign_id;
  4477. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4478. $param->file = $newfile->get_itemid();
  4479. } else
  4480. $param->file = $file->get_itemid();
  4481. } else {
  4482. $param->file = $file->get_itemid();
  4483. }
  4484. $newentry = new stdClass();
  4485. $newentry->id = $param->iassign_id;
  4486. $newentry->name = $param->name;
  4487. $newentry->type_iassign = $param->type_iassign;
  4488. $newentry->store_all_submissions = $param->store_all_submissions;
  4489. //2019 $newentry->proposition = $param->proposition;
  4490. $proposition = $param->proposition;
  4491. if (is_array($proposition))
  4492. $proposition_text = $proposition['text'];
  4493. else
  4494. $proposition_text = $proposition;
  4495. $newentry->proposition = $proposition_text;
  4496. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4497. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4498. $newentry->grade = $param->grade;
  4499. $newentry->author_modified_name = $param->author_modified_name;
  4500. $newentry->timemodified = time();
  4501. if ($param->type_iassign == 1) {
  4502. $newentry->timedue = 0;
  4503. $newentry->timeavailable = 0;
  4504. } // if ($param->type_iassign == 1)
  4505. else {
  4506. $newentry->timedue = $param->timedue;
  4507. $newentry->timeavailable = $param->timeavailable;
  4508. }
  4509. $newentry->preventlate = $param->preventlate;
  4510. $newentry->test = $param->test;
  4511. if (isset($param->special_param1))
  4512. $newentry->special_param1 = $param->special_param1;
  4513. else
  4514. $newentry->special_param1 = NULL;
  4515. $newentry->visible = $param->visible;
  4516. $newentry->max_experiment = $param->max_experiment;
  4517. $newentry->dependency = $param->dependency;
  4518. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4519. $newentry->show_answer = $param->show_answer;
  4520. if (!$DB->update_record("iassign_statement", $newentry))
  4521. print_error('error_update', 'iassign');
  4522. if ($param->type_iassign == 3) {
  4523. iassign::update_grade_iassign($param->iassignid);
  4524. }
  4525. //$id = $newentry->id; // MOOC 2016 --- inicio
  4526. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4527. //if ($iassign_activity_item_configs) {
  4528. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4529. // $newentry = new stdClass();
  4530. // $newentry->id = $iassign_activity_item_config->id;
  4531. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4532. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4533. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4534. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4535. // print_error('error_edit_param', 'iassign');
  4536. // }
  4537. // } // MOOC 2016 --- final
  4538. // log event --------------------------------------------------------------------------------------
  4539. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4540. // log event --------------------------------------------------------------------------------------
  4541. return $newentry->id;
  4542. // if ($param->type_iassign==3)
  4543. // $this->update_grade_iassign($param->iassignid);
  4544. } // function update_iassign($param)
  4545. /// Show information of activity
  4546. function show_info_iassign () {
  4547. global $DB, $OUTPUT;
  4548. $output = '';
  4549. if ($this->activity->type_iassign == 3) {
  4550. if ($this->activity->dependency == 0) {
  4551. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4552. } else {
  4553. $dependencys = explode(';', $this->activity->dependency);
  4554. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4555. foreach ($dependencys as $dependency) {
  4556. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4557. if ($dependencyiassign)
  4558. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4559. } // foreach ($dependencys as $dependency)
  4560. } // if ($iassign_statement_activity_item->dependency == 0)
  4561. if ($this->activity->max_experiment == 0)
  4562. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4563. else
  4564. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4565. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4566. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4567. $output .= $this->toggle_columns_script();
  4568. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4569. print $OUTPUT->box($output);
  4570. } // function show_info_iassign()
  4571. /// Provide script to toggle columns
  4572. static function toggle_columns_script () {
  4573. $output = "";
  4574. $output .= '<script>
  4575. function toLeft () {
  4576. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4577. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4578. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4579. document.getElementById("columnsbutton").style.color = "#1da075";
  4580. }
  4581. function toDefault () {
  4582. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4583. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4584. document.getElementById("fullscreen").style.marginTop = "0";
  4585. document.getElementById("columnsbutton").style.color = "#343a40";
  4586. }
  4587. var activate = false;
  4588. function toggleColumns () {
  4589. if (activate) {
  4590. activate = false;
  4591. toDefault();
  4592. } else {
  4593. activate = true;
  4594. toLeft();
  4595. }
  4596. }
  4597. </script>';
  4598. $output .= '<span tabindex="0" data-toggle="tooltip" title="'.get_string('enable_disable_columns', 'iassign').'" style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>';
  4599. return $output;
  4600. }
  4601. /// Shows date of opening and closing activities
  4602. function view_dates () {
  4603. global $USER, $CFG, $DB, $OUTPUT;
  4604. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4605. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4606. $status_iassign = "";
  4607. $status_iassign1 = "";
  4608. $status_iassign2 = "";
  4609. if ($this->activity->type_iassign == 1) // activity of type example
  4610. $type_iassign = get_string('example_iassign', 'iassign');
  4611. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4612. $type_iassign = get_string('test_iassign', 'iassign');
  4613. if ($this->activity->timeavailable > time()) {
  4614. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4615. } elseif ($this->activity->timedue < time()) {
  4616. $status_iassign = get_string('last_timedue', 'iassign');
  4617. }
  4618. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4619. $type_iassign = get_string('exercise_iassign', 'iassign');
  4620. if ($this->activity->timeavailable > time()) {
  4621. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4622. } elseif ($this->activity->timedue < time()) { // after delivery
  4623. $status_iassign = get_string('last_timedue', 'iassign');
  4624. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4625. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4626. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4627. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4628. if ($this->activity->test == 1) // allowed to test after of deadline
  4629. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4630. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4631. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4632. } // elseif ($iassign_statement_activity_item->test == 0)
  4633. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4634. } // elseif ($iassign_statement_activity_item->timedue < time())
  4635. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4636. $output = '<table width=100% >' . "\n";
  4637. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4638. $output .= '<tr>' . "\n";
  4639. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4640. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4641. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4642. // leo $output .= '<td width=80%>' . $type_iassign;
  4643. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4644. // $output .= '</td>' . "\n";
  4645. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4646. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4647. $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>";
  4648. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4649. } else {
  4650. $link_next = "";
  4651. $link_previous = "";
  4652. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4653. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4654. // previous_activity
  4655. if ($iassign_previous) {
  4656. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4657. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4658. } // next_activity
  4659. if ($iassign_next) {
  4660. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4661. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4662. }
  4663. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4664. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4665. $output .= '</tr></table>' . "\n";
  4666. $output .= '<table width=100% >' . "\n";
  4667. if ($this->activity->type_iassign > 1) {
  4668. if ($this->activity->timeavailable)
  4669. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4670. if ($this->activity->timedue)
  4671. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4672. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4673. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4674. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4675. $output .= '</table>' . "\n";
  4676. print $OUTPUT->box($output);
  4677. } // function view_dates()
  4678. } // class activity
  4679. /// Class to manage Interactive Learning Module (iLM)
  4680. class ilm {
  4681. var $ilm;
  4682. /// Constructor of class
  4683. // @param int $id Id of iLM
  4684. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4685. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4686. function __construct ($id) {
  4687. global $DB;
  4688. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4689. if (empty($this->ilm))
  4690. $this->ilm = null;
  4691. }
  4692. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4693. // @calledby view_iassign_current()
  4694. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4695. global $USER, $CFG, $DB;
  4696. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4697. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4698. $typec = strtolower($iassign_ilm->type);
  4699. require_once 'ilm_handlers/' . $typec . '.php';
  4700. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4701. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4702. return $retorno;
  4703. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4704. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4705. // @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);
  4706. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4707. // @param Object $file File in use in activity
  4708. // @return int Return the id of log
  4709. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4710. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4711. $newentry = new stdClass();
  4712. $newentry->iassign_statementid = $iassign_activity_itemid;
  4713. $newentry->userid = $USER->id;
  4714. $newentry->filesid = $content_or_id_from_ilm_security;
  4715. $newentry->timecreated = time();
  4716. $newentry->view = 1;
  4717. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4718. if (!$id_iLM_security) {
  4719. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4720. } // from (!$DB->insert_record("iassign_security", $newentry))
  4721. return $id_iLM_security;
  4722. }
  4723. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4724. // @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);
  4725. // @param int $userid
  4726. // @param int $iassign_activity_itemid Id of iassign statement
  4727. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4728. global $DB;
  4729. // 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")
  4730. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4731. }
  4732. } // class ilm
  4733. /// Class to manage settings of iLM.
  4734. class ilm_settings {
  4735. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4736. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4737. // @param int $ilm_id Id of iLM
  4738. // @param array $options An array with options for create dynamic tag html APPLET
  4739. // @return string Return with a tag html APPLET created
  4740. static function build_ilm_tags ($ilm_id, $options = array()) {
  4741. global $DB;
  4742. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4743. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4744. $typec = strtolower($iassign_ilm->type);
  4745. require_once 'ilm_handlers/' . $typec . '.php';
  4746. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4747. return $retorno;
  4748. } // static function build_ilm_tags($ilm_id, $options = array())
  4749. /// Function for get modified date of iLM file
  4750. // @param string $file_jar String with Ids of iLM files
  4751. // @return string Return with the filenames and modified date
  4752. static function applet_filetime ($file_jar) {
  4753. $filetime = "";
  4754. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4755. $files_jar = explode(",", $file_jar);
  4756. foreach ($files_jar as $one_file) {
  4757. $file = $fs->get_file_by_id($one_file);
  4758. if ($file)
  4759. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4760. }
  4761. return $filetime;
  4762. }
  4763. /// Function for verify an default applet
  4764. // @param String $file_jar String containing an list de ids of applet files
  4765. // @return boolean Return true or fale if applet is default
  4766. static function applet_default ($file_jar) {
  4767. $is_default = true;
  4768. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4769. $files_jar = explode(",", $file_jar);
  4770. foreach ($files_jar as $one_file) {
  4771. $file = $fs->get_file_by_id($one_file);
  4772. if ($file)
  4773. $is_default &= ($file->get_itemid() == 0);
  4774. }
  4775. return $is_default;
  4776. }
  4777. /// Function for get form variables for add, edit, or copy iLM
  4778. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4779. // @see settings_form.php
  4780. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4781. // @param int $ilm_id Id of iLM
  4782. // @param string $action String with the action
  4783. // @return object Return an object with forms variables
  4784. static function add_edit_copy_ilm ($ilm_id, $action) {
  4785. global $USER, $DB, $CFG;
  4786. require_once('settings_form.php'); // put the form
  4787. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4788. $param = new stdClass();
  4789. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  4790. $param->action = $action;
  4791. $param->ilm_id = $ilm_id;
  4792. $CFG->action_ilm = $action;
  4793. $CFG->ilm_id = $ilm_id;
  4794. if ($action == 'add') {
  4795. $param->title = get_string('add_ilm', 'iassign');
  4796. $param->name = "";
  4797. $param->version = "";
  4798. $param->url = "";
  4799. $param->description = "";
  4800. $param->extension = "";
  4801. $param->author = $USER->id;
  4802. $param->file_jar = "";
  4803. $param->file_jar_static = "";
  4804. $param->file_class = "";
  4805. $param->width = 800;
  4806. $param->height = 600;
  4807. $param->enable = 0; // 0 - hide / 1 - show
  4808. $param->timecreated = time();
  4809. $param->timemodified = time();
  4810. $param->evaluate = 0;
  4811. $param->parent = 0;
  4812. }
  4813. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4814. if ($iassign_ilm) {
  4815. $description = json_decode($iassign_ilm->description);
  4816. $param->title = get_string('edit_ilm', 'iassign');
  4817. $param->id = $iassign_ilm->id;
  4818. $param->name_ilm = $iassign_ilm->name;
  4819. $param->name = $iassign_ilm->name;
  4820. $param->version = $iassign_ilm->version;
  4821. $param->ilm_type = $iassign_ilm->type;
  4822. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4823. $param->url = $iassign_ilm->url; // iLM official URL
  4824. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  4825. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4826. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4827. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4828. if (!isset($description->{current_language()})) {
  4829. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4830. else
  4831. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4832. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4833. }
  4834. else
  4835. $param->description = $description->{current_language()};
  4836. $param->description_lang = $iassign_ilm->description;
  4837. $param->extension = $iassign_ilm->extension;
  4838. $param->author = $iassign_ilm->author;
  4839. $param->file_jar = $iassign_ilm->file_jar;
  4840. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4841. $param->file_class = $iassign_ilm->file_class;
  4842. $param->width = $iassign_ilm->width;
  4843. $param->height = $iassign_ilm->height;
  4844. $param->enable = $iassign_ilm->enable;
  4845. $param->timecreated = $iassign_ilm->timecreated;
  4846. $param->timemodified = time();
  4847. $param->evaluate = $iassign_ilm->evaluate;
  4848. $param->parent = $iassign_ilm->parent;
  4849. }
  4850. }
  4851. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4852. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4853. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4854. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4855. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4856. // echo "Sem dados<br/>"; exit;
  4857. return;
  4858. }
  4859. $description = json_decode($iassign_ilm->description);
  4860. if ($iassign_ilm) {
  4861. if ($iassign_ilm->parent == 0)
  4862. $iassign_ilm->parent = $ilm_id;
  4863. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4864. $param->title = get_string('new_version_ilm', 'iassign');
  4865. $param->name_ilm = $iassign_ilm->name;
  4866. $param->name = $iassign_ilm->name;
  4867. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4868. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4869. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4870. $param->ilm_type = $iassign_ilm->type;
  4871. $param->url = $iassign_ilm->url;
  4872. $param->description = $description->{current_language()};
  4873. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4874. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4875. $param->extension = $iassign_ilm->extension;
  4876. $param->author = $USER->id;
  4877. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4878. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4879. $param->file_jar_static = '';
  4880. $param->file_class = $iassign_ilm->file_class;
  4881. $param->width = $iassign_ilm->width;
  4882. $param->height = $iassign_ilm->height;
  4883. $param->enable = 0;
  4884. $param->timecreated = time();
  4885. $param->timemodified = time();
  4886. $param->evaluate = $iassign_ilm->evaluate;
  4887. $param->parent = $iassign_ilm->parent;
  4888. }
  4889. }
  4890. elseif ($action == 'copy') {
  4891. $description = json_decode($iassign_ilm->description);
  4892. if ($iassign_ilm) {
  4893. if ($iassign_ilm->parent == 0)
  4894. $iassign_ilm->parent = $ilm_id;
  4895. $param->title = get_string('copy_ilm', 'iassign');
  4896. $param->id = $iassign_ilm->id;
  4897. $param->name_ilm = $iassign_ilm->name;
  4898. $param->name = $iassign_ilm->name;
  4899. $param->version = "";
  4900. $param->ilm_type = $iassign_ilm->type;
  4901. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4902. $param->url = $iassign_ilm->url;
  4903. $param->description = $description->{current_language()};
  4904. $param->description_lang = $iassign_ilm->description;
  4905. $param->extension = $iassign_ilm->extension;
  4906. $param->author = $USER->id;
  4907. $param->file_jar = '';
  4908. $param->file_jar_static = '';
  4909. $param->file_class = $iassign_ilm->file_class;
  4910. $param->width = $iassign_ilm->width;
  4911. $param->height = $iassign_ilm->height;
  4912. $param->enable = 0;
  4913. $param->timecreated = time();
  4914. $param->timemodified = time();
  4915. $param->evaluate = $iassign_ilm->evaluate;
  4916. $param->parent = $iassign_ilm->parent;
  4917. }
  4918. }
  4919. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  4920. //D var_dump(debug_backtrace());
  4921. //D print_r(debug_backtrace());
  4922. return $param;
  4923. } // static function add_edit_copy_ilm($ilm_id, $action)
  4924. /// Function for save iLM file in moodledata
  4925. // @param int $itemid Itemid of file save in draft (upload file)
  4926. // @param int $ilm_id Id of iLM
  4927. // @return string Return an string with ids of iLM files
  4928. static function new_file_ilm ($itemid, $iassign_ilm) {
  4929. global $CFG, $USER, $DB;
  4930. $return = null;
  4931. $file_jar = array();
  4932. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4933. $contextuser = context_user::instance($USER->id);
  4934. $contextsystem = context_system::instance();
  4935. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4936. if ($files_ilm) {
  4937. foreach ($files_ilm as $value) {
  4938. // CHECK IF file is HTML type
  4939. if ($iassign_ilm->type == 1) {
  4940. // Check if the file extension is ZIP
  4941. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4942. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4943. if ((strtolower($ext) == 'zip')) {
  4944. // Coping...:
  4945. $destination = 'ilm_debug/' . $value->get_filename();
  4946. $value->copy_content_to($destination);
  4947. // Extracting content...:
  4948. $zip = new ZipArchive();
  4949. $extracted = './ilm';
  4950. $dir = "";
  4951. if ($zip->open($destination) === TRUE) {
  4952. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4953. if (is_dir($dir)) {
  4954. $i = 1;
  4955. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4956. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4957. $i ++;
  4958. }
  4959. $name = $previous . "_" . $i;
  4960. $dir = './ilm/' . $name . "/";
  4961. $j = 0;
  4962. while ($item_name = $zip->getNameIndex($j)) {
  4963. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4964. $j++;
  4965. }
  4966. $zip->close();
  4967. }
  4968. $zip->open($destination);
  4969. $zip->extractTo($extracted);
  4970. $zip->close();
  4971. // After the extraction, remove it from DEBUG
  4972. unlink($destination);
  4973. } else { // Error trying to open destination...
  4974. // After the extraction error, also remove it from DEBUG
  4975. unlink($destination);
  4976. print_error('error_add_ilm_zip', 'iassign');
  4977. }
  4978. return $dir;
  4979. }
  4980. } // if ($iassign_ilm->type == 1)
  4981. if ($value->get_filename() != '.') {
  4982. $file_ilm = array(
  4983. 'userid' => $USER->id,
  4984. 'contextid' => $contextsystem->id,
  4985. 'component' => 'mod_iassign',
  4986. 'filearea' => 'ilm',
  4987. 'itemid' => rand(1, 999999999),
  4988. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4989. 'filename' => $value->get_filename());
  4990. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4991. array_push($file_jar, $file_ilm->get_id());
  4992. }
  4993. }
  4994. if (!empty($file_jar)) {
  4995. $return = implode(",", $file_jar);
  4996. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4997. foreach ($old_file_jar as $value) {
  4998. $file = $fs->get_file_by_id($value);
  4999. if ($file)
  5000. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  5001. }
  5002. }
  5003. }
  5004. else // if ($files_ilm)
  5005. $return = $iassign_ilm->file_jar;
  5006. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  5007. return $return;
  5008. } // static function new_file_ilm($itemid, $iassign_ilm)
  5009. /// Function for save in database an new iLM
  5010. // @param object $param An object with iLM params
  5011. static function new_ilm ($itemid) {
  5012. global $CFG, $USER, $OUTPUT;
  5013. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5014. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5015. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5016. }
  5017. $pathtemp = $CFG->dataroot . '/temp/';
  5018. $contextuser = context_user::instance($USER->id);
  5019. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5020. $zip = new zip_packer();
  5021. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5022. foreach ($files as $file) {
  5023. if (!$file->is_directory())
  5024. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5025. }
  5026. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5027. // Verifica se o pacote possui o XML
  5028. if (!$application_xml) {
  5029. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5030. return;
  5031. } else {
  5032. $missing = "";
  5033. if (!isset($application_xml->name)) {
  5034. $missing .= "name";
  5035. }
  5036. if (!isset($application_xml->version)) {
  5037. $missing .= ", version";
  5038. }
  5039. if (!isset($application_xml->type)) {
  5040. $missing .= ", type";
  5041. }
  5042. if (!isset($application_xml->extension)) {
  5043. $missing .= ", extension";
  5044. }
  5045. if (!isset($application_xml->file_jar)) {
  5046. $missing .= ", file_jar";
  5047. }
  5048. if (!isset($application_xml->file_class)) {
  5049. $missing .= ", file_class";
  5050. }
  5051. if (!isset($application_xml->width)) {
  5052. $missing .= ", width";
  5053. }
  5054. if (!isset($application_xml->height)) {
  5055. $missing .= ", height";
  5056. }
  5057. if (!isset($application_xml->evaluate)) {
  5058. $missing .= ", evaluate";
  5059. }
  5060. if (strlen($missing) > 2) {
  5061. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5062. return;
  5063. }
  5064. }
  5065. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5066. $typec = strtolower($application_xml->type);
  5067. require_once 'ilm_handlers/' . $typec . '.php';
  5068. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5069. return $retorno;
  5070. } // static function new_ilm($itemid)
  5071. /// Function for save in database an iLM edit
  5072. // @param object $param An object with iLM params
  5073. static function edit_ilm ($param, $itemid) {
  5074. // Descobrir o tipo de iLM:
  5075. global $DB, $USER, $CFG;
  5076. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5077. $pathtemp = $CFG->dataroot . '/temp/';
  5078. $contextuser = context_user::instance($USER->id);
  5079. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5080. $zip = new zip_packer();
  5081. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5082. $files_extract = null;
  5083. foreach ($files as $file) {
  5084. if (!$file->is_directory())
  5085. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5086. }
  5087. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5088. $typec = strtolower($iassign_t->type);
  5089. require_once 'ilm_handlers/' . $typec . '.php';
  5090. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5091. }
  5092. /// Function for register the new iLM (in database and in the directory)
  5093. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5094. // @param object $param An object with iLM params
  5095. static function copy_new_version_ilm ($param) {
  5096. global $DB, $CFG, $USER;
  5097. $itemid = $param->file;
  5098. $pathtemp = $CFG->dataroot . '/temp/';
  5099. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5100. //D echo "pathtemp=$pathtemp<br/>";
  5101. $contextuser = context_user::instance($USER->id);
  5102. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5103. $zip = new zip_packer();
  5104. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5105. $files_extract = null;
  5106. foreach ($files as $file) {
  5107. if (!$file->is_directory())
  5108. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5109. }
  5110. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5111. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5112. $typec = strtolower($iassign_t->type);
  5113. require_once 'ilm_handlers/' . $typec . '.php';
  5114. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5115. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5116. } // static function copy_new_version_ilm($param)
  5117. //VER::
  5118. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5119. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5120. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5121. /// Function for change visibility of iLM
  5122. // @param int $ilm_id Id of iLM
  5123. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5124. static function visible_ilm ($ilm_id, $status) {
  5125. global $DB;
  5126. if ($status == 0)
  5127. $visible = 1;
  5128. else
  5129. $visible = 0;
  5130. $newentry = new stdClass();
  5131. $newentry->id = $ilm_id;
  5132. $newentry->enable = $visible;
  5133. if (!$DB->update_record("iassign_ilm", $newentry))
  5134. error(get_string('error_edit_ilm', 'iassign'));
  5135. }
  5136. /// Function for confirm change default iLM
  5137. // @param int $ilm_id Id of iLM
  5138. // @param int $ilm_parent Id of parent iLM
  5139. // @return string Return with an string for create default page confirmation
  5140. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5141. global $OUTPUT, $DB;
  5142. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5143. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5144. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5145. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5146. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5147. return $return;
  5148. }
  5149. /// Function for change the default iLM
  5150. // @see settings_ilm.php
  5151. // @param int $ilm_id Id of iLM
  5152. // @return int Return Id of default iLM
  5153. static function default_ilm ($ilm_id) {
  5154. global $DB;
  5155. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5156. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5157. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5158. $iassign_ilm_default->id = $iassign_ilm->id;
  5159. $iassign_ilm_default->parent = 0;
  5160. $iassign_ilm->parent = $iassign_ilm_default->id;
  5161. $iassign_ilm->id = 0;
  5162. $iassign_ilm_default->enable = 1;
  5163. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5164. print_error('error_edit_ilm', 'iassign');
  5165. }
  5166. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5167. if (!$inserted) {
  5168. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5169. print_error($msg_error);
  5170. //xx print_error('error_add_ilm', 'iassign');
  5171. }
  5172. return $iassign_ilm_default->id;
  5173. } // static function default_ilm ($ilm_id)
  5174. /// Function for confirm delete iLM
  5175. // @param int $ilm_id Id of iLM
  5176. // @param int $ilm_parent Id of parent iLM
  5177. // @return string Return with an string for create delete page confirmation
  5178. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5179. global $OUTPUT, $DB;
  5180. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5181. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5182. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5183. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5184. }
  5185. /// Function for delete directory where the iLM is allocated.
  5186. // @param string $dirPath
  5187. // @throws InvalidArgumentException
  5188. public static function delete_dir ($dirPath) {
  5189. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5190. $dirPath .= '/';
  5191. }
  5192. $files = glob($dirPath . '*', GLOB_MARK);
  5193. foreach ($files as $file) {
  5194. if (is_dir($file)) {
  5195. ilm_settings::delete_dir($file);
  5196. } else {
  5197. unlink($file);
  5198. }
  5199. }
  5200. rmdir($dirPath);
  5201. }
  5202. /// Function for delete iLM
  5203. // @param int $ilm_id Id of iLM
  5204. // @return int Return Id of parent iLM
  5205. static function delete_ilm ($ilm_id) {
  5206. global $DB;
  5207. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  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::delete_ilm($ilm_id);
  5212. return $retorno;
  5213. }
  5214. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5215. // @param int $ilm_id Id of iLM
  5216. static function export_ilm ($ilm_id) {
  5217. global $DB;
  5218. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5219. if (!$iassign_ilm) return; // security debug...
  5220. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5221. $typec = strtolower($iassign_ilm->type);
  5222. if (!$typec) $typec = "html5"; // security debug...
  5223. require_once 'ilm_handlers/' . $typec . '.php';
  5224. $typec::export_ilm($ilm_id);
  5225. } // static function export_ilm($ilm_id)
  5226. //TODO iLM_HTML5 :: //MOOC 2016
  5227. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5228. // @param int $ilm_id Id of iLM
  5229. static function export_update_ilm ($ilm_id) {
  5230. global $DB, $CFG;
  5231. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5232. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5233. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5234. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5235. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5236. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5237. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5238. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5239. $upgrade_descriptor .= '</upgrade>' . "\n";
  5240. file_put_contents($xml_filename, $upgrade_descriptor);
  5241. header("Pragma: public");
  5242. header("Expires: 0");
  5243. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5244. header("Cache-Control: private", false);
  5245. header('Content-Type: application/xml; charset=utf-8');
  5246. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5247. header("Content-Length: " . @filesize($xml_filename));
  5248. set_time_limit(0);
  5249. @readfile("$xml_filename") || die("File not found.");
  5250. unlink($xml_filename);
  5251. exit;
  5252. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5253. /// Function for save iLM from XML descriptor
  5254. // @param array $application_xml Data of XML descriptor
  5255. // @param array $files_extract Filenames of extract files
  5256. // @return array Return an array content id of JAR files
  5257. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5258. global $CFG, $USER;
  5259. // Tratamento diferenciado se for do tipo HTML5:
  5260. $source = "";
  5261. $diretorio = "";
  5262. if (strtolower($application_xml->type) == 'html5') {
  5263. $i = 0;
  5264. foreach ($files_extract as $key => $value) {
  5265. $file = $CFG->dataroot . '/temp/' . $key;
  5266. // Verifica se já existe a pasta no diretório dos iLM:
  5267. if ($i == 0) {
  5268. $source = $file;
  5269. if (file_exists("ilm/" . basename($file))) {
  5270. $j = 1;
  5271. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5272. $j ++;
  5273. }
  5274. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5275. // mkdir($diretorio, 0777, true);
  5276. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5277. }
  5278. else {
  5279. $diretorio = 'ilm/' . basename($file);
  5280. // mkdir($diretorio, 0777, true);
  5281. mkdir($diretorio, 0755, true);
  5282. }
  5283. break;
  5284. }
  5285. $i ++;
  5286. }
  5287. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5288. if ($item->isDir()) {
  5289. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5290. }
  5291. else {
  5292. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5293. }
  5294. }
  5295. ilm_settings::delete_dir($source);
  5296. return "./" . $diretorio;
  5297. }
  5298. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5299. $file_jar = array();
  5300. $files_ilm = explode(",", $application_xml->file_jar);
  5301. $contextsystem = context_system::instance();
  5302. foreach ($files_ilm as $value) {
  5303. $file_ilm = array(
  5304. 'userid' => $USER->id,
  5305. 'contextid' => $contextsystem->id,
  5306. 'component' => 'mod_iassign',
  5307. 'filearea' => 'ilm',
  5308. 'itemid' => rand(1, 999999999),
  5309. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5310. 'filename' => $value);
  5311. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5312. array_push($file_jar, $file_ilm->get_id());
  5313. }
  5314. foreach ($files_extract as $key => $value) {
  5315. $file = $CFG->dataroot . '/temp/' . $key;
  5316. if (file_exists($file))
  5317. unlink($file);
  5318. }
  5319. return $file_jar;
  5320. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5321. /// Function for import the iLM from an package
  5322. // @param int $itemid Itemid of zip file
  5323. static function import_ilm ($itemid) {
  5324. global $CFG, $USER, $OUTPUT;
  5325. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5326. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5327. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5328. }
  5329. $pathtemp = $CFG->dataroot . '/temp/';
  5330. $contextuser = context_user::instance($USER->id);
  5331. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5332. $zip = new zip_packer();
  5333. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5334. foreach ($files as $file) {
  5335. if (!$file->is_directory())
  5336. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5337. }
  5338. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5339. // Verifica se o pacote possui o XML
  5340. if (!$application_xml) {
  5341. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5342. return;
  5343. } else {
  5344. $missing = "";
  5345. if (!isset($application_xml->name)) {
  5346. $missing .= "name";
  5347. }
  5348. if (!isset($application_xml->version)) {
  5349. $missing .= ", version";
  5350. }
  5351. if (!isset($application_xml->type)) {
  5352. $missing .= ", type";
  5353. }
  5354. if (!isset($application_xml->extension)) {
  5355. $missing .= ", extension";
  5356. }
  5357. if (!isset($application_xml->file_jar)) {
  5358. $missing .= ", file_jar";
  5359. }
  5360. if (!isset($application_xml->file_class)) {
  5361. $missing .= ", file_class";
  5362. }
  5363. if (!isset($application_xml->width)) {
  5364. $missing .= ", width";
  5365. }
  5366. if (!isset($application_xml->height)) {
  5367. $missing .= ", height";
  5368. }
  5369. if (!isset($application_xml->evaluate)) {
  5370. $missing .= ", evaluate";
  5371. }
  5372. if (strlen($missing) > 2) {
  5373. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5374. return;
  5375. }
  5376. }
  5377. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5378. $typec = strtolower($application_xml->type);
  5379. require_once 'ilm_handlers/' . $typec . '.php';
  5380. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5381. } // static function import_ilm($itemid)
  5382. /// Function for list iLM defaults
  5383. // @return string Return an string with a table of iLM
  5384. static function list_ilm () {
  5385. global $DB, $OUTPUT;
  5386. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5387. $str = '';
  5388. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5389. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5390. if ($iassign_ilm) {
  5391. foreach ($iassign_ilm as $ilm) {
  5392. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5393. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5394. $str .= '<tr><td>';
  5395. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5396. $str .= '<tr>';
  5397. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5398. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5399. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5400. $str .= '</tr>';
  5401. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5402. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5403. $str .= '</table>';
  5404. $str .= '</td></tr>';
  5405. }
  5406. }
  5407. $str .= '</table>';
  5408. return $str;
  5409. }
  5410. /// Function for download and install an upgrade of an iLM
  5411. // @param int $ilm_id Id of iLM
  5412. static function upgrade_ilm ($ilm_id) {
  5413. global $DB, $CFG, $USER;
  5414. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5415. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5416. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5417. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5418. if (!$result)
  5419. print_error('error_upgrade_ilm', 'iassign');
  5420. else {
  5421. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5422. $extension = explode(".", $zip_filename);
  5423. if ($extension[count($extension) - 1] != 'ipz') {
  5424. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5425. die;
  5426. }
  5427. $zip = new zip_packer();
  5428. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5429. $contextuser = context_user::instance($USER->id);
  5430. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5431. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5432. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5433. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5434. if (file_exists($zip_filename))
  5435. unlink($zip_filename);
  5436. if (empty($file_jar)) {
  5437. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5438. print_error($msg_error);
  5439. //xx print_error('error_add_ilm', 'iassign');
  5440. }
  5441. else {
  5442. $newentry = new stdClass();
  5443. $newentry->name = (String) $application_xml->name;
  5444. $newentry->version = (String) $application_xml->version;
  5445. $newentry->url = (String) $application_xml->url;
  5446. $newentry->description = $description_str;
  5447. $newentry->extension = strtolower((String) $application_xml->extension);
  5448. $newentry->file_jar = implode(",", $file_jar);
  5449. $newentry->file_class = (String) $application_xml->file_class;
  5450. $newentry->width = (String) $application_xml->width;
  5451. $newentry->height = (String) $application_xml->height;
  5452. $newentry->enable = 0;
  5453. $newentry->timemodified = time();
  5454. $newentry->author = $USER->id;
  5455. $newentry->timecreated = time();
  5456. $newentry->evaluate = (String) $application_xml->evaluate;
  5457. $newentry->parent = $ilm_id;
  5458. }
  5459. }
  5460. return $iassign_ilm->id;
  5461. } // static function upgrade_ilm($ilm_id)
  5462. //MOOC2014 -- inicio
  5463. //TODO: REVIEW
  5464. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5465. // static function move_iassign($ilm_id)
  5466. //MOOC2014 -- final
  5467. /// Function for list iLM versions with all informations
  5468. // @return string Return an string with a table of iLM
  5469. static function view_ilm ($ilmid, $from) {
  5470. global $DB;
  5471. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5472. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5473. $typec = strtolower($iassign_ilm->type);
  5474. require_once 'ilm_handlers/' . $typec . '.php';
  5475. $retorno = $typec::view_ilm($ilmid, $from);
  5476. return $retorno;
  5477. }
  5478. /// Function for get form variables for add, edit, or copy iLM params
  5479. // @param int $ilm_param_id Id of iLM param
  5480. // @param string $action String with the action
  5481. // @return object Return an object with forms variables
  5482. static function add_edit_copy_param ($ilm_param_id, $action) {
  5483. global $DB;
  5484. require_once('params_form.php');
  5485. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5486. $param = new stdClass();
  5487. $param->action = $action;
  5488. $param->ilm_param_id = $ilm_param_id;
  5489. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5490. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5491. $type = $iassign_ilm_config->param_type;
  5492. if ($action == 'add') {
  5493. $param->title = get_string('add_ilm', 'iassign');
  5494. $param->iassign_ilmid = $ilm_param_id;
  5495. $param->param_name = "";
  5496. $param->param_value = "";
  5497. $param->description = "";
  5498. $param->visible = 1;
  5499. }
  5500. elseif ($action == 'edit') {
  5501. if ($iassign_ilm_config) {
  5502. $param->title = get_string('edit_ilm', 'iassign');
  5503. $param->id = $iassign_ilm_config->id;
  5504. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5505. $param->param_type = $type; //MOOC2014
  5506. $param->param_name = $iassign_ilm_config->param_name;
  5507. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5508. $param->param_value = $iassign_ilm_config->param_value;
  5509. else //MOOC2014
  5510. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5511. $param->param_value = $iassign_ilm_config->param_value;
  5512. $param->description = $iassign_ilm_config->description;
  5513. $param->visible = $iassign_ilm_config->visible;
  5514. }
  5515. }
  5516. elseif ($action == 'copy') {
  5517. if ($iassign_ilm_config) {
  5518. $param->title = get_string('copy_ilm', 'iassign');
  5519. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5520. $param->param_type = $type; //MOOC2014
  5521. $param->param_name = $iassign_ilm_config->param_name;
  5522. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5523. $param->param_value = $iassign_ilm_config->param_value;
  5524. else //MOOC2014
  5525. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5526. $param->description = $iassign_ilm_config->description;
  5527. $param->visible = $iassign_ilm_config->visible;
  5528. }
  5529. }
  5530. return $param;
  5531. } // static function add_edit_copy_param($ilm_param_id, $action)
  5532. /// Function for change visibility of iLM param
  5533. // @param int $ilm_param_id Id of iLM param
  5534. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5535. static function visible_param ($ilm_param_id, $status) {
  5536. global $DB, $CFG;
  5537. if ($status == 0)
  5538. $visible = 1;
  5539. else
  5540. $visible = 0;
  5541. $newentry = new stdClass();
  5542. $newentry->id = $ilm_param_id;
  5543. $newentry->visible = $visible;
  5544. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5545. error(get_string('error_edit_param', 'iassign'));
  5546. }
  5547. /// Function for save in database an new iLM param
  5548. // @param object $param An object with iLM params
  5549. static function add_param ($param) {
  5550. global $DB;
  5551. $newentry = new stdClass();
  5552. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5553. //MOOC2014 $newentry->param_name = $param->param_name;
  5554. $newentry->param_type = $param->param_type; //MOOC2014
  5555. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5556. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5557. $newentry->param_value = $param->param_value;
  5558. else //MOOC2014
  5559. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5560. $newentry->description = $param->description;
  5561. $newentry->visible = $param->visible;
  5562. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5563. if (!$newentry->id) {
  5564. print_error('error_add_param', 'iassign');
  5565. }
  5566. }
  5567. /// Function for save in database a iLM param edit
  5568. // @param object $param An object with iLM params
  5569. static function edit_param ($param) {
  5570. global $DB;
  5571. $updentry = new stdClass();
  5572. $updentry->id = $param->id;
  5573. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5574. $updentry->param_type = $param->param_type; //MOOC2014
  5575. // $updentry->param_name = $param->param_name;
  5576. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5577. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5578. $updentry->param_value = $param->param_value;
  5579. else //MOOC2014
  5580. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5581. $updentry->description = $param->description;
  5582. $updentry->visible = $param->visible;
  5583. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5584. error(get_string('error_edit_param', 'iassign'));
  5585. }
  5586. }
  5587. /// Function for save in database a iLM param copy
  5588. // @param object $param An object with iLM params
  5589. static function copy_param ($param) {
  5590. global $DB;
  5591. $newentry = new stdClass();
  5592. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5593. //$newentry->param_name = $param->param_name;
  5594. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5595. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5596. $newentry->param_value = $param->param_value;
  5597. else //MOOC2014
  5598. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5599. $newentry->description = $param->description;
  5600. $newentry->visible = $param->visible;
  5601. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5602. if (!$newentry->id) {
  5603. print_error('error_add_param', 'iassign');
  5604. }
  5605. }
  5606. /// Function for delete iLM param of database
  5607. // @param int $param_id Id of iLM param
  5608. static function delete_param ($param_id) {
  5609. global $DB;
  5610. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5611. print_error('error_delete_param', 'iassign');
  5612. }
  5613. }
  5614. } // class ilm_settings
  5615. /// Class for manage iLM files (editor).
  5616. class ilm_manager {
  5617. var $id; // course id
  5618. var $url;
  5619. var $from;
  5620. /// Constructor for the base ilm_manager class
  5621. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5622. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5623. function __construct ($id, $url, $from) {
  5624. $this->id = $id; // course id
  5625. $this->url = $url;
  5626. $this->from = $from;
  5627. }
  5628. /// Function to get iAssign content file in Moodle data (exercise)
  5629. // @calledby x function preview_ilm($iassign_ilm) :
  5630. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5631. function get_file_ilm () {
  5632. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5633. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5634. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5635. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5636. $md_file = $fs->get_file_by_id($fileid);
  5637. $ilm_content_file = $md_file->get_content();
  5638. return $ilm_content_file;
  5639. }
  5640. /// Function for creating a new file from the iLM online editor
  5641. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5642. function ilm_editor_new () {
  5643. global $CFG, $DB, $OUTPUT, $PAGE;
  5644. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5645. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5646. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5647. $context = context_course::instance($this->id);
  5648. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5649. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5650. if (!$iassign) {
  5651. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5652. die();
  5653. }
  5654. $temp = explode(",", $iassign->extension);
  5655. $extension = $temp[0]; // default extension for this iLM
  5656. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5657. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5658. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5659. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5660. if ($stringArchiveContent != NULL) {
  5661. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5662. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5663. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5664. $filename = optional_param('filename', NULL, PARAM_RAW);
  5665. //Leo $filename = iassign_utils::format_filename($filename); //
  5666. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5667. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5668. //2019/02 $arrayfilename = explode(".", $filename);
  5669. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5670. //2019/02 $count_dots = count($arrayfilename);
  5671. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5672. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5673. //2019/02 if ($last_name != $extension)
  5674. //2019/02 $filename = $filename . '.' . $extension;
  5675. //2019/02 }
  5676. //2019/02 else { // no extension...
  5677. //2019/02 $filename = $filename . '.' . $extension;
  5678. //2019/02 }
  5679. // Store the name of recent created file
  5680. $_SESSION['file_name'] = $filename;
  5681. //$this->write_file_iassign($string, $filename);
  5682. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5683. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5684. die();
  5685. }
  5686. else { // if ($stringArchiveContent != NULL)
  5687. // iLM On-line editor
  5688. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5689. $str_get_iLM = "window.frames.iLM";
  5690. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5691. }
  5692. else { // otherwise it is JAR named 'iLM'
  5693. $str_get_iLM = "document.iLM";
  5694. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5695. }
  5696. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5697. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5698. $files_array = '';
  5699. foreach ($files as $value) {
  5700. if ($value->get_filename() != ".")
  5701. $files_array .= "'" . $value->get_filename() . "',";
  5702. }
  5703. $files_array .= "''";
  5704. $file = null;
  5705. $ia_content = "";
  5706. $filename = "";
  5707. $error_files_exists = get_string('error_file_exists', 'iassign');
  5708. $output = "<script type='text/javascript'>
  5709. //<![CDATA[
  5710. //D alert('locallib.php: ilm_editor_new');
  5711. function submit_iLM_Answer () {
  5712. var docFormOnLineEditor = document.formEnvio;
  5713. var resposta_exerc = new Array(3);
  5714. var valor_resposta = new Array(3);
  5715. var sessao = new Array(3);
  5716. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5717. resposta_exerc[0] = doc_iLM.getAnswer();
  5718. valor_resposta[0] = doc_iLM.getEvaluation();
  5719. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5720. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5721. var files = new Array(" . $files_array . ");
  5722. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5723. if (docFormOnLineEditor.filename.value=='') {
  5724. // ERROR: the file name is empty
  5725. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5726. return false;
  5727. }
  5728. // }
  5729. for (i=0; i<files.length; i++) {
  5730. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5731. alert('" . $error_files_exists . "');
  5732. return false;
  5733. }
  5734. }
  5735. docFormOnLineEditor.submit();
  5736. return true;
  5737. }
  5738. //]]>
  5739. </script>\n";
  5740. $output .= "
  5741. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5742. $output .= $OUTPUT->box_start();
  5743. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5744. $output .= "
  5745. <table width='100%' cellpadding='20'>
  5746. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5747. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5748. </tr>
  5749. </table>\n";
  5750. $output .= $OUTPUT->box_end();
  5751. $output .= "<center>\n";
  5752. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5753. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5754. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5755. $output .= $output_ilm;
  5756. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5757. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5758. </center>
  5759. </form>\n";
  5760. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5761. $PAGE->navbar->add($title);
  5762. $PAGE->set_title($title);
  5763. $PAGE->set_heading($title); // insert title above the navigation bar
  5764. print $OUTPUT->header();
  5765. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5766. print $output;
  5767. print $OUTPUT->footer();
  5768. }
  5769. die();
  5770. } // function ilm_editor_new()
  5771. /// Function for editing an file in online editor
  5772. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5773. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5774. global $CFG, $DB, $OUTPUT, $PAGE;
  5775. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5776. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5777. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5778. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5779. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5780. // If iLM is not registered, error!
  5781. if (!$iassign) {
  5782. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5783. die;
  5784. }
  5785. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5786. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5787. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5788. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5789. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5790. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5791. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5792. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5793. if ($stringArchiveContent != NULL) {
  5794. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5795. die();
  5796. } else { // if ($stringArchiveContent != NULL)
  5797. $end_file = '';
  5798. if ($content_file) {
  5799. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5800. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5801. }
  5802. $temp = explode(",", $iassign->extension);
  5803. $extension = $temp[0]; // default extension for this iLM
  5804. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5805. $str_get_iLM = "window.frames.iLM";
  5806. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5807. } else { // otherwise it is JAR named 'iLM'
  5808. $str_get_iLM = "document.iLM";
  5809. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5810. }
  5811. $output = "<script type='text/javascript'>
  5812. //<![CDATA[
  5813. function submit_iLM_Answer () {
  5814. var docFormEditor = document.formEnvio;
  5815. var activityAnswer; // to get activity answer (text)
  5816. var activityValue; // to get activity answer value (float)
  5817. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5818. //activityAnswer = doc_iLM.getAnswer();
  5819. //activityValue = doc_iLM.getEvaluation();
  5820. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5821. activityValue = " . $str_get_iLM . ".getEvaluation();
  5822. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5823. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5824. docFormEditor.submit();
  5825. return true;
  5826. }
  5827. //]]>
  5828. </script>\n";
  5829. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5830. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5831. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5832. // return true;
  5833. // }
  5834. $output .= "
  5835. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5836. $output .= $OUTPUT->box_start();
  5837. $output .= "
  5838. <table width='100%' cellpadding='20'>
  5839. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5840. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5841. <input type='hidden' name='filename' value='$filename'/></td>
  5842. <td>
  5843. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5844. </tr>
  5845. </table>\n";
  5846. $output .= $OUTPUT->box_end();
  5847. $output .= " <center>\n";
  5848. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5849. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5850. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5851. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5852. </center>
  5853. </form>\n";
  5854. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5855. $PAGE->navbar->add($title);
  5856. $PAGE->set_title($title);
  5857. $PAGE->set_heading($title); // insert title above the navigation bar
  5858. print $OUTPUT->header();
  5859. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5860. print $output;
  5861. print $OUTPUT->footer();
  5862. } // else if ($stringArchiveContent != NULL)
  5863. die();
  5864. } // function ilm_editor_update()
  5865. /// Function for write iAssign file in Moodle data (exercise)
  5866. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5867. // @param string $stringArchiveContent Content of iassign file
  5868. // @param string $filename Filename of iassign file
  5869. function write_file_iassign ($stringArchiveContent, $filename) {
  5870. global $USER;
  5871. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5872. $context = context_course::instance($this->id);
  5873. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5874. $dirid = $this->get_dir_ilm('dirid');
  5875. $dir = $fs->get_file_by_id($dirid);
  5876. $fileinfo = array('contextid' => $context->id, // ID of course
  5877. 'component' => 'mod_iassign', // usually = table name
  5878. 'filearea' => 'activity', // usually = table name
  5879. 'itemid' => 0, // usually = ID of row in table
  5880. 'filepath' => '/', // any path beginning and ending whith '/'
  5881. 'userid' => $USER->id,
  5882. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5883. 'filename' => $filename); // any filename
  5884. // Create file containing text. '$stringArchiveContent'
  5885. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5886. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5887. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5888. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5889. // 'Activité interactive enregistrée avec succès sous le nom:';
  5890. // 'Atividade interativa gravada com sucesso sob o nome:'
  5891. $output = "
  5892. <script type='text/javascript'>
  5893. //<![CDATA[
  5894. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5895. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5896. //]]>
  5897. </script>";
  5898. print $output;
  5899. die();
  5900. }
  5901. /// Function for write iAssign file in Moodle data (exercise)
  5902. // @param string $stringArchiveContent Content of iassign file
  5903. // @param string $filename Filename of iassign file
  5904. // @param int $itemid Itemid of iassign file
  5905. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5906. global $OUTPUT, $USER;
  5907. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5908. $context = context_course::instance($this->id);
  5909. $dirid = $this->get_dir_ilm('dirid');
  5910. if ($stringArchiveContent != (-1)) {
  5911. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5912. $file = $fs->get_file_by_id($fileid);
  5913. if (!$file) {
  5914. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5915. die;
  5916. }
  5917. $fileinfo = array('contextid' => $context->id, // ID of context
  5918. 'component' => 'mod_iassign', // usually = table name
  5919. 'filearea' => 'activity', // usually = table name
  5920. 'itemid' => 0, // usually = ID of row in table
  5921. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5922. 'userid' => $USER->id,
  5923. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5924. 'license' => 'allrightsreserved', // allrightsreserved
  5925. 'timecreated' => $file->get_timecreated(),
  5926. 'filename' => $file->get_filename()); // any filename
  5927. $file->delete();
  5928. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5929. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5930. }
  5931. $output = "<script type='text/javascript'>
  5932. //<![CDATA[
  5933. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5934. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5935. //]]>
  5936. </script>";
  5937. print $output;
  5938. die();
  5939. }
  5940. /// Function for create an tag for iAssign filter
  5941. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5942. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5943. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5944. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5945. // @param int $fileid Id of file
  5946. // @return string Return an string with an tag of iassign filter
  5947. function tag_ilm ($fileid) {
  5948. global $DB;
  5949. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5950. $width = '600';
  5951. $height = '400';
  5952. $file = $fs->get_file_by_id($fileid);
  5953. $filetype = explode(".", $file->get_filename());
  5954. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5955. foreach ($iassign_ilm as $value) {
  5956. $extensions = explode(",", $value->extension);
  5957. if (in_array($filetype[1], $extensions)) {
  5958. $width = $value->width;
  5959. $height = $value->height;
  5960. }
  5961. }
  5962. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5963. }
  5964. /// Function for delete iAssign file in Moodle data (exercise)
  5965. function delete_file_ilm () {
  5966. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5967. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5968. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5969. $file = $fs->get_file_by_id($fileid);
  5970. if ($file)
  5971. $file->delete();
  5972. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5973. die();
  5974. }
  5975. /// Function for delete selected iAssign file in Moodle data (exercise)
  5976. function delete_selected_ilm () {
  5977. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5978. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5979. $context = context_course::instance($this->id);
  5980. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5981. $dirid = $this->get_dir_ilm('dirid');
  5982. foreach ($files_id as $file_id) {
  5983. $file = $fs->get_file_by_id($file_id);
  5984. if ($file) {
  5985. if (!$file->is_directory())
  5986. $file->delete();
  5987. else {
  5988. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5989. foreach ($files_delete as $value)
  5990. $value->delete();
  5991. $file->delete();
  5992. }
  5993. }
  5994. }
  5995. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5996. die();
  5997. }
  5998. /// Function for duplicate iAssign file from "online" edition
  5999. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  6000. function duplicate_file_ilm () {
  6001. global $USER, $COURSE;
  6002. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6003. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6004. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6005. $filename = optional_param('filename', NULL, PARAM_RAW);
  6006. $file = $fs->get_file_by_id($fileid);
  6007. $context = context_course::instance($this->id);
  6008. $fileinfo = array(
  6009. 'contextid' => $context->id, // ID of context
  6010. 'component' => 'mod_iassign', // usually = table name
  6011. 'filearea' => 'activity', // usually = table name
  6012. 'itemid' => 0, // usually = ID of row in table
  6013. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  6014. 'userid' => $USER->id,
  6015. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6016. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  6017. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  6018. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  6019. die();
  6020. }
  6021. /// Function for rename iAssign file
  6022. function rename_file_ilm () {
  6023. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6024. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6025. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6026. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6027. $file = $fs->get_file_by_id($fileid);
  6028. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  6029. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  6030. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6031. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  6032. die();
  6033. }
  6034. /// Function for get iassign file for iassign form
  6035. function add_ilm () {
  6036. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6037. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6038. $output = "
  6039. <script type='text/javascript'>
  6040. //<![CDATA[
  6041. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  6042. iassign_file_link.innerHTML = '$filename';
  6043. window.opener.document.forms['mform1'].file.value='$fileid';
  6044. window.opener.document.forms['mform1'].filename.value='$filename';
  6045. window.close();
  6046. //]]>
  6047. </script>";
  6048. print $output;
  6049. die();
  6050. }
  6051. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  6052. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  6053. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  6054. function preview_ilm ($courseid, $iassign_ilm) {
  6055. global $OUTPUT, $CFG, $USER;
  6056. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6057. $title = get_string('modulename', 'iassign'); // iAssign
  6058. print $OUTPUT->header();
  6059. print $OUTPUT->box_start();
  6060. $javascript = "
  6061. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  6062. <script type='text/javascript'>
  6063. //<![CDATA[
  6064. function submit_close () {
  6065. window.opener.location.reload();
  6066. window.close();
  6067. }
  6068. //]]>
  6069. </script>\n";
  6070. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6071. // to the complete "applet" tag
  6072. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6073. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6074. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6075. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6076. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6077. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6078. if ($ilm_name != "ivprog") {
  6079. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6080. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6081. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6082. } else {
  6083. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6084. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6085. $timecreated = time();
  6086. $token = md5($timecreated);
  6087. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6088. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6089. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6090. $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)
  6091. }
  6092. $html = "
  6093. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6094. <table border='1'>
  6095. <tr><td>
  6096. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6097. <!-- iLM calls : end -->
  6098. </td></tr>
  6099. </table>
  6100. <table>
  6101. <tr>
  6102. <td align='center'>
  6103. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6104. </td></tr>
  6105. </table>
  6106. </form>\n";
  6107. print $javascript . $html;
  6108. print $OUTPUT->box_end();
  6109. //NAO echo format_string($html); // Moodle 3.X
  6110. die();
  6111. } // function preview_ilm($courseid, $iassign_ilm)
  6112. //r_ function preview_ilm ($iassign_ilm)
  6113. //r_ /// Function for preview iassign file from iassign filter.
  6114. //r_ function preview_ilm() {
  6115. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6116. //r_ $tag_filter = $this->tag_ilm($fileid);
  6117. //r_ $javascript = "<script type='text/javascript'>
  6118. //r_ //<![CDATA[
  6119. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6120. //r_ //]]>
  6121. //r_ </script>";
  6122. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6123. //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>
  6124. //r_ </table></form></body></html>";
  6125. //r_ echo $javascript . format_text($html);
  6126. //r_ die;
  6127. //r_ }
  6128. /// Function for export an package (zip) of iassign files
  6129. function export_files_ilm () {
  6130. global $CFG;
  6131. $context = context_course::instance($this->id);
  6132. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6133. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6134. $zip = new zip_archive();
  6135. $zip->open($zip_filename);
  6136. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6137. foreach ($files_id as $file_id) {
  6138. $file = $fs->get_file_by_id($file_id);
  6139. if (!$file->is_directory())
  6140. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6141. else {
  6142. $zip->add_directory($file->get_filepath());
  6143. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6144. foreach ($files_zip as $value) {
  6145. if (!$value->is_directory())
  6146. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6147. else
  6148. $zip->add_directory($value->get_filepath());
  6149. }
  6150. }
  6151. }
  6152. $zip->close();
  6153. header("Pragma: public");
  6154. header("Expires: 0");
  6155. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6156. header("Cache-Control: private", false);
  6157. header("Content-Type: application/zip");
  6158. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6159. header("Content-Transfer-Encoding: binary");
  6160. header("Content-Length: " . @filesize($zip_filename));
  6161. set_time_limit(0);
  6162. @readfile("$zip_filename") || die("File not found.");
  6163. unlink($zip_filename);
  6164. exit;
  6165. }
  6166. /// Function of execute a command in button editor tinymce
  6167. // @param int $fileid Id of file
  6168. function tinymce_ilm ($fileid) {
  6169. $tag_filter = $this->tag_ilm($fileid);
  6170. $output = "<script type='text/javascript'>
  6171. //<![CDATA[
  6172. var tag_filter = '$tag_filter';
  6173. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6174. // all right, insert it
  6175. } else {
  6176. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6177. }
  6178. // window.close();
  6179. //]]>
  6180. </script>\n";
  6181. print $output;
  6182. die();
  6183. }
  6184. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6185. /// Function to add content to the Editor Window
  6186. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6187. // @param int $fileid Id of file
  6188. function editor_ilm ($fileid, $editor) {
  6189. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6190. $output1 = "<script type='text/javascript'>
  6191. //<![CDATA[
  6192. var tag_filter = '$tag_filter';\n";
  6193. if ($editor == 'atto') {
  6194. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6195. } elseif ($editor == 'tinyMCE') {
  6196. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6197. } else
  6198. $output2 = "";
  6199. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6200. window.close();
  6201. //]]>
  6202. </script>\n";
  6203. //D var_dump($output);
  6204. print $output1 . $output2 . $output3;
  6205. die();
  6206. }
  6207. /// Function to add content to the Atto Editor Window
  6208. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6209. // @param int $fileid Id of file
  6210. function atto_ilm ($fileid) {
  6211. global $CFG, $DB;
  6212. $tag_filter = $this->tag_ilm($fileid);
  6213. $output = "<script type='text/javascript'>
  6214. //<![CDATA[
  6215. var tag_filter = '$tag_filter';
  6216. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6217. // all right, insert iLM tag to this editor
  6218. } else {
  6219. // error trying to insert
  6220. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6221. }
  6222. //window.close();
  6223. //]]>
  6224. </script>\n";
  6225. print $output;
  6226. die();
  6227. }
  6228. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6229. // @param string $key Key for return information
  6230. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6231. function get_dir_ilm ($key) {
  6232. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6233. $context = context_course::instance($this->id);
  6234. $dirid = optional_param('dirid', 0, PARAM_INT);
  6235. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6236. if ($dirid == 0) {
  6237. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6238. $dirid = $dir->get_id();
  6239. }
  6240. else {
  6241. $dir = $fs->get_file_by_id($dirid);
  6242. $dir_base = $dir->get_filepath();
  6243. }
  6244. $dir_parent = $dir->get_parent_directory();
  6245. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6246. return $data[$key];
  6247. }
  6248. /// Function for create an new dir
  6249. function new_dir_ilm () {
  6250. global $USER;
  6251. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6252. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6253. $dir_base = $this->get_dir_ilm('dir_base');
  6254. $context = context_course::instance($this->id);
  6255. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6256. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6257. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6258. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6259. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6260. }
  6261. /// Function for delete an dir
  6262. function delete_dir_ilm () { //
  6263. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6264. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6265. $context = context_course::instance($this->id);
  6266. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6267. $dir_parent = $this->get_dir_ilm('dir_parent');
  6268. if ($dir) {
  6269. if ($dir->is_directory()) {
  6270. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6271. foreach ($files_delete as $value)
  6272. $value->delete();
  6273. $dir->delete();
  6274. }
  6275. }
  6276. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6277. die();
  6278. }
  6279. /// Function for rename an dir
  6280. function rename_dir_ilm () {
  6281. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6282. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6283. $context = context_course::instance($this->id);
  6284. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6285. $dir_parent = $this->get_dir_ilm('dir_parent');
  6286. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6287. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6288. if ($dir->is_directory()) {
  6289. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6290. foreach ($files_rename_path as $value)
  6291. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6292. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6293. }
  6294. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6295. die();
  6296. }
  6297. /// Function for move an dir and your content for other dir
  6298. function selected_move_ilm () {
  6299. global $PAGE, $OUTPUT, $CFG;
  6300. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6301. $context = context_course::instance($this->id);
  6302. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6303. $dirid = $this->get_dir_ilm('dirid');
  6304. $dir_base = $this->get_dir_ilm('dir_base');
  6305. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6306. $code_javascript_ilm = "
  6307. <script type='text/javascript'>
  6308. //<![CDATA[
  6309. function getRadiobutton () {
  6310. var radioButtons = document.getElementsByTagName('input');
  6311. var param = '';
  6312. for (var counter=0; counter < radioButtons.length; counter++) {
  6313. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6314. param = radioButtons[counter].value;
  6315. }
  6316. return param;
  6317. }
  6318. function move_selected_ilm () {
  6319. var msgAnswer;
  6320. if (getRadiobutton() != '') {
  6321. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6322. if (msgAnswer)
  6323. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6324. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6325. }
  6326. else
  6327. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6328. }
  6329. function cancel_selected_ilm () {
  6330. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6331. }
  6332. //]]>
  6333. </script>\n";
  6334. $title = get_string('move_files', 'iassign');
  6335. $PAGE->set_title($title);
  6336. $PAGE->set_pagelayout('base');
  6337. print $OUTPUT->header();
  6338. print $OUTPUT->heading($title);
  6339. $dir_paths = array();
  6340. print $OUTPUT->box_start();
  6341. print "<center>";
  6342. foreach ($files_id as $file_id) {
  6343. $file = $fs->get_file_by_id($file_id);
  6344. if ($file) {
  6345. if (!$file->is_directory())
  6346. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6347. else {
  6348. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6349. array_push($dir_paths, $file->get_filepath());
  6350. }
  6351. }
  6352. }
  6353. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6354. if ($dir_base != '/') {
  6355. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6356. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6357. }
  6358. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6359. foreach ($files_tree as $file) {
  6360. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6361. $is_parent = false;
  6362. foreach ($dir_paths as $dir) {
  6363. $path = explode("/", $dir);
  6364. array_pop($path);
  6365. $path[count($path) - 1] = '';
  6366. $path = implode("/", $path);
  6367. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6368. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6369. }
  6370. if ($is_parent == false) {
  6371. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6372. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6373. }
  6374. }
  6375. }
  6376. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6377. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6378. print "</center>";
  6379. print $OUTPUT->box_end();
  6380. print $OUTPUT->footer();
  6381. print $code_javascript_ilm;
  6382. die;
  6383. }
  6384. /// Function for move files for an dir
  6385. function move_files_ilm () {
  6386. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6387. $context = context_course::instance($this->id);
  6388. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6389. $dirid = $this->get_dir_ilm('dirid');
  6390. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6391. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6392. foreach ($files_id as $file_id) {
  6393. $file = $fs->get_file_by_id($file_id);
  6394. if ($file) {
  6395. if ($file->is_directory()) {
  6396. $pathname = explode("/", $file->get_filepath());
  6397. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6398. foreach ($files_move_path as $value) {
  6399. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6400. $value->rename($path_move, $value->get_filename());
  6401. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6402. }
  6403. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6404. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6405. $file->rename($path_move, $file->get_filename());
  6406. } else {
  6407. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6408. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6409. }
  6410. }
  6411. }
  6412. //die;
  6413. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6414. die();
  6415. } // function move_files_ilm()
  6416. /// Function for recover files in use on all activities of a course
  6417. function recover_files_ilm () {
  6418. global $DB, $USER;
  6419. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6420. $courseid = optional_param('id', NULL, PARAM_INT);
  6421. $dirid = $this->get_dir_ilm('dirid');
  6422. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6423. $contextfile = context_course::instance($this->id);
  6424. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6425. foreach ($iassigns as $iassign) {
  6426. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6427. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6428. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6429. $context = context_module::instance($cm->id);
  6430. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
  6431. if ($files) {
  6432. foreach ($files as $value) {
  6433. $extension = explode(".", $value->get_filename());
  6434. if (!$value->is_directory()) {
  6435. $fileinfo = array('contextid' => $contextfile->id,
  6436. 'component' => 'mod_iassign',
  6437. 'filearea' => 'activity',
  6438. 'itemid' => 0,
  6439. 'filepath' => $this->get_dir_ilm('dir_base'),
  6440. 'userid' => $USER->id,
  6441. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6442. 'license' => 'allrightsreserved',
  6443. 'timecreated' => time(),
  6444. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6445. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6446. }
  6447. }
  6448. } // if ($files)
  6449. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6450. } // foreach ($iassigns as $iassign)
  6451. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6452. die();
  6453. } // function recover_files_ilm()
  6454. /// Auxiliary function the get all files in a given context
  6455. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6456. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6457. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6458. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6459. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6460. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6461. // (NAO s_iassign_statement.file = s_files.id)
  6462. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6463. $dir_base = $this->get_dir_ilm('dir_base');
  6464. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6465. $countf = 0;
  6466. $array_files_id = array(); // all files from this context
  6467. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6468. //$filename = $item_fc->get_filename();
  6469. //$filepath = $item_fc->get_filepath();
  6470. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6471. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6472. // $array_files_aux[] = $item_fc;
  6473. $itemid = $item_fc->get_id();
  6474. if (!in_array($itemid, $array_files_id)) {
  6475. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6476. if ($fileuserid == $userid)
  6477. $filesfrommine[] = $item_fc;
  6478. else
  6479. $filesfromothers[] = $item_fc;
  6480. $array_files_id[] = $itemid;
  6481. $countf++;
  6482. }
  6483. }
  6484. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6485. return $countf;
  6486. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6487. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6488. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6489. function get_all_ilm_files_by_fileid ($fileid) {
  6490. global $DB, $USER;
  6491. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6492. //TODO Criar coluna 'authorid'
  6493. $str_query = "SELECT * FROM {iassign_statement} " .
  6494. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6495. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6496. return $array_iassign_ilm;
  6497. }
  6498. //NN
  6499. //NN
  6500. // Build string with JavaScript code with function to edit/remove/double iLM files
  6501. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6502. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6503. global $CFG;
  6504. $error_files_exists = get_string('error_file_exists', 'iassign');
  6505. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6506. $code_javascript_ilm = "
  6507. <script type='text/javascript'>
  6508. //<![CDATA[
  6509. function preview_ilm (fileid, ilmid) { //JavaScript function
  6510. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6511. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6512. }
  6513. function update_ilm (ilmid, fileid) { //JavaScript function
  6514. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6515. }
  6516. function delete_ilm (ilmid, fileid) { //JavaScript function
  6517. var msgAnswer;
  6518. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6519. if (msgAnswer) {
  6520. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6521. }
  6522. }
  6523. function delete_selected_ilm () { //JavaScript function
  6524. var msgAnswer;
  6525. var param = getCheckbox();
  6526. if (param.join() != '') {
  6527. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6528. if (msgAnswer)
  6529. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6530. }
  6531. else
  6532. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6533. }
  6534. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6535. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6536. }
  6537. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6538. var filenamecopy;
  6539. var i;
  6540. var files = new Array(" . $files_array . ");
  6541. do {
  6542. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6543. } while (filenamecopy == '');
  6544. if (filenamecopy == null)
  6545. return false;\n
  6546. else {
  6547. for (i=0;i<files.length;i++) {
  6548. if (files[i]==filenamecopy) {
  6549. alert('" . $error_files_exists . "');
  6550. return false;\n
  6551. }
  6552. }\n" .
  6553. // @see: function 'duplicate_file_ilm()' above
  6554. "
  6555. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6556. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6557. } // else
  6558. }
  6559. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6560. var filenamecopy;
  6561. var i;
  6562. var files = new Array($files_array);
  6563. do {
  6564. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6565. } while (filenamecopy == '');
  6566. if (filenamecopy == null)
  6567. return false;
  6568. else {
  6569. for (i=0;i<files.length;i++) {
  6570. if (files[i]==filenamecopy) {
  6571. alert('" . $error_files_exists . "');
  6572. return false;
  6573. }
  6574. }
  6575. 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;
  6576. }
  6577. }
  6578. function export_files_ilm () { //JavaScript function
  6579. var param = getCheckbox();
  6580. if (param.join() != '')
  6581. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6582. else
  6583. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6584. }
  6585. function select_all_ilm () { //JavaScript function
  6586. var checkBoxes = document.getElementsByTagName('input');
  6587. var selectAll = document.getElementById('select_all');
  6588. for (var counter=0; counter < checkBoxes.length; counter++) {
  6589. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6590. checkBoxes[counter].checked = selectAll.checked;
  6591. }
  6592. }
  6593. function getCheckbox () { //JavaScript function
  6594. var checkBoxes = document.getElementsByTagName('input');
  6595. var param = new Array();
  6596. for (var counter=0; counter < checkBoxes.length; counter++) {
  6597. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6598. param.push(checkBoxes[counter].value);
  6599. }
  6600. return param;
  6601. }
  6602. function new_dir_ilm () { //JavaScript function
  6603. var dirname = '';
  6604. var i;
  6605. var dirs = new Array(" . $dirs_array . ");
  6606. do {
  6607. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6608. } while (dirname == '');
  6609. if (dirname == null)
  6610. return false;\n
  6611. else {
  6612. for (i=0;i<dirs.length;i++) {
  6613. if (dirs[i]==dirname) {
  6614. alert('" . $error_dir_exists . "');
  6615. return false;\n
  6616. }
  6617. }
  6618. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6619. }
  6620. }
  6621. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6622. var msgAnswer;
  6623. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6624. if (msgAnswer) {
  6625. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6626. }
  6627. }
  6628. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6629. var dirnamecopy;
  6630. var i;
  6631. var dirs = new Array($dirs_array);
  6632. do {
  6633. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6634. } while (dirnamecopy == '');
  6635. if (dirnamecopy == null)
  6636. return false;\n
  6637. else {
  6638. for (i=0;i<dirs.length;i++) {
  6639. if (dirs[i]==dirnamecopy) {
  6640. alert('" . $error_dir_exists . "');
  6641. return false;\n
  6642. }
  6643. }
  6644. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6645. }
  6646. }
  6647. function move_selected_ilm (ilmid) { //JavaScript function
  6648. var param = getCheckbox();
  6649. if (param.join() != '')
  6650. 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();
  6651. else
  6652. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6653. }
  6654. function recover_files_ilm () { //JavaScript function
  6655. var msgAnswer;
  6656. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6657. if (msgAnswer) {
  6658. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6659. }
  6660. }
  6661. window.onload = function() { //JavaScript function
  6662. var xPosition = 0;
  6663. var yPosition = 0;
  6664. element=document.getElementById('new_file');
  6665. while(element) {
  6666. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6667. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6668. element = element.offsetParent;
  6669. }
  6670. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6671. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6672. location.hash = '#new_file';
  6673. };
  6674. //]]>
  6675. </script>\n"; // end of $code_javascript_ilm
  6676. return $code_javascript_ilm;
  6677. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6678. /// List iassign files from course directory
  6679. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6680. function view_files_ilm ($iassign_ilm_class, $extension) {
  6681. global $CFG, $DB, $USER, $OUTPUT;
  6682. $fs = get_file_storage();
  6683. $context = context_course::instance($this->id);
  6684. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6685. $dirid = $this->get_dir_ilm('dirid');
  6686. $dir_base = $this->get_dir_ilm('dir_base');
  6687. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6688. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6689. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6690. $files_array = '';
  6691. foreach ($files_course as $value) {
  6692. if (!$value->is_directory())
  6693. $files_array .= "'" . $value->get_filename() . "',";
  6694. }
  6695. $files_array .= "''";
  6696. $error_files_exists = get_string('error_file_exists', 'iassign');
  6697. $dirs_array = '';
  6698. foreach ($files_course as $value) {
  6699. if ($value->is_directory()) {
  6700. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6701. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6702. }
  6703. }
  6704. $dirs_array .= "''";
  6705. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6706. // TODO Rever o preview pois só deixar ver uma vez.
  6707. $code_javascript_ilm = "
  6708. <script type='text/javascript'>
  6709. //<![CDATA[
  6710. function preview_ilm (fileid, ilmid) {
  6711. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6712. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6713. }
  6714. function update_ilm (ilmid, fileid) {
  6715. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6716. }
  6717. function delete_ilm (ilmid, fileid) {
  6718. var msgAnswer;
  6719. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6720. if (msgAnswer) {
  6721. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6722. }
  6723. }
  6724. function delete_selected_ilm () {
  6725. var msgAnswer;
  6726. var param = getCheckbox();
  6727. if (param.join() != '') {
  6728. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6729. if (msgAnswer)
  6730. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6731. }
  6732. else
  6733. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6734. }
  6735. function add_ilm_iassign (ilmid, filename, fileid) {
  6736. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6737. }
  6738. function duplicate_ilm (ilmid, filename, fileid) {
  6739. var filenamecopy;
  6740. var i;
  6741. var files = new Array($files_array);
  6742. do {
  6743. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6744. } while (filenamecopy == '');
  6745. if (filenamecopy == null)
  6746. return false;\n
  6747. else {
  6748. for (i=0;i<files.length;i++) {
  6749. if (files[i]==filenamecopy) {
  6750. alert('$error_files_exists');
  6751. return false;\n
  6752. }
  6753. }\n" .
  6754. // @see: function 'duplicate_file_ilm()' above
  6755. "
  6756. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6757. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6758. } // else
  6759. }
  6760. function rename_ilm (ilmid, filename, fileid) {
  6761. var filenamecopy;
  6762. var i;
  6763. var files = new Array($files_array);
  6764. do {
  6765. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6766. } while (filenamecopy == '');
  6767. if (filenamecopy == null)
  6768. return false;
  6769. else {
  6770. for (i=0;i<files.length;i++) {
  6771. if (files[i]==filenamecopy) {
  6772. alert('$error_files_exists');
  6773. return false;
  6774. }
  6775. }
  6776. 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;
  6777. }
  6778. }
  6779. function export_files_ilm () {
  6780. var param = getCheckbox();
  6781. if (param.join() != '')
  6782. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6783. else
  6784. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6785. }
  6786. function select_all_ilm () {
  6787. var checkBoxes = document.getElementsByTagName('input');
  6788. var selectAll = document.getElementById('select_all');
  6789. for (var counter=0; counter < checkBoxes.length; counter++) {
  6790. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6791. checkBoxes[counter].checked = selectAll.checked;
  6792. }
  6793. }
  6794. function getCheckbox () {
  6795. var checkBoxes = document.getElementsByTagName('input');
  6796. var param = new Array();
  6797. for (var counter=0; counter < checkBoxes.length; counter++) {
  6798. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6799. param.push(checkBoxes[counter].value);
  6800. }
  6801. return param;
  6802. }
  6803. function new_dir_ilm () {
  6804. var dirname = '';
  6805. var i;
  6806. var dirs = new Array($dirs_array);
  6807. do {
  6808. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6809. } while (dirname == '');
  6810. if (dirname == null)
  6811. return false;\n
  6812. else {
  6813. for (i=0;i<dirs.length;i++) {
  6814. if (dirs[i]==dirname) {
  6815. alert('$error_dir_exists');
  6816. return false;\n
  6817. }
  6818. }
  6819. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6820. }
  6821. }
  6822. function delete_dir_ilm (ilmid, dirid) {
  6823. var msgAnswer;
  6824. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6825. if (msgAnswer) {
  6826. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6827. }
  6828. }
  6829. function rename_dir_ilm (ilmid, dirname, dirid) {
  6830. var dirnamecopy;
  6831. var i;
  6832. var dirs = new Array($dirs_array);
  6833. do {
  6834. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6835. } while (dirnamecopy == '');
  6836. if (dirnamecopy == null)
  6837. return false;\n
  6838. else {
  6839. for (i=0;i<dirs.length;i++) {
  6840. if (dirs[i]==dirnamecopy) {
  6841. alert('$error_dir_exists');
  6842. return false;\n
  6843. }
  6844. }
  6845. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6846. }
  6847. }
  6848. function move_selected_ilm (ilmid) {
  6849. var param = getCheckbox();
  6850. if (param.join() != '')
  6851. 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();
  6852. else
  6853. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6854. }
  6855. function recover_files_ilm () {
  6856. var msgAnswer;
  6857. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6858. if (msgAnswer) {
  6859. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6860. }
  6861. }
  6862. window.onload = function() {
  6863. var xPosition = 0;
  6864. var yPosition = 0;
  6865. element=document.getElementById('new_file');
  6866. while(element) {
  6867. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6868. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6869. element = element.offsetParent;
  6870. }
  6871. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6872. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6873. location.hash = '#new_file';
  6874. };
  6875. //]]>
  6876. </script>\n";
  6877. $output = "";
  6878. $select_all = "";
  6879. $count_files = 0;
  6880. $extensions_allow = array();
  6881. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6882. foreach ($iassign_ilm as $item_iassign_ilm)
  6883. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6884. foreach ($files_course as $value) {
  6885. $filename = $value->get_filename();
  6886. $filepath = $value->get_filepath();
  6887. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6888. $pathname = $pathname[count($pathname) - 1];
  6889. $fileid = $value->get_id();
  6890. $tmp = explode(".", $filename);
  6891. if (count($tmp)>1) // avoid error if the file has no extension
  6892. $filetype = $tmp[1];
  6893. else // probably error...
  6894. $filetype = '';
  6895. $author = $value->get_author();
  6896. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6897. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6898. $extensions = explode(",", $extension);
  6899. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6900. $count_files ++;
  6901. // buscar fileid nas tabelas do iassign
  6902. $list_filein_use = "";
  6903. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6904. if ($iassign_statement_activity_list) {
  6905. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6906. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6907. }
  6908. }
  6909. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6910. if (!$iassign_ilm) {
  6911. $iassign_ilm = new stdClass();
  6912. $iassign_ilm->id = $ilmid;
  6913. }
  6914. // Do not use $var inside "..." - problem with some "unusual" operational system
  6915. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6916. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6917. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6918. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6919. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6920. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6921. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6922. $check_select = "";
  6923. $link_rename = "";
  6924. $link_delete = "";
  6925. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6926. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6927. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6928. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6929. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6930. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6931. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6932. if ($value->get_userid() == $USER->id) {
  6933. if ($iassign_statement_activity_list) {
  6934. $check_select = "";
  6935. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6936. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6937. $link_rename = "";
  6938. } else {
  6939. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6940. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6941. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6942. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6943. }
  6944. }
  6945. if (!in_array($filetype, $extensions_allow)) {
  6946. $link_edit = "";
  6947. $link_add_ilm_iassign = "";
  6948. $link_add_ilm_tinymce = "";
  6949. $link_add_ilm_atto = "";
  6950. $link_filter = "";
  6951. }
  6952. if ($value->is_directory()) {
  6953. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6954. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6955. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6956. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6957. <td><center>$author</center></td>
  6958. <td><center>$timecreated</center></td>
  6959. <td><center>$timemodified</center></td></tr>\n";
  6960. }
  6961. else if ($this->from == 'iassign') {
  6962. $new_id = "";
  6963. $new_class = "";
  6964. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6965. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6966. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6967. }
  6968. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6969. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6970. <td><center>$author</center></td>
  6971. <td><center>$timecreated</center></td>
  6972. <td><center>$timemodified</center></td></tr>\n";
  6973. }
  6974. else if ($this->from == 'block') {
  6975. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6976. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6977. <td><center>$author</center></td>
  6978. <td><center>$timecreated</center></td>
  6979. <td><center>$timemodified</center></td></tr>\n";
  6980. }
  6981. else if ($this->from == 'tinymce') {
  6982. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6983. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6984. <td><center>$author</center></td>
  6985. <td><center>$timecreated</center></td>
  6986. <td><center>$timemodified</center></td></tr>\n";
  6987. }
  6988. else if ($this->from == 'atto') {
  6989. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6990. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6991. <td><center>$author</center></td>
  6992. <td><center>$timecreated</center></td>
  6993. <td><center>$timemodified</center></td></tr>\n";
  6994. }
  6995. }
  6996. }
  6997. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6998. $dir_base = "";
  6999. $header = "";
  7000. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  7001. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  7002. foreach ($basename as $value) {
  7003. $dir_base .= $value . "/";
  7004. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  7005. if ($dir_id) {
  7006. if ($value == "") {
  7007. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7008. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  7009. } else {
  7010. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7011. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  7012. }
  7013. }
  7014. } // foreach ($basename as $value)
  7015. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  7016. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  7017. $html .= "
  7018. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  7019. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  7020. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  7021. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  7022. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  7023. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  7024. </table>\n";
  7025. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  7026. $html .= "<table width='100%'><tr>\n";
  7027. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  7028. if ($count_files != 0) {
  7029. $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";
  7030. $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";
  7031. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  7032. }
  7033. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  7034. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  7035. $html .= "</form>\n";
  7036. print $code_javascript_ilm;
  7037. print $html;
  7038. } // function view_files_ilm($extension)
  7039. } // class ilm_manager
  7040. /// Class to insert of icons
  7041. class iassign_icons {
  7042. static function insert ($icon) {
  7043. global $CFG;
  7044. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  7045. return $string;
  7046. }
  7047. }
  7048. /// Class with util functions for plugin manage
  7049. class iassign_utils {
  7050. /// Function to return the filename extension
  7051. // @param string The $filename as an string
  7052. // @return string Return an string (last group after '.')
  7053. static function filename_extension ($filename) {
  7054. if ($filename == null || $filename == '') {
  7055. return null;
  7056. }
  7057. $itens = explode('.', $filename);
  7058. $num = count($itens);
  7059. if ($num < 2) {
  7060. return null;
  7061. }
  7062. return $itens[$num - 1];
  7063. }
  7064. /// Use the PHP class/package ZipArchive to create a Zip file
  7065. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  7066. // 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
  7067. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  7068. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  7069. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7070. $zip = new zip_archive(); //2
  7071. $res = $zip->open($full_path_zip_filename);
  7072. $total_vet = count($vet_student_filename);
  7073. for ($ii=0; $ii<$total_vet; $ii++) {
  7074. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7075. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7076. }
  7077. $ret = $zip->close();
  7078. iassign_utils::download_file($full_path_zip_filename);
  7079. $filenameZip = $zip->filename;
  7080. return array($ret, $zip);
  7081. }
  7082. static function download_file ($zip_filename) {
  7083. header("Pragma: public");
  7084. header("Expires: 0");
  7085. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7086. header("Cache-Control: private", false);
  7087. header("Content-Type: application/zip");
  7088. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7089. header("Content-Transfer-Encoding: binary");
  7090. header("Content-Length: " . @filesize($zip_filename));
  7091. set_time_limit(0);
  7092. @readfile("$zip_filename") || die("File not found.");
  7093. unlink($zip_filename);
  7094. }
  7095. /// Function for format filename remove special caracters
  7096. // @param string $text String for clean
  7097. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7098. // @return string Return an string in clean format
  7099. static function format_filename ($text) {
  7100. if ($text != '.') {
  7101. //D $text = htmlspecialchars(urldecode($text));
  7102. //D echo "locallib.php: format_filename: $text<br/>";
  7103. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7104. $text = json_decode($text)->{current_language()};
  7105. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7106. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7107. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7108. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7109. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7110. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7111. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7112. // E.g. text = "exerc_midpoint.course.geo"
  7113. // 0123456789012345678901234
  7114. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7115. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7116. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7117. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7118. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7119. //$ext = strrpos($text, ".");
  7120. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7121. //$text = str_replace($array1, $array2, $text);
  7122. }
  7123. return $text;
  7124. }
  7125. /// Function to filter characters to the file name to iLM content
  7126. // @param string $text String for clean
  7127. // @param string $ext String ot the extension of the iLM
  7128. // @return string Return an string in clean format
  7129. static function filter_filename_extension ($filename, $ext) {
  7130. if ($filename != '.') {
  7131. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7132. $arrTo = array("_","","","","","","","","","","","","");
  7133. $filename = str_replace($arrFrom, $arrTo, $filename);
  7134. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7135. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7136. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7137. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7138. $index_lastposition = strlen($filenameF);
  7139. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7140. $text = str_replace(".", "_", $text); // erase all other "."
  7141. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7142. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7143. }
  7144. else
  7145. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7146. return $filenameF;
  7147. }
  7148. /// Function for format pathname remove special caracters
  7149. // @param string $text String for clean
  7150. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7151. // @return string Return an string in clean format
  7152. static function format_pathname ($text, $is_lowercase = true) {
  7153. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7154. $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", "-", "_", "", "", "");
  7155. $text = str_replace($array1, $array2, $text);
  7156. if ($is_lowercase)
  7157. $text = strtolower($text);
  7158. return $text;
  7159. }
  7160. /// Function for format file name from iLM original name
  7161. // @param string $text String to build the file neam
  7162. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7163. // @return string Return an string in clean format
  7164. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7165. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7166. $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", "-", "_", "", "", "");
  7167. $index_firstposition_blank = strpos($ilm_name, " ");
  7168. if ($index_firstposition_blank) { // truncate the name!
  7169. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7170. }
  7171. $index_firstposition_dots = strpos($ilm_name, ":");
  7172. if ($index_firstposition_dots) { // truncate the name!
  7173. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7174. }
  7175. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7176. if ($is_lowercase)
  7177. $namefiltered = strtolower($namefiltered);
  7178. return $namefiltered;
  7179. }
  7180. /// Function for insert version in the filename
  7181. // @param string $filename Name of file
  7182. // @return string Return the filename with version
  7183. static function version_filename ($filename) {
  7184. $array_filename = explode('.', $filename);
  7185. if (count($array_filename) > 1)
  7186. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7187. else
  7188. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7189. return $filename;
  7190. }
  7191. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7192. static function remove_code_message ($string) {
  7193. $array = explode("&lt;ia_uc&gt;", $string);
  7194. return $array[0];
  7195. }
  7196. }
  7197. // class iassign_utils
  7198. /// Class with language functions for plugin manage
  7199. class iassign_language {
  7200. /// Function for return text in language or get default language (en)
  7201. // @param string $lang Code of language
  7202. // @param string $description JSON text content all languages
  7203. // @return string Return an string in the language selected
  7204. static function get_description_lang ($lang, $descriptions) {
  7205. $description_lang = "";
  7206. $description = json_decode($descriptions);
  7207. if ($description == null) {
  7208. $description_lang = $descriptions;
  7209. }
  7210. else {
  7211. if (isset($description->{$lang}))
  7212. $description_lang = $description->{$lang};
  7213. else
  7214. if (isset($description->en)) //MOOC2014
  7215. $description_lang = $description->en;
  7216. else //MOOC2014
  7217. $description_lang = "en"; //MOOC2014
  7218. }
  7219. return $description_lang;
  7220. }
  7221. /// Function for return all language supported by iLM
  7222. // @param string $descriptions JSON text content all languages
  7223. // @return string Return as string with all languages
  7224. static function get_all_lang ($descriptions) {
  7225. $langs = "";
  7226. $description = json_decode($descriptions);
  7227. if ($description) {
  7228. foreach ($description as $key => $value) {
  7229. $langs .= $key . " ; ";
  7230. }
  7231. $langs = substr($langs, 0, strlen($langs) - 3);
  7232. }
  7233. return $langs;
  7234. }
  7235. /// Function for convert json in xml //MOOC2014
  7236. // @param string $json JSON text
  7237. // @return string Return as string with xml tags
  7238. static function json_to_xml ($json) {
  7239. $xml = "";
  7240. $json = json_decode($json);
  7241. foreach ($json as $key => $value) {
  7242. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7243. }
  7244. return $xml;
  7245. }
  7246. }
  7247. // class iassign_language
  7248. /// Class with log functions for plugin manage.
  7249. class iassign_log {
  7250. /// Function for insert log event
  7251. // @param string $action Code action of event
  7252. // @param string $information Text for describe action of event
  7253. // @param int $cmid Id of context module
  7254. // @param int $ilmid Id of iLM
  7255. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7256. global $COURSE, $CFG, $USER, $DB;
  7257. $newentry = new stdClass();
  7258. $newentry->time = time();
  7259. $newentry->userid = $USER->id;
  7260. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7261. $newentry->course = $COURSE->id;
  7262. $newentry->cmid = $cmid;
  7263. $newentry->ilmid = $ilmid;
  7264. $newentry->action = $action;
  7265. $newentry->info = $information;
  7266. $newentry->language = current_language();
  7267. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7268. if (ini_get("browscap") && function_exists('get_browse')) {
  7269. $browser = get_browse(null, true);
  7270. $newentry->javascript = $browser['javascript'];
  7271. $newentry->java = $browser['javaapplets'];
  7272. }
  7273. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7274. print_error('error_add_log', 'iassign');
  7275. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7276. } // class iassign_log