locallib.php 447 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.8 2022/09/15
  7. * + Fix iLM edition (now is possible to update fields 'reevaluate', 'editingbehavior' and 'evaluate' of table 'iassign_ilm')
  8. * - v 4.9.7 2022/02/11
  9. * + Try to fix teacher edit of activity changing 'statement.id' to 'statement.file' in 'add_edit_iassign()';
  10. * + Changed fix to activities order in 'show_iassign()', from "student view" to "teacher view"
  11. *
  12. * - v 4.9.6 2022/01/21
  13. * + Try to fix view activity not sent through report ("view_iassign_current()": else if (!$student_answer) $loadTeacherActivity=true;)
  14. *
  15. * - v 4.9.5 2021/12/28
  16. * + Detail to fix order o activities inside a block ('iassign_statement.position' - old instalation could generate order error)
  17. *
  18. * - v 4.9.4 2020/05/28
  19. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  20. *
  21. * - v 4.9.3 2020/01/16
  22. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  23. *
  24. * - v 4.9.2 2019/03/13
  25. * + Several fixes to allow iLM under HTML stack
  26. *
  27. * - v 4.9.1 2017/11/02
  28. * + 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")
  29. * + 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)'
  30. *
  31. * - v 4.9 2017/03/13
  32. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  33. *
  34. * - v 4.8 2016/05/12
  35. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  36. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  37. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  38. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  39. * replaced by
  40. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  41. * - v 4.7 2016/02/17
  42. * + 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(...)')
  43. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  44. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  45. * + 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)
  46. * + 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'
  47. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  48. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  49. *
  50. * --------------- (code bellow was used at our MOOC 2014)
  51. * - v 4.6 2014/02/25
  52. * + Fix bugs in filter function for open applets.
  53. * - v 4.5 2014/02/24
  54. * + Fix bugs in params.
  55. * + Insert new param type.
  56. * - v 4.4 2014/01/24
  57. * + Allow select type of params.
  58. * + Insert the use of applet params specific for activities.
  59. * - v 4.3 2014/01/23
  60. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  61. * - v 4.2 2016/02/13
  62. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  63. * --------------- (above code used at our MOOC 2014)
  64. *
  65. * - v 4.1 2013/12/13
  66. * + Insert log in iAssign actions.
  67. * + 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).
  68. * + Insert class for Log actions in system.
  69. * - v 4.0 2013/10/31
  70. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  71. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  72. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  73. * - v 3.9 2013/10/25
  74. * + Insert support of upgrade iLM.
  75. * + Insert support for more than one extension in iLM.
  76. * + Fix bugs in verion control.
  77. * - v 3.8 2013/09/19
  78. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  79. * - v 3.7 2013/09/12
  80. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  81. * + 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).
  82. * - v 3.6 2013/09/05
  83. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  84. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  85. * + Change tag APPLET in function ilm_settings::view_ilm.
  86. * - v 3.5 2013/08/26
  87. * + Fix bug in download package iassign without answers (iassign::report).
  88. * - v 3.4 2013/08/23
  89. * + Fix bug in export package iassign.
  90. * - v 3.3 2013/08/22
  91. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  92. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  93. * - v 3.2 2013/08/21
  94. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  95. * + Change functions for import files for ilm_manager.php.
  96. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  97. * - v 3.1 2013/08/15
  98. * + Change return file selected (ilm_manager::add_ilm).
  99. * + 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).
  100. * - v 3.0 2013/08/02
  101. * + 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).
  102. * - v 2.9 2013/08/01
  103. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  104. * - v 2.8 2013/07/25
  105. * + Insert the activity name in header of view (activity::view_dates).
  106. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  107. * - v 2.7 2013/07/24
  108. * + Create link previous and next for student view in one activity (activity::view_dates).
  109. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  110. * - v 2.6 2013/07/23
  111. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  112. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  113. * - v 2.5 2013/07/12
  114. * + 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).
  115. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  116. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  117. *
  118. * @author Patricia Alves Rodrigues
  119. * @author Leônidas O. Brandão
  120. * @contributor Igor Moreira Félix (2018-)
  121. * @contributor Márcio de Lima Passos (2014)
  122. * @version v 4.9.2 2019/03/13
  123. * @version v 4.8 2016/05/12
  124. * @package mod_iassign_lib
  125. * @since 2010/09/27
  126. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  127. *
  128. * <b>License</b>
  129. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  130. */
  131. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  132. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  133. //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"'
  134. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  135. /// Standard base class for all iAssign
  136. // Basic class to iAssign block of activities
  137. class iassign {
  138. var $cm;
  139. var $course;
  140. var $iassign;
  141. var $striassign;
  142. var $striassigns;
  143. var $context;
  144. var $activity;
  145. var $iassign_up;
  146. var $iassign_down;
  147. var $action;
  148. var $iassign_submission_current;
  149. var $userid_iassign;
  150. var $bottonPost;
  151. var $write_solution;
  152. var $view_iassign;
  153. // 3.1 update PHP 7.0 compatibility for all moodle versions
  154. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  155. /// Constructor for the base iassign class
  156. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  157. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  158. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  159. function __construct ($iassign, $cm, $course) {
  160. global $COURSE, $CFG, $USER, $DB;
  161. $botton = optional_param('botton', NULL, PARAM_TEXT);
  162. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  163. if (!is_null($botton))
  164. $USER->iassignEdit = $botton;
  165. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  166. // 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'
  167. $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"
  168. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  169. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  170. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  171. $this->action = optional_param('action', NULL, PARAM_TEXT);
  172. $this->cm = $cm;
  173. $this->context = context_module::instance($this->cm->id);
  174. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  175. $this->userid_iassign = $USER->id;
  176. if ($course) {
  177. $this->course = $course;
  178. }
  179. else if ($this->cm->course == $COURSE->id) {
  180. $this->course = $COURSE;
  181. }
  182. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  183. print_error('invalidid', 'iassign');
  184. }
  185. $this->coursecontext = context_course::instance($this->course->id);
  186. if ($iassign) {
  187. $this->iassign = $iassign;
  188. }
  189. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  190. print_error('invalidid', 'iassign');
  191. }
  192. $USER->context = context_module::instance($this->cm->id);
  193. $USER->cm = $this->cm->id;
  194. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  195. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  196. $this->context = context_module::instance($this->cm->id);
  197. $this->striassign = get_string('modulename', 'iassign');
  198. $this->striassigns = get_string('modulenameplural', 'iassign');
  199. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  200. $this->bottonPost = 0;
  201. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  202. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT)); // this is the activity inside iAssign block (content file)
  203. $this->view();
  204. } // function __construct($iassign, $cm, $course)
  205. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  206. // This method provides the page to view each iLM with any interactive activity
  207. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  208. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  209. global $USER, $DB, $OUTPUT;
  210. // $iassign_statementid = $this->iassign->iassign_statementid;
  211. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  212. $iassign_statementid = $this->activity->get_activity()->id;
  213. else
  214. $iassign_statementid = "";
  215. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  216. // If this user has no capability to View 'iassign': stop here
  217. require_capability('mod/iassign:view', $this->context);
  218. // Trigger module view event
  219. $event = \mod_iassign\event\course_module_viewed::create(array(
  220. 'objectid' => $this->iassign->id,
  221. 'context' => $this->context
  222. ));
  223. $event->add_record_snapshot('course', $this->course);
  224. $event->trigger();
  225. if ($this->action) { // when student do/redo activity or teacher see student solution
  226. $this->action(); // calls '$this->view_iLM();'
  227. }
  228. else {
  229. print $OUTPUT->header();
  230. $this->view_iassigns(); // show the iLM with the content
  231. print $OUTPUT->footer();
  232. }
  233. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  234. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  235. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  236. //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" }
  237. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  238. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  239. //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" }
  240. //D else echo "Apagou!<br/>";
  241. die();
  242. } // function view()
  243. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  244. function action () {
  245. global $USER;
  246. // action:
  247. // up - move up activity (mover atividade para cima)
  248. // down - move down activity (mover atividade para baixo)
  249. // visible - view/hide activity (exibir/ocultar atividade)
  250. // delete - delete activity (excluir atividade)
  251. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  252. // deleteno - does not erase activity (não apaga atividade)
  253. // add - add activity (adicionar atividade)
  254. // edit - edit activity (modificar atividade)
  255. $action_iassign = array(
  256. 'newcomment' => '$this->add_comment();',
  257. 'view' => '$this->view_iassign_current();',
  258. 'get_answer' => '$this->get_answer();',
  259. 'repeat' => '$this->view_iassign_current();',
  260. 'overwrite' => '$this->get_answer();',
  261. 'stats_student' => '$this->stats_students();',
  262. 'download_answer' => '$this->export_file_answer();',
  263. 'download_all_answer' => '$this->export_package_answer();',
  264. 'notifications' => '$this->view_notifications();');
  265. $action_iassign_limit = array(
  266. 'view' => '$this->view_iassign_current();',
  267. //'newcomment' => '$this->get_answer();',
  268. 'viewsubmission' => '$this->view_iassign_current();',
  269. 'edit_status' => '$this->edit_status();',
  270. 'edit_grade' => '$this->edit_grade();',
  271. 'export_csv' => '$this->export_csv();',
  272. 'report' => '$this->report();',
  273. 'print' => '$this->report();',
  274. 'stats' => '$this->stats();',
  275. 'printstats' => '$this->stats();');
  276. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  277. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  278. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  279. 'visible' => '$this->activity->visible_iassign($this->return);',
  280. 'delete' => '$this->activity->delete($this->return);',
  281. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  282. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  283. 'add' => '$this->add_edit_iassign();',
  284. 'edit' => '$this->add_edit_iassign();',
  285. 'get_answer' => '$this->get_answer();',
  286. 'duplicate_activity' => '$this->duplicate_activity();',
  287. 'move_activity' => '$this->move_activity();',
  288. 'auto_evaluate' => '$this->auto_evaluate();',
  289. 'all_submissions' => '$this->all_submissions();',
  290. 'delete_submissions' => '$this->delete_submissions();',
  291. 'download_submissions' => '$this->download_submissions();',
  292. 'open_individual_submission' => '$this->open_individual_submission();',
  293. 'get_individual_submission' => '$this->get_individual_submission();',
  294. 'get_student_submission' => '$this->get_student_submission();',
  295. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  296. 'post_auto_eval_result' => '$this->post_auto_eval_result();',
  297. 'import_activity' => '$this->import_activity();',
  298. 'import_activity_confirm' => '$this->import_activity_confirm();'
  299. );
  300. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  301. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  302. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  303. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  304. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  305. }
  306. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  307. eval($action_iassign_limit[$this->action]);
  308. }
  309. else { // Student reaches this point
  310. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  311. // Arrive here with: "get_answer"; "view"
  312. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  313. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  314. }
  315. } // function action()
  316. /// This method prints the student submission to a specific exercise
  317. function get_student_submission () {
  318. global $DB;
  319. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  320. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  321. if (!$student || !$exercise) exit;
  322. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  323. if ($iassign_submission)
  324. print($iassign_submission->answer);
  325. die();
  326. }
  327. /// This method prints the teacher exercise
  328. // @calledby AJAX trhough "function action()" that calls "function auto_evaluate()"
  329. function get_teacher_exercise () {
  330. global $DB, $COURSE;
  331. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  332. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  333. $fs = get_file_storage(); // Get reference to all files in Moodle data
  334. //2021/12: $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  335. //TODO 2022: trocar "$iassign_statement->id" por "$iassign_statement->file"???
  336. // ./lib/filestorage/file_storage.php: public function get_area_files($contextid, $component, $filearea, $itemid = false,...)
  337. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id); // use itemid=$iassign_statement->id
  338. if (!$files) { // try with 'iassign_statement->filesid'
  339. //D echo "locallib.php: get_teacher_exercise(): com iassign_statement->id=" . $iassign_statement->id . " resulta vazio! Tente com iassign_statement->filesid=" . $iassign_statement->filesid . "<br/>\n";
  340. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  341. }
  342. foreach ($files as $file) {
  343. if ($file->get_filename() != ".") {
  344. print($file->get_content());
  345. }
  346. }
  347. die();
  348. }
  349. /// This method receives the data from auto_eval event
  350. /// @see auto_evaluate()
  351. function post_auto_eval_result () {
  352. global $COURSE, $CFG, $USER, $DB;
  353. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  354. exit;
  355. //$exercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  356. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  357. $student = optional_param('student', -1, PARAM_INT);
  358. $grade = optional_param('grade', 0, PARAM_FLOAT);
  359. // 1: Recuperar a nota atual:
  360. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  361. // 2: Atualizar a tabela:
  362. $update_entry = new stdClass();
  363. $update_entry->id = $actual->id;
  364. $update_entry->previous_grade = $actual->grade;
  365. $update_entry->grade = $grade;
  366. // Update the iassign_submission
  367. $DB->update_record("iassign_submission", $update_entry);
  368. }
  369. /// Function to help download all_submissions files
  370. function download_submissions_help ($list) {
  371. global $DB, $CFG, $OUTPUT;
  372. // Get list of iLMs
  373. $ilm_list = $DB->get_records("iassign_ilm");
  374. // Get list of enrolled students:
  375. $params_temp = array('shortname' => 'student');
  376. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  377. $context = context_course::instance($this->course->id);
  378. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  379. $students_list = $DB->get_records_sql(
  380. "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);
  381. $json_obj = new stdclass();
  382. $json_obj->submissions = [];
  383. $csvfields = [];
  384. $csvfields[] = 'submissionid';
  385. $csvfields[] = 'file';
  386. $csvfields[] = 'filesize';
  387. $csvfields[] = 'timestamp';
  388. $csvfields[] = 'humandate';
  389. $csvfields[] = 'grade';
  390. $csvfields[] = 'userid';
  391. $csvfields[] = 'exerciseid';
  392. $json_obj->submissions[] = $csvfields;
  393. $exercise_dir = [];
  394. $exercises_list = [];
  395. foreach ($list as $item) {
  396. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  397. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  398. $exercises_list[] = $temp;
  399. $exercise_dir[] = $temp->id;
  400. }
  401. }
  402. $student_dir = [];
  403. $students_list = [];
  404. foreach ($list as $item) {
  405. if (!in_array($item->userid, $student_dir)) {
  406. $temp = $DB->get_record("user", array("id" => $item->userid));
  407. $students_list[] = $temp;
  408. $student_dir[] = $temp->id;
  409. }
  410. }
  411. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  412. //TODO: tem que criar moodledata/temp/iassign_files
  413. // Create $CFG->dataroot/temp/iassign_files
  414. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  415. if (!file_exists($tempfilespath)) {
  416. mkdir($tempfilespath, 0777, true);
  417. }
  418. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  419. if (!file_exists($iassignfilespath)) {
  420. mkdir($iassignfilespath, 0777, true);
  421. }
  422. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  423. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  424. if (!file_exists($diretorio)) {
  425. 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.';
  426. exit;
  427. }
  428. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  429. $zip = new zip_archive(); // create ZIP
  430. if (!$zip->open($zip_filename)) {
  431. 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;
  432. exit;
  433. }
  434. ;
  435. foreach ($exercises_list as $exercise) {
  436. $dir_ex = iassign_utils::format_filename($exercise->name);
  437. $zip->add_directory($dir_ex);
  438. $extension_ilm = '';
  439. foreach ($ilm_list as $ilm) {
  440. if ($exercise->iassign_ilmid == $ilm->id) {
  441. $extension_ilm = $ilm->extension;
  442. break;
  443. }
  444. }
  445. foreach ($students_list as $student) {
  446. $individual_dir =
  447. $dir_ex . DIRECTORY_SEPARATOR .
  448. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  449. $zip->add_directory($individual_dir);
  450. $i = 1;
  451. foreach($list as $item) {
  452. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  453. $date = new DateTime();
  454. $date->setTimestamp($item->timecreated);
  455. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  456. $zip->add_file_from_string($new_file, $item->answer);
  457. $temp_json = [];
  458. $temp_json[] = intval($item->id);
  459. $temp_json[] = $new_file;
  460. $temp_json[] = strlen($new_file);
  461. $temp_json[] = intval($item->timecreated);
  462. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  463. $temp_json[] = doubleval($item->grade);
  464. $temp_json[] = intval($item->userid);
  465. $temp_json[] = intval($exercise->id);
  466. $json_obj->submissions[] = $temp_json;
  467. }
  468. }
  469. }
  470. }
  471. $csv_str = "";
  472. foreach($json_obj->submissions as $sub) {
  473. $csv_str .= $this->csvstr($sub) . "\n";
  474. }
  475. $zip->add_file_from_string('index.csv', $csv_str);
  476. $zip->close();
  477. iassign_utils::download_file($zip_filename);
  478. exit;
  479. }
  480. function csvstr(array $fields) : string {
  481. $f = fopen('php://memory', 'r+');
  482. if (fputcsv($f, $fields) === false) {
  483. return false;
  484. }
  485. rewind($f);
  486. $csv_line = stream_get_contents($f);
  487. return rtrim($csv_line);
  488. }
  489. /// Download submissions from table iassign_allsubmissions
  490. function download_submissions () {
  491. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  492. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  493. exit;
  494. $type = optional_param('type', NULL, PARAM_TEXT);
  495. $item = optional_param('item', NULL, PARAM_TEXT);
  496. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  497. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  498. $sub_list = [];
  499. if ($type == 'individual') {
  500. $sub_list[] = $DB->get_record(
  501. 'iassign_allsubmissions', array('id' => $item));
  502. } elseif ($type == 'student') {
  503. $sub_list = $DB->get_records(
  504. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  505. } elseif ($type == 'exercise') {
  506. $sub_list = $DB->get_records(
  507. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  508. } elseif ($type == 'block') {
  509. $exercises_in_block = $DB->get_records(
  510. 'iassign_statement', array('iassignid' => $iassign_id));
  511. foreach ($exercises_in_block as $exercise) {
  512. $temp = $DB->get_records(
  513. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  514. $sub_list = array_merge($sub_list, $temp);
  515. }
  516. }
  517. $this->download_submissions_help($sub_list);
  518. }
  519. /// Delete submissions in table iassign_allsubmissions
  520. function delete_submissions () {
  521. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  522. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  523. exit;
  524. $type = optional_param('type', NULL, PARAM_TEXT);
  525. $item = optional_param('item', NULL, PARAM_TEXT);
  526. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  527. if ($type == 'individual') {
  528. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  529. } elseif ($type == 'student') {
  530. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  531. } elseif ($type == 'exercise') {
  532. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  533. }
  534. }
  535. function get_individual_submission () {
  536. global $DB, $USER;
  537. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  538. exit;
  539. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  540. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  541. print $submission->answer;
  542. }
  543. /// Open individual submission
  544. function open_individual_submission () {
  545. global $DB, $USER, $CFG;
  546. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  547. exit;
  548. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  549. $id = $this->cm->id;
  550. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  551. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  552. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  553. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  554. $all_submissions = $DB->get_records('iassign_allsubmissions', array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  555. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  556. $previous = null;
  557. $next = null;
  558. $i = 0;
  559. $found = false;
  560. foreach($all_submissions as $individual) {
  561. if (!$found && $individual->id != $submissionid) {
  562. $previous = $individual;
  563. }
  564. if ($found) {
  565. $next = $individual;
  566. break;
  567. }
  568. if ($individual->id === $submissionid) {
  569. $found = true;
  570. }
  571. $i++;
  572. }
  573. print '<center>' . "\n";
  574. 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>' . "\n";
  575. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>' . "\n";
  576. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>' . "\n";
  577. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>' . "\n";
  578. print '</table>' . "\n";
  579. if ($previous) {
  580. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  581. print '<a href="' . $url_prev . '" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
  582. } else {
  583. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
  584. }
  585. print ' (' . $i . '/' . count($all_submissions) . ')';
  586. if ($next) {
  587. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  588. print '<a href="' . $url_next . '" style="color: blue; text-decoration: none;margin: 1rem;">' . get_string('all_submissions_manager_next', 'iassign') . ' <span>&#9654;</span></a>' . "\n";
  589. } else {
  590. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">' . get_string('all_submissions_manager_next', 'iassign') . ' <span>&#9654;</span></a>' . "\n";
  591. }
  592. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  593. //array("type" => "editor_new", "notSEND" => "true")
  594. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  595. print '</center>' . "\n";
  596. } // function open_individual_submission()
  597. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - inicio 1
  598. function import_activity_confirm () {
  599. global $USER, $DB;
  600. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  601. exit;
  602. if (!isset($_REQUEST['statements'])) exit;
  603. $iassign_destiny = $this->iassign->id;
  604. $activities_list = $_REQUEST['statements'];
  605. foreach ($activities_list as $activity) {
  606. $activity_source = $DB->get_record('iassign_statement', array('id' => $activity));
  607. $activity_source->id = 0;
  608. $iassign_id_from = $activity_source->iassignid;
  609. $filesid_from = $activity_source->filesid;
  610. $activity_source->iassignid = $iassign_destiny;
  611. $author = $DB->get_record("user", array('id' => $USER->id));
  612. $activity_source->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  613. $activity_source->author_modified = $activity_source->author_modified_name;
  614. if ($id_ = $DB->insert_record("iassign_statement", $activity_source)) {
  615. $fs = get_file_storage();
  616. // Duplicate activity file
  617. $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
  618. print("Files to be copied: "); //TODO: universalizar 'Arquivos a serem copiados: '
  619. print_r($files_ids);
  620. foreach ($files_ids as $fileid) {
  621. $source_file = $fs->get_file_by_id($fileid->id);
  622. $newfile = $fs->create_file_from_storedfile(array('contextid' => $this->context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $source_file);
  623. $updateentry = new stdClass();
  624. $updateentry->id = $id_;
  625. $updateentry->filesid = $id_;
  626. // Update the duplicated iLM iAssign with new file id
  627. $DB->update_record("iassign_statement", $updateentry);
  628. }
  629. }
  630. } // foreach ($activities_list as $activity)
  631. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->context->id));
  632. $str_index = count($activities_list) > 1 ? 'import_activities_success' : 'import_activity_success';
  633. redirect($this->return, get_string($str_index, 'iassign'), null, \core\output\notification::NOTIFY_SUCCESS);
  634. exit;
  635. }
  636. function import_activity () {
  637. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  638. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  639. exit;
  640. print '<script>
  641. function verify_selection () {
  642. document.getElementById("msg-error").classList.add("d-none");
  643. var checkboxes = document.getElementsByName("statements[]");
  644. for (var i = 0; i < checkboxes.length; i++)
  645. if (checkboxes[i].checked) return true;
  646. document.getElementById("msg-error").classList.remove("d-none");
  647. return false;
  648. }
  649. </script>'; // "
  650. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id, 'action' => 'import_activity_confirm'));
  651. print $OUTPUT->header();
  652. $this->print_main_menu();
  653. print '<h2 class="m-b-2 mt-4">' . get_string('import_activity', 'iassign') . '</h2>' . "\n";
  654. print '<form action="' . $destiny_url . '" method="post" onsubmit="return verify_selection()">' . "\n";
  655. $courses_as_teacher = $this->get_courses_enroled_as_teacher($USER->id);
  656. foreach ($courses_as_teacher as $course) {
  657. print '<a href="#item-' . $course->id . '" class="list-group-item list-group-item-action h5" 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> ' . $course->fullname . ' </a>' . "\n";
  658. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '">' . "\n";
  659. $iassigns = $this->get_iassign_items_by_course($course->id);
  660. if ($iassigns) {
  661. foreach ($iassigns as $iassign) {
  662. print '<a href="#item-' . $course->id . '-' . $iassign->id . '" 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");\'><i class="fa fa-caret-right"></i> ' . $iassign->name . '</a>' . "\n";
  663. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '-' . $iassign->id . '">' . "\n";
  664. $statements = $this->get_iassign_statement_by_iassign($iassign->id);
  665. print '<table class="table table-hover">' . "\n";
  666. if ($statements) {
  667. foreach ($statements as $statement) {
  668. print '<tr><td> <div class="form-check"> <input class="form-check-input" name="statements[]" type="checkbox" value="' . $statement->id . '" id="statement-' . $statement->id . '">' . "\n";
  669. print '<label class="form-check-label w-100" for="statement-' . $statement->id . '">' . $statement->name;
  670. print '</label></div></td></tr>' . "\n";
  671. }
  672. }
  673. else {
  674. print '<tr><td>' . get_string('no_activity', 'iassign') . '</td></tr>' . "\n";
  675. }
  676. print '</table></div>' . "\n";
  677. }
  678. }
  679. else {
  680. print '<div class="p-2">' . get_string('import_statement_empty', 'iassign') . '</div>' . "\n";
  681. }
  682. print '</div>' . "\n";
  683. }
  684. print '<div class="text-center"><button type="submit" class="btn btn-primary mt-2">Confirmar</button></div>' . "\n";
  685. print '<div class="text-center text-danger d-none" id="msg-error">' . get_string('import_statement_no_exercise', 'iassign') . '</div>' . "\n";
  686. print "</form>\n";
  687. print $OUTPUT->footer();
  688. } // function post_auto_eval_result()
  689. function get_iassign_items_by_course ($courseid) {
  690. global $DB;
  691. return $DB->get_records("iassign", array("course" => $courseid));
  692. }
  693. function get_iassign_statement_by_iassign ($iassignid) {
  694. global $DB;
  695. return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  696. }
  697. function get_courses_enroled_as_teacher ($userid) {
  698. $all_enroled = enrol_get_users_courses($userid);
  699. $return = array();
  700. foreach ($all_enroled as $enroled) {
  701. $context_course = context_course::instance($enroled->id);
  702. if (has_capability('mod/iassign:runautoevaluate', $context_course, $userid, false) ) {
  703. array_push($return, $enroled);
  704. }
  705. }
  706. return $return;
  707. }
  708. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - final 1
  709. /// Manage all submissions in exercises to table iassign_allsubmissions
  710. function all_submissions () {
  711. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  712. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  713. exit;
  714. print $OUTPUT->header();
  715. $this->print_main_menu();
  716. $id = $this->cm->id;
  717. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  718. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  719. print '
  720. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  721. <div class="modal-dialog modal-dialog-centered" role="document">
  722. <div class="modal-content">
  723. <div class="modal-header">
  724. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('delete', 'iassign') . '</h5>
  725. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  726. <span aria-hidden="true">&times;</span>
  727. </button>
  728. </div>
  729. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  730. <div class="modal-footer">
  731. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  732. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  733. </div>
  734. </div>
  735. </div>
  736. </div>'; // "
  737. print '
  738. <script>
  739. var sub_type;
  740. var sub_item;
  741. var sub_el;
  742. var sub_exercise;
  743. function delete_submission (type, item, el, exercise = 0) {
  744. sub_type = type;
  745. sub_item = item;
  746. sub_exercise = exercise;
  747. sub_el = el.closest("tr");
  748. if (!sub_el) sub_el = el.closest("a");
  749. $("#modalConfirm").modal();
  750. }
  751. function confirm_delete () {
  752. var url = "'.$enderecoPOST.'&action=delete_submissions";
  753. var xhttp = new XMLHttpRequest();
  754. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  755. xhttp.send();
  756. $("#modalConfirm").modal("hide");
  757. if ($(sub_el).attr("href"))
  758. $($(sub_el).attr("href")).remove();
  759. if (sub_el) sub_el.remove();
  760. }
  761. function download_submission(type, item, exercise = 0, iassign = 0) {
  762. var url = "'.$enderecoPOST.'&action=download_submissions";
  763. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  764. document.location = url;
  765. }
  766. function open_submission(item) {
  767. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  768. var poupup = window.open(url, "popup", "width=900,height=900");
  769. }
  770. </script>' . chr(13); // '
  771. // Get list of exercises in the instance:
  772. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  773. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  774. print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
  775. 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>';
  776. // Get list of enrolled students:
  777. $params_temp = array('shortname' => 'student');
  778. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  779. $context = context_course::instance($this->course->id);
  780. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  781. $students_list = $DB->get_records_sql(
  782. "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);
  783. print '<div>';
  784. foreach ($exercises_list as $exercise) {
  785. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  786. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  787. print '
  788. <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> '
  789. . $exercise->name
  790. . ' - ' . $iassign_ilm->name
  791. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  792. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  793. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  794. . $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> '
  795. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  796. . '</a>';
  797. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  798. foreach ($students_list as $student) {
  799. $total = 0;
  800. $student_submissions = [];
  801. foreach ($submissions_list as $submission) {
  802. if ($submission->userid == $student->userid) {
  803. $student_submissions[] = $submission;
  804. $total++;
  805. }
  806. }
  807. 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");\'>
  808. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  809. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  810. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  811. . '<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> '
  812. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  813. . ' </a>';
  814. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  815. print '<table class="table table-striped table-hover"><thead>
  816. <tr>
  817. <th scope="col">#</th>
  818. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  819. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  820. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  821. </tr>
  822. </thead><tbody>'; // "
  823. $i = 1;
  824. foreach ($student_submissions as $individual) {
  825. $date = new DateTime();
  826. $date->setTimestamp($individual->timecreated);
  827. print '<tr>';
  828. print '<td>' . ($i++) . '</td>';
  829. print '<td>' . date_format($date, 'd/m/Y H:i:s') . '</td>';
  830. print '<td>' . $individual->grade . '</td>';
  831. print '<td>
  832. <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>
  833. <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>
  834. <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>';
  835. print " </tr>\n";
  836. }
  837. print '</tbody></table>';
  838. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  839. print '</div>';
  840. }
  841. print '</div>';
  842. }
  843. print '</div>';
  844. print $OUTPUT->footer();
  845. } // function all_submissions()
  846. /// This method runs activities auto evaluation in teacher area
  847. function auto_evaluate () {
  848. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  849. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  850. exit;
  851. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  852. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  853. // Get list of exercises in the instance:
  854. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  855. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  856. // Get list of enrolled students:
  857. $params_temp = array('shortname' => 'student');
  858. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  859. $context = context_course::instance($this->course->id);
  860. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  861. $students_list = $DB->get_records_sql(
  862. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  863. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  864. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  865. print $OUTPUT->header();
  866. $this->print_main_menu();
  867. print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  868. print '<ul style="list-style-type: none; margin: 1em;">';
  869. foreach ($exercises_list as $exercise) {
  870. $matches = [];
  871. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  872. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  873. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  874. if ($matches[0][0]) {
  875. 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>';
  876. } else {
  877. 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>';
  878. }
  879. } else {
  880. if ($matches[0][0]) {
  881. 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>';
  882. } else {
  883. 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>';
  884. }
  885. }
  886. }
  887. print '</ul>
  888. <center>
  889. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  890. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  891. <div id="evaluate_message" style="color: red"></div>
  892. <div id="evaluate_alerts"></div>
  893. <div>
  894. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  895. <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>
  896. </div>
  897. </center>'; // close "
  898. print ' </div>' . "\n";
  899. print ' <script>' . "\n";
  900. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  901. print ' var submissions = [';
  902. // Get list of student id have submit for each exercise:
  903. foreach ($exercises_list as $exercise) {
  904. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  905. print '
  906. {
  907. "exerciseid": "' . $exercise->id . '",
  908. "grade": ' . $exercise->grade . ',
  909. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  910. "submited": ['; // "
  911. $params_temp = array('iassign_statementid' => $exercise->id);
  912. $submited = $DB->get_records_sql( // Get userid and his grade
  913. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  914. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  915. foreach ($submited as $ss) {
  916. print($ss->userid . ',');
  917. }
  918. print '],';
  919. print '"allgrades": [';
  920. foreach ($submited as $ss) {
  921. print( $ss->grade . ',');
  922. }
  923. print ']
  924. },'; // close "
  925. } // foreach ($exercises_list as $exercise)
  926. // Start of JavaScript code to auto-evaluation
  927. print " ];\n";
  928. print '
  929. var total_submissions = 0;
  930. var selected_exercises;
  931. var count_steps;
  932. var value_by_step;
  933. var stoped = false;
  934. var time_interval = 5000;
  935. var var_interval;
  936. function add_hover_th (id_th, id_li) { //AJAX
  937. $("#" + id_th).hover(function() {
  938. $("#" + id_li).css("background-color", "#d9d8d8");
  939. $(this).css("background-color", "#d9d8d8");
  940. }, function() {
  941. $("#" + id_li).css("background-color", "");
  942. $(this).css("background-color", "");
  943. });
  944. }
  945. function start_evaluation () {
  946. stoped = false;
  947. //AJAX
  948. $("#progress_bar").css("display", "none");
  949. $("#evaluate_message").text("");
  950. $("#evaluate_alerts").text("");
  951. $(".added-col").remove();
  952. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  953. selected_exercises = [];
  954. var c = 0;
  955. for (var i = 0; i < exercises.length; i++) {
  956. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  957. selected_exercises[c++] = exercises[i];
  958. }
  959. }
  960. if (selected_exercises.length == 0) {
  961. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  962. return;
  963. } else {
  964. $("input:checkbox").attr("disabled", true); //AJAX
  965. for (var i = 0; i < selected_exercises.length; i++) {
  966. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  967. //AJAX
  968. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  969. $("#table-results tbody tr").each(function(e) {
  970. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  971. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  972. });
  973. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  974. }
  975. //AJAX
  976. $("#button_start").prop("disabled", true);
  977. $("#button_stop").prop("disabled", false);
  978. $("#progress_bar").css("display", "block");
  979. }
  980. total_submissions = selected_exercises.length * students.length;
  981. count_steps = 0;
  982. value_by_step = 100/total_submissions;
  983. actual_exercise = 0;
  984. actual_student = 0;
  985. actual_submission = 0;
  986. get_original_propositions();
  987. var_interval = setInterval(verifyBreak, time_interval);
  988. } // function start_evaluation()
  989. var actual_exercise;
  990. var actual_student;
  991. var actual_submission;
  992. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  993. function run_individual_evaluation () {
  994. if (stoped) return;
  995. // Verify if student really sent his answer
  996. var found = false;
  997. for (var j = 0; j < submissions.length; j++) {
  998. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  999. for (var k = 0; k < submissions[j].submited.length; k++) {
  1000. if (students[actual_student] == submissions[j].submited[k]) {
  1001. found = true;
  1002. break;
  1003. }
  1004. }
  1005. break;
  1006. }
  1007. }
  1008. if (found == false) {
  1009. postResultAutoEval();
  1010. } else {
  1011. // If it was sent, search it...
  1012. var final_url = "";
  1013. 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];
  1014. for (var j = 0; j < submissions.length; j++) {
  1015. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  1016. final_url = submissions[j].ilm;
  1017. break;
  1018. }
  1019. }
  1020. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  1021. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1022. window.frames["ifrm"].location=final_url;
  1023. }
  1024. } // function run_individual_evaluation()
  1025. var break_student = -1;
  1026. var break_exercise = -1;
  1027. function verifyBreak () {
  1028. if (actual_student == break_student && actual_exercise == break_exercise) {
  1029. postResultAutoEval(-6);
  1030. break_student = -1;
  1031. break_exercise = -1;
  1032. return;
  1033. } else {
  1034. break_student = actual_student;
  1035. break_exercise = actual_exercise;
  1036. }
  1037. }
  1038. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  1039. function getStudentAnswerURL () {
  1040. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1041. }
  1042. // This function is called by the iLM!!!
  1043. function getAutoEvalOriginalData () {
  1044. return original_propositions[actual_exercise];
  1045. }
  1046. function updateProgressBar () {
  1047. if (stoped) return;
  1048. var temp = (count_steps * value_by_step)|0;
  1049. count_steps++;
  1050. temp = temp > 100 ? 100 : temp;
  1051. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  1052. if (temp >= 100) {
  1053. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1054. $("#button_start").prop("disabled", false);
  1055. $("#button_stop").prop("disabled", true);
  1056. $("input:checkbox").attr("disabled", false);
  1057. clearInterval(var_interval);
  1058. }
  1059. }
  1060. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  1061. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  1062. function postResultAutoEval (grade = null) {
  1063. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  1064. if (grade == null) {
  1065. $("#"+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>\');
  1066. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1067. } else {
  1068. // Verify if the re-evaluation grade is the of that one registered:
  1069. var actual_value = 0;
  1070. var actual_student_grade = 0;
  1071. for (var k = 0; k < submissions.length; k++) {
  1072. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  1073. actual_value = submissions[k].grade;
  1074. for (var h = 0; h < submissions[k].submited.length; h++) {
  1075. if (submissions[k].submited[h] == students[actual_student]) {
  1076. actual_student_grade = submissions[k].allgrades[h];
  1077. break;
  1078. }
  1079. }
  1080. break;
  1081. }
  1082. }
  1083. // @FeedbackConvention
  1084. if (grade < 0) {
  1085. switch (grade) {
  1086. case -1:
  1087. // Test-cases are empty:
  1088. $("#"+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>\');
  1089. var mm = actual_exercise;
  1090. $("#"+id_t).find(".details-button").click(function(e) {
  1091. $(".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>\');
  1092. });
  1093. break;
  1094. case -2:
  1095. // Test-cases were manually altered by the student (fraud!):
  1096. $("#"+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>\');
  1097. var mm = actual_exercise;
  1098. $("#"+id_t).find(".details-button").click(function(e) {
  1099. $(".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>");
  1100. });
  1101. //AJAX
  1102. $.ajax({
  1103. dataType: "html",
  1104. 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",
  1105. success: function(d) {} });
  1106. break;
  1107. case -5:
  1108. // Execution failed:
  1109. $("#"+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>\');
  1110. var mm = actual_exercise;
  1111. //AJAX
  1112. $("#"+id_t).find(".details-button").click(function(e) {
  1113. $(".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>\');
  1114. });
  1115. break;
  1116. case -6: // iLM not answering was detected in "verifyBreak()"
  1117. // The iLM are not answering:
  1118. //AJAX
  1119. $("#"+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>\');
  1120. $("#"+id_t).find(".details-button").click(function(e) {
  1121. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  1122. });
  1123. break;
  1124. }
  1125. //AJAX
  1126. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1127. } else {
  1128. console.log((grade), (actual_student_grade));
  1129. if ((grade) == (actual_student_grade)) {
  1130. $("#"+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>\');
  1131. } else { // Notas diferem:
  1132. $("#"+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>\');
  1133. var mm = actual_exercise;
  1134. //AJAX
  1135. $("#"+id_t).find(".details-button").click(function(e) {
  1136. $(".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>\');
  1137. });
  1138. //AJAX
  1139. // Send to the endpoint the post_auto_eval_result to verify:
  1140. $.ajax({
  1141. dataType: "html",
  1142. 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),
  1143. success: function(d) {}
  1144. });
  1145. }
  1146. //AJAX
  1147. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1148. }
  1149. }
  1150. updateProgressBar();
  1151. // Does it must continue in the same exercise or stop?
  1152. if (actual_student < students.length) {
  1153. actual_student++;
  1154. run_individual_evaluation();
  1155. } else {
  1156. actual_student = 0;
  1157. // Does it go to next exercise or is it finished?
  1158. if (actual_exercise < selected_exercises.length) {
  1159. actual_exercise++;
  1160. run_individual_evaluation();
  1161. } else {
  1162. //AJAX
  1163. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1164. }
  1165. }
  1166. }
  1167. var original_propositions;
  1168. function get_original_propositions () {
  1169. original_propositions = [];
  1170. var count = 0;
  1171. for (var i = 0; i < exercises.length; i++) {
  1172. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1173. //AJAX
  1174. $.ajax({
  1175. dataType: "html",
  1176. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1177. success: function(d) { // variable "d" has the iLM content
  1178. original_propositions[count] = d; // exercise original content
  1179. count++;
  1180. if (count == selected_exercises.length) {
  1181. run_individual_evaluation();
  1182. }
  1183. }
  1184. });
  1185. }
  1186. }
  1187. }
  1188. function stop_evaluation () {
  1189. stoped = true;
  1190. //AJAX
  1191. $("#button_start").prop("disabled", false);
  1192. $("#button_stop").prop("disabled", true);
  1193. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1194. $("input:checkbox").attr("disabled", false);
  1195. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1196. clearInterval(var_interval);
  1197. }
  1198. var exercises = [ '; // '
  1199. foreach ($exercises_list as $exercise) {
  1200. print $exercise->id . ',';
  1201. }
  1202. print ' ];';
  1203. print ' var students = [ ';
  1204. foreach ($students_list as $student) {
  1205. print $student->userid . ',';
  1206. }
  1207. print '];';
  1208. print ' var ilms = [';
  1209. foreach ($exercises_list as $exercise) {
  1210. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1211. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1212. }
  1213. print ']';
  1214. print '</script>';
  1215. print '
  1216. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1217. <div class="modal-dialog modal-dialog-centered" role="document">
  1218. <div class="modal-content">
  1219. <div class="modal-header">
  1220. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1221. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1222. <span aria-hidden="true">&times;</span>
  1223. </button>
  1224. </div>
  1225. <div class="modal-body">
  1226. ...
  1227. </div>
  1228. <div class="modal-footer">
  1229. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1230. </div>
  1231. </div>
  1232. </div>
  1233. </div>'; //
  1234. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1235. print '<table id="table-results" class="table table-hover m-t-1">
  1236. <thead>
  1237. <tr id="cols-exercises">
  1238. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1239. </tr>
  1240. </thead>
  1241. <tbody>'; // "
  1242. // End of JavaScript code to auto-evaluation
  1243. foreach ($students_list as $student) {
  1244. $user = $DB->get_record('user', array('id' => $student->userid));
  1245. $avatar = new user_picture($user);
  1246. $avatar->courseid = $COURSE->id;
  1247. $avatar->link = true;
  1248. print ' <tr data-student="' . $student->userid . '">
  1249. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1250. </tr>' . "\n"; // "
  1251. }
  1252. print " </tbody>
  1253. </table>\n";
  1254. print $OUTPUT->footer();
  1255. } // function auto_evaluate()
  1256. /// This method moves an iAssign activity
  1257. function move_activity () {
  1258. global $USER, $CFG, $DB, $COURSE;
  1259. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1260. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1261. $update_entry_new_iassign = new stdClass();
  1262. $update_entry_new_iassign->id = $iassign_id;
  1263. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1264. // Update the iassign_statement
  1265. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1266. // Update file context
  1267. $c_i = context_module::instance($this->cm->id);
  1268. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1269. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1270. $path_module = context_course::instance($COURSE->id);
  1271. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1272. $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny); //2021/12
  1273. if ($context_file) {
  1274. $id_context = $context_file->id;
  1275. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1276. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1277. $context = context_module::instance($USER->cm); //2021/12
  1278. //2021/12 $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1279. //TODO 2022: trocar "$iassign_statement->id" por "$iassign_statement->file"???
  1280. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  1281. foreach ($files as $value) {
  1282. if ($value->get_filename() != ".") {
  1283. //2021/12 $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1284. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1285. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1286. $destiny_context = context_module::instance($course_module->id);
  1287. $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());
  1288. $updateentry = new stdClass();
  1289. $updateentry->id = $iassign_id;
  1290. $updateentry->filesid = $iassign_id; //2021/12 $newfile->get_itemid(); //TODO: esta' correto? $newfile definido 3 linhas acima NAO mais usado?
  1291. $DB->update_record("iassign_statement", $updateentry);
  1292. //2021/12 $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1293. break;
  1294. }
  1295. }
  1296. }
  1297. //2021/12 $this->return_home_course('moved_activity');
  1298. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
  1299. 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);
  1300. exit;
  1301. } // function move_activity()
  1302. // AQUI
  1303. /// This method duplicates an iAssign activity
  1304. function duplicate_activity () {
  1305. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1306. // Not used: $id = $this->cm->id; // Get {iassign}.id from {course_module}: {iassign_statement}.iassignid = {course_module}.id = $id
  1307. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1308. $context = context_module::instance($this->cm->id);
  1309. // Not used: $contextuser = context_user::instance($USER->id);
  1310. echo "locallib.php: duplicate_activity()<br/>"; //R
  1311. echo "cm.id=" . $id . ", iassignid=" . $iassignid . ", context.id=" . $contextuser->id . "<br/>"; //R ", context.instanceid=" . $contextuser->instanceid
  1312. // Get the the iAssign acitivity to be duplicated
  1313. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1314. echo "{iassign_statement}: #iassign_statement=" . count($iassign_statement) . "<br/>"; //R
  1315. // Remove the current id of activity
  1316. $original_iassign_statement_id = $iassign_statement->id;
  1317. $iassign_statement->id=0; // will receive the new {iassign_statement}.id - below "$updateentry->id = $id"
  1318. // Include prefix (Copy of ...)
  1319. $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name; // new name to {iassign_statement}.name
  1320. // Get the information about current author, and add this information in author_modified field
  1321. $author = $DB->get_record("user", array('id' => $USER->id)); // id; auth; ... username; password; idnumber; firstname; lastname; email; ... description ...
  1322. $iassign_statement->author_modified_name = $author->firstname . ' ' . $author->lastname;
  1323. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1324. echo "iassign_statement.id=" . $iassign_statement->id . ",iassign_statement.name =" . $iassign_statement->name . ", id_source_copy=" . $original_iassign_statement_id .
  1325. ", author.id=" . $author->id . ", author.firstname=" . $author->firstname . "<br/>";
  1326. // Store the activity in the table
  1327. //R if ($new_iassign_statement_id = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1328. if (1==1) { //R REMOVER!!!!
  1329. // Duplicate activity file
  1330. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1331. //2021/12 $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1332. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $original_iassign_statement_id);
  1333. echo "{files}: #files=" . count($files) . "<br/>"; //R
  1334. // {files}.get_id()
  1335. foreach ($files as $value) {
  1336. if ($value->get_filename() != ".") {
  1337. // Must have: {files}.itemid = {iassign_statement}.id ; {iassign_statement}.filesid = {files}.id
  1338. // Get the last entry in {files} $last_id and use as new {files}.itemid = $last_id+1
  1339. //2021/12 $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1340. echo "{files}: id=" . $value->id . "=" . $value->get_id() . ", filename=" . $value->filename . ", itemid=" . $value->itemid . ", contextid=" . $value->contextid . ", component=" . $value->component
  1341. . ", filearea=" . $value->filearea . ", userid=" . $value->userid . "<br/>"; //R
  1342. //print_r($value); echo "<br/>";
  1343. //R echo "last_id = {files}.itemid = " . $last_id . "<br/>";
  1344. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1345. /* //R
  1346. // ./lib/filestorage/file_storage.php: '$newfile' is protected
  1347. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $new_iassign_statement_id), $value);
  1348. // Now update {iassign_statement}.filesid with '$newfile->id': {iassign_statement}.filesid = {files}.id
  1349. $updateentry = new stdClass();
  1350. $updateentry->id = $new_iassign_statement_id; // points {iassign_statement}.id to the new entry of {iassign_statement}
  1351. //2021/12 $updateentry->filesid = $newfile->get_itemid();
  1352. $updateentry->filesid = $newfile->get_id(); // points {iassign_statement}.filesid to the new {files}: {iassign_statement}.filesid = {files}.id
  1353. // Update the duplicated iLM iAssign with new file id
  1354. $DB->update_record("iassign_statement", $updateentry);
  1355. */
  1356. }
  1357. }
  1358. }
  1359. // log event --------------------------------------------------------------------------------------
  1360. //R iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $new_iassign_statement_id, $this->cm->id);
  1361. //R $this->return_home_course('duplicated_activity');
  1362. exit;
  1363. } // function duplicate_activity()
  1364. // / This method gets the content from comment and register it
  1365. function add_comment () {
  1366. global $USER, $DB;
  1367. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1368. $comment = false;
  1369. if ($submission_comment)
  1370. $comment = $this->write_comment_submission();
  1371. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1372. if (!$id_submission) {
  1373. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  1374. if ($iassign_submission) {
  1375. $id_submission = $iassign_submission->id;
  1376. }
  1377. }
  1378. $content = $this->search_comment_submission($id_submission);
  1379. ob_end_clean();
  1380. header("Connection: close\r\n");
  1381. header("Content-Encoding: none\r\n");
  1382. header('Content-Type: text/html');
  1383. ob_start();
  1384. print $this->search_comment_submission($id_submission);
  1385. $size = ob_get_length();
  1386. header("Content-Length: $size");
  1387. ob_end_flush();
  1388. flush();
  1389. ob_end_clean();
  1390. // Send email to users:
  1391. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $id_submission));
  1392. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1393. }
  1394. /// This method alerts envolved to new comment sent
  1395. function send_alert_new_comment ($comment, $student_id = -1) {
  1396. global $USER, $DB, $COURSE, $SITE;
  1397. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign') . " ";
  1398. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); //leo 2021/12
  1399. $subject .= $iassign_ilm->name . ' ' . get_string('new_comment_mail_at', 'iassign') . ' ' . get_string("iassign", "iassign") . '/Moodle'; //leo 2021/12
  1400. // $url_curso; $url_submissao;
  1401. $text = "<p style='margin-top: 1rem;'>\n";
  1402. $text .= "<a href=\"" . new moodle_url('/course/view.php', array('id' => $COURSE->id)) . "\">" . $COURSE->shortname . "</a> " . " &#8811; \n";
  1403. $modinfo = get_fast_modinfo($COURSE);
  1404. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1405. if ($modinfo->get_section_info($i) && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1406. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1407. $text .= "<a href=\"" . $url_curso . "#section-" . $modinfo->get_section_info($i)->section . "\">" . get_section_name($COURSE, $modinfo->get_section_info($i)->section) . "</a> &#8811; \n";
  1408. break;
  1409. }
  1410. }
  1411. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1412. $text .= "<a href=\"" . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id)) . "\">" . $iassign->name . "</a> &#8811; \n";
  1413. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1414. array(
  1415. 'id' => $this->cm->id,
  1416. 'action' => 'viewsubmission',
  1417. 'iassign_current' => $this->activity->get_activity()->id,
  1418. 'userid_iassign' => $USER->id));
  1419. $text .= "<a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a></p>\n";
  1420. $text .= "<div style='margin-left: .5rem;'>\n";
  1421. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>\n";
  1422. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1423. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>\n";
  1424. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1425. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': ' . "<a href=\"" .
  1426. new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">" . $USER->firstname . " " . $USER->lastname . "</a>\n";
  1427. $text .= " - " . userdate(time());
  1428. $text .= "</div><div style='margin: 2rem;'>\n";
  1429. $text .= $comment;
  1430. $text .= "</div><div>\n";
  1431. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | \n";
  1432. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>\n";
  1433. $text .= "</div>\n";
  1434. // Who has to receive?
  1435. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1436. $userfrom = \core_user::get_noreply_user();
  1437. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1438. // other teachers receive also: (excepts the sender)
  1439. foreach ($teachers as $teacher) {
  1440. if ($teacher->id != $USER->id) {
  1441. email_to_user(
  1442. $teacher,
  1443. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1444. $subject,
  1445. "",
  1446. $text,
  1447. '',
  1448. '',
  1449. false,
  1450. $userfrom->email,
  1451. 'Não responda a esta mensagem' //TODO: internacionalizar
  1452. );
  1453. $message = new \core\message\message();
  1454. $message->component = 'mod_iassign';
  1455. $message->name = 'message';
  1456. $message->userfrom = core_user::get_noreply_user();
  1457. $message->userto = $teacher;
  1458. $message->subject = $subject;
  1459. $message->fullmessage = $text;
  1460. $message->fullmessageformat = FORMAT_MARKDOWN;
  1461. $message->fullmessagehtml = $text;
  1462. $message->smallmessage = $subject;
  1463. $message->notification = 1;
  1464. $message->contexturl = $url_submissao . '#comments';
  1465. $message->contexturlname = $this->activity->get_activity()->name;
  1466. $messageid = message_send($message);
  1467. }
  1468. } // foreach ($teachers as $teacher)
  1469. // and student:
  1470. $student = $DB->get_record('user', array('id' => $student_id));
  1471. $formated_text = str_replace("viewsubmission", "view", $text);
  1472. email_to_user(
  1473. $student,
  1474. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1475. $subject,
  1476. "",
  1477. $formated_text,
  1478. '',
  1479. '',
  1480. false,
  1481. $userfrom->email,
  1482. 'Não responda a esta mensagem' //TODO: internacionalizar
  1483. );
  1484. $url_student = new moodle_url('/mod/iassign/view.php',
  1485. array(
  1486. 'id' => $this->cm->id,
  1487. 'action' => 'view',
  1488. 'iassign_current' => $this->activity->get_activity()->id));
  1489. $message = new \core\message\message();
  1490. $message->component = 'mod_iassign';
  1491. $message->name = 'message';
  1492. $message->userfrom = core_user::get_noreply_user();
  1493. $message->userto = $student;
  1494. $message->subject = $subject;
  1495. $message->fullmessage = $formated_text;
  1496. $message->fullmessageformat = FORMAT_MARKDOWN;
  1497. $message->fullmessagehtml = $formated_text;
  1498. $message->smallmessage = $subject;
  1499. $message->notification = 1;
  1500. $message->contexturl = $url_student . '#comments';
  1501. $message->contexturlname = $this->activity->get_activity()->name;
  1502. $messageid = message_send($message);
  1503. } // if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  1504. else { // a student has sent the comment:
  1505. foreach ($teachers as $teacher) {
  1506. email_to_user(
  1507. $teacher,
  1508. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1509. $subject,
  1510. "",
  1511. $text,
  1512. '',
  1513. '',
  1514. false,
  1515. $userfrom->email,
  1516. 'Não responda a esta mensagem' //TODO: internacionalizar
  1517. );
  1518. $message = new \core\message\message();
  1519. $message->component = 'mod_iassign';
  1520. $message->name = 'message';
  1521. $message->userfrom = core_user::get_noreply_user();
  1522. $message->userto = $teacher;
  1523. $message->subject = $subject;
  1524. $message->fullmessage = $text;
  1525. $message->fullmessageformat = FORMAT_MARKDOWN;
  1526. $message->fullmessagehtml = $text;
  1527. $message->smallmessage = $subject;
  1528. $message->notification = 1;
  1529. $message->contexturl = $url_submissao . '#comments';
  1530. $message->contexturlname = $this->activity->get_activity()->name;
  1531. $messageid = message_send($message);
  1532. } // foreach ($teachers as $teacher)
  1533. }
  1534. } // function send_alert_new_comment($comment, $student_id = -1)
  1535. /// This method gets the content from the iLM and register it
  1536. // It could be the "exercise template" (teacher) or an answer (student)
  1537. function get_answer () {
  1538. global $USER, $CFG, $DB, $OUTPUT;
  1539. $id = $this->cm->id;
  1540. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1541. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1542. if ($submission_ajax == 1) ob_start();
  1543. $comment = false;
  1544. if ($submission_comment)
  1545. $comment = $this->write_comment_submission();
  1546. // receives data of iLM using the current activity
  1547. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1548. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1549. // receives data of submission of current activity
  1550. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1551. // receives post and get
  1552. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1553. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1554. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1555. $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)
  1556. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1557. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1558. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1559. $msg = '';
  1560. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1561. $newentry = new stdClass();
  1562. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1563. $newentry->userid = $this->userid_iassign;
  1564. $newentry->timecreated = time();
  1565. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1566. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1567. $DB->insert_record("iassign_allsubmissions", $newentry);
  1568. }
  1569. // Feedback
  1570. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1571. $str_action = "view"; // repeat
  1572. if (strtolower($iassign_ilm->name) == "igeom") {
  1573. }
  1574. $title = get_string('evaluate_iassign', 'iassign');
  1575. print $OUTPUT->header();
  1576. print $OUTPUT->box_start();
  1577. // Action = { view ; repeat ; viewsubmission }
  1578. // * '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")
  1579. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1580. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1581. $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;
  1582. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1583. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1584. print '<table width=100% >';
  1585. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1586. //TODO alterar aqui???
  1587. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1588. // empty_answer_post = No solution was posted.
  1589. if ($comment)
  1590. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1591. else
  1592. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1593. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1594. } else {
  1595. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1596. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1597. // Correct answer!!
  1598. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1599. $this->write_solution = 1; //
  1600. $status = 3;
  1601. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1602. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1603. // log record
  1604. $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;
  1605. // Trigger module viewed event.
  1606. $event = \mod_iassign\event\submission_created::create(array(
  1607. 'objectid' => $this->iassign->id,
  1608. 'context' => $this->context,
  1609. 'other' => $info
  1610. ));
  1611. $event->add_record_snapshot('course', $this->course);
  1612. $event->trigger();
  1613. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1614. // Wrong answer...: get_answer_incorrect
  1615. $status = 2;
  1616. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1617. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1618. // log record
  1619. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1620. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1621. // Trigger module viewed event.
  1622. $event = \mod_iassign\event\submission_created::create(array(
  1623. 'objectid' => $this->iassign->id,
  1624. 'context' => $this->context,
  1625. 'other' => $info
  1626. ));
  1627. $event->add_record_snapshot('course', $this->course);
  1628. $event->trigger();
  1629. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1630. // Presents to the learner the result of the automatic evaluate?
  1631. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1632. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1633. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1634. print '<tr>';
  1635. // log record
  1636. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1637. // Trigger module viewed event.
  1638. $event = \mod_iassign\event\submission_created::create(array(
  1639. 'objectid' => $this->iassign->id,
  1640. 'context' => $this->context,
  1641. 'other' => $info
  1642. ));
  1643. $event->add_record_snapshot('course', $this->course);
  1644. $event->trigger();
  1645. } else { // yes!!!
  1646. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1647. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1648. print '<tr>';
  1649. print $msg;
  1650. }
  1651. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1652. $status = 1;
  1653. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1654. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1655. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1656. print '<tr>';
  1657. // log record
  1658. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1659. $event = \mod_iassign\event\submission_created::create(array(
  1660. 'objectid' => $this->iassign->id,
  1661. 'context' => $this->context,
  1662. 'other' => $info
  1663. ));
  1664. $event->add_record_snapshot('course', $this->course);
  1665. $event->trigger();
  1666. } // if ($iassign_ilm->evaluate == 1)
  1667. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1668. print '</tr></table>';
  1669. print $OUTPUT->box_end();
  1670. // add or update evaluate
  1671. if ($this->write_solution == 1) {
  1672. $timenow = time();
  1673. // new record
  1674. if (!$iassign_submission) {
  1675. $newentry = new stdClass();
  1676. $newentry->userid = $this->userid_iassign;
  1677. // $newentry->userid = $USER->id;
  1678. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1679. $newentry->timecreated = $timenow;
  1680. $newentry->timemodified = $timenow;
  1681. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1682. $newentry->grade = round($grade_student, 2);
  1683. $newentry->status = $status;
  1684. $newentry->experiment = 1;
  1685. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1686. print_error('error_insert', 'iassign');
  1687. } else {
  1688. // Trigger module viewed event.
  1689. $event = \mod_iassign\event\submission_created::create(array(
  1690. 'objectid' => $this->iassign->id,
  1691. 'context' => $this->context
  1692. ));
  1693. $event->add_record_snapshot('course', $this->course);
  1694. $event->trigger();
  1695. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1696. }
  1697. } elseif ($iassign_submission->status != 3) {
  1698. $newentry = new stdClass();
  1699. $newentry->id = $iassign_submission->id;
  1700. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1701. $newentry->userid = $iassign_submission->userid;
  1702. $newentry->timecreated = $iassign_submission->timecreated;
  1703. $newentry->timemodified = $timenow;
  1704. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1705. $newentry->grade = round($grade_student, 2);
  1706. $newentry->status = $status;
  1707. $newentry->experiment = $iassign_submission->experiment + 1;
  1708. if (!$DB->update_record("iassign_submission", $newentry)) {
  1709. print_error('error_update', 'iassign');
  1710. //D depurar...
  1711. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1712. //D $fp = fopen("teste1.txt","w");
  1713. //D fwrite($fp,$stringAux);
  1714. } else {
  1715. // Trigger module viewed event.
  1716. $event = \mod_iassign\event\submission_updated::create(array(
  1717. 'objectid' => $this->iassign->id,
  1718. 'context' => $this->context
  1719. ));
  1720. $event->add_record_snapshot('course', $this->course);
  1721. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1722. }
  1723. } else {
  1724. if ($return_get_answer == 1) {
  1725. $newentry = new stdClass();
  1726. $newentry->id = $iassign_submission->id;
  1727. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1728. $newentry->userid = $iassign_submission->userid;
  1729. $newentry->timecreated = $iassign_submission->timecreated;
  1730. $newentry->timemodified = $timenow;
  1731. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1732. $newentry->grade = round($grade_student, 2);
  1733. $newentry->status = $status;
  1734. $newentry->experiment = $iassign_submission->experiment + 1;
  1735. if (!$DB->update_record("iassign_submission", $newentry))
  1736. print_error('error_update', 'iassign');
  1737. else {
  1738. $event = \mod_iassign\event\submission_updated::create(array(
  1739. 'objectid' => $this->iassign->id,
  1740. 'context' => $this->context
  1741. ));
  1742. $event->add_record_snapshot('course', $this->course);
  1743. $event->trigger();
  1744. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1745. print $OUTPUT->box_start();
  1746. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1747. print $OUTPUT->box_end();
  1748. }
  1749. } elseif ($return_get_answer == 2) {
  1750. print $OUTPUT->box_start();
  1751. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1752. print $OUTPUT->box_end();
  1753. } else {
  1754. print $OUTPUT->box_start();
  1755. print "
  1756. <script type='text/javascript'>
  1757. //<![CDATA[
  1758. function overwrite () {
  1759. document.formEnvio.return_get_answer.value = 1;
  1760. document.formEnvio.submit();
  1761. }
  1762. function nooverwrite () {
  1763. document.formEnvio.return_get_answer.value = 2;
  1764. document.formEnvio.submit();
  1765. }
  1766. //]]>
  1767. </script>";
  1768. $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;
  1769. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1770. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1771. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1772. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1773. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1774. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1775. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1776. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1777. <input type='hidden' name='return_get_answer'/> ";
  1778. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1779. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1780. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1781. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1782. print " </form>";
  1783. print $OUTPUT->box_end();
  1784. }
  1785. }
  1786. } // if ($this->write_solution == 1)
  1787. print $OUTPUT->footer();
  1788. if ($submission_ajax == 1) {
  1789. ob_end_clean();
  1790. print 'OK';
  1791. }
  1792. die();
  1793. } // function get_answer()
  1794. /// Export in file the answer of student.
  1795. function export_file_answer () {
  1796. global $DB;
  1797. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1798. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1799. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1800. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1801. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1802. $extensions = explode(",", $iassign_ilm->extension);
  1803. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1804. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1805. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1806. header("Pragma: public");
  1807. header("Expires: 0");
  1808. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1809. header("Cache-Control: private", false);
  1810. header("Content-Type: document/unknown");
  1811. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1812. set_time_limit(0);
  1813. print($iassign_submission->answer);
  1814. exit;
  1815. } // function export_file_answer()
  1816. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1817. // @calledby $this->export_package_answer()
  1818. //TODO Precisa terminar! //TODO_HTML
  1819. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1820. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1821. <head>
  1822. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1823. $str_html .= " </head>
  1824. <body>\n";
  1825. $tam = sizeof($array_iassign_name);
  1826. for ($ii=0; $ii<$tam; $ii++) {
  1827. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1828. }
  1829. $str_html .= "
  1830. </body>\n</html>";
  1831. return $str_html;
  1832. }
  1833. /// Export an package (zip) with all answer of students
  1834. // @calledby $this->action()
  1835. function export_package_answer () {
  1836. global $DB, $CFG, $OUTPUT;
  1837. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1838. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1839. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1840. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1841. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1842. $userid = optional_param('userid', NULL, PARAM_INT);
  1843. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1844. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1845. //TODO_HTML echo "username=$username<br/>"; exit;
  1846. $current_date = date('Y_m_d_H');
  1847. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1848. // If temporary directory under Moodle data does not exists => create it
  1849. if (!is_dir($diretorio)) {
  1850. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1851. // created directory with permissions to be seen by everyone
  1852. }
  1853. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1854. if (!is_writable($diretorio)) { // send a highlighted message!
  1855. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1856. exit; // just in case
  1857. }
  1858. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1859. $zip = new zip_archive(); // create ZIP
  1860. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1861. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1862. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1863. $vet_student_filename = array();
  1864. $vet_student_content = array();
  1865. foreach ($iassign_statements as $iassign_statement) {
  1866. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1867. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1868. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1869. $extensions = explode(",", $iassign_ilm->extension);
  1870. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1871. if ($iassign_submission) {
  1872. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1873. $student_content = $iassign_submission->answer;
  1874. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1875. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1876. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1877. if ($resp) {
  1878. $vet_student_filename[] = $student_filename;
  1879. $vet_student_content[] = $student_content;
  1880. }
  1881. else { // send a highlighted message!
  1882. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1883. exit; // just in case
  1884. }
  1885. }
  1886. } // foreach ($iassign_statements as $iassign_statement)
  1887. $zip->close(); // close the ZIP file
  1888. if (count($vet_student_filename)>0) {
  1889. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1890. $result_tf = $vet_result[0];
  1891. $filenameZip = $vet_result[1]->filename;
  1892. }
  1893. iassign_utils::download_file($zip_filename); // download the ZIP file
  1894. exit;
  1895. } // function export_package_answer()
  1896. /// Editing status of interactive activities
  1897. function edit_status () {
  1898. global $USER, $DB, $OUTPUT;
  1899. $newentry = new stdClass();
  1900. $newentry->id = $this->iassign_submission_current;
  1901. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1902. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1903. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1904. $newentry->status = $iassign_submission->status;
  1905. $newentry->teacher = $USER->id;
  1906. if (!$DB->update_record('iassign_submission', $newentry))
  1907. print_error('error_update', 'iassign');
  1908. else {
  1909. // Trigger module viewed event.
  1910. $event = \mod_iassign\event\submission_updated::create(array(
  1911. 'objectid' => $this->iassign->id,
  1912. 'context' => $this->context
  1913. ));
  1914. $event->add_record_snapshot('course', $this->course);
  1915. $event->trigger();
  1916. $this->action = 'viewsubmission';
  1917. $this->view_iassign_current();
  1918. } // if (!$DB->update_record('iassign_submission', $newentry))
  1919. } // function edit_status()
  1920. /// Editing grade of interactive activities
  1921. function edit_grade () {
  1922. global $USER, $DB, $OUTPUT;
  1923. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1924. if ($newgrade && $newgrade >= 0) {
  1925. $newentry = new stdClass();
  1926. $newentry->id = $this->iassign_submission_current;
  1927. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1928. $newentry->teacher = $USER->id;
  1929. if (!$DB->update_record('iassign_submission', $newentry))
  1930. print_error('error_update', 'iassign');
  1931. else {
  1932. // Trigger module viewed event.
  1933. $event = \mod_iassign\event\submission_updated::create(array(
  1934. 'objectid' => $this->iassign->id,
  1935. 'context' => $this->context
  1936. ));
  1937. $event->add_record_snapshot('course', $this->course);
  1938. $event->trigger();
  1939. }
  1940. } // if ($newgrade >= 0)
  1941. $this->action = 'viewsubmission';
  1942. $this->view_iassign_current();
  1943. } // function edit_grade()
  1944. //2022: ---------------------------------------------------------------------------------------------------------------------------------
  1945. //2022: Recuperacao {files} {iassign_statement}
  1946. //2022/02 see_all_files_context($context, $DB)
  1947. /// Temporary: fix 'iassign_statement.filesid' and 'files.itemid' (iassign_statement.filesid <- files.id; files.itemid <- iassign_statement.id)
  1948. // First version of iAssign used a random value to associate 'files.itemid' with 'iassign_statement.file'
  1949. // @calledby locallib.php ! get_update_files($context_id, $component, $filearea, $iassign_statement)
  1950. static function update_iassign_statement_files ($iassign_statement_id, $context_id, $component, $filearea, $files_ilmid) {
  1951. global $DB; //2022: echo "update_iassign_statement_files:<br/>";//D2022
  1952. // $files = $DB->get_records("files", array("component" => "mod_iassign", "filearea" => "exercise", "contextid" => $context_id, "itemid" => $files_ilmid)); // contextid=1390 ; itemid=400 ;
  1953. // $sql_query = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='exercise' AND contextid=" . $context_id . " AND filename<>'.' AND itemid=" . $files_ilmid;
  1954. $sql_query = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='exercise' AND contextid=" . $context_id . " AND itemid=" . $files_ilmid;
  1955. //echo "sql_query=" . $sql_query . "<br/>";//D2022
  1956. $elem_in_files = $DB->get_records_sql($sql_query);
  1957. if (!$elem_in_files) {
  1958. print "Vazio! <br/>"; //TODO: se mantiver, internacionalizar!
  1959. return NULL;
  1960. }
  1961. // if (count($elem_in_files)>1) { echo "Problema! Mais de um arquivo!<br/>"; return NULL; }
  1962. //2022: echo "#files=" . count($elem_in_files) . ": "; // print_r($elem_in_files); echo "<br/>";//D2022
  1963. foreach ($elem_in_files as $element_file) { // since ID is greater than 0, only "$file1 = $elem_in_files[0]" will not work!
  1964. if ($element_file->filename != '.') { // If not '.' is the actual file
  1965. $file1 = $element_file;
  1966. //2022: echo " - files: id=" . $file1->id . "; contextid=" . $file1->contextid . "; filearea=" . $file1->filearea . "; itemid=" . $file1->itemid . " <- " . $iassign_statement_id . "<br/>";
  1967. // this '$file1' has the 'hashcontent' of the real file content, then it will be used to update 'iassign_statement.filesid' <- 'files.id'
  1968. // break;
  1969. }
  1970. // Update 'files.itemid' with 'iassign_statement.id'
  1971. $newentry = new stdClass();
  1972. $newentry->id = $element_file->id; $newentry->itemid = $iassign_statement_id;
  1973. //2022: echo " &nbsp; &nbsp; &nbsp; &nbsp; Update 'files.itemid': "; print_r($newentry); echo "<br/>";
  1974. //2022: //leo voltar a atualizacao ou deixar para ADMIN via 'settings_activities.php'???????????????????????????????????????????????????????????????????????????
  1975. //2022: if (!$DB->update_record('files', $newentry)) print_error('error_update', 'iassign');
  1976. }
  1977. // Update 'iassign_statement.filesid' with 'files.id'
  1978. $newentry = new stdClass();
  1979. $newentry->id = $iassign_statement_id; $newentry->filesid = $file1->id;
  1980. //2022: echo " &nbsp; &nbsp; &nbsp; &nbsp; Update 'iassign_statement.filesid': "; print_r($newentry); echo "<br/>";
  1981. //2022: //leo voltar a atualizacao ou deixar para ADMIN via 'settings_activities.php'???????????????????????????????????????????????????????????????????????????
  1982. //2022: if (!$DB->update_record('iassign_statement', $newentry)) print_error('error_update', 'iassign');
  1983. } // static function update_iassign_statement_files($iassign_statement_id, $context_id, $component, $filearea, $files_ilmid)
  1984. /// Get file from table 'files', if 'files.itemid != iassign_statement.id' then update 'files.itemid' with 'iassign_statement.id'
  1985. // Usually 'context.instanceid' is 'course_modules.id' and 'course_modules.instance = iassign.id'
  1986. // However since iAssign is a "block of actual activities" from "iassign_statement", we store in 'files.itemid' the 'iassign_statement.id'
  1987. // @calledby function add_edit_iassign(): if ($this->action == 'edit'): to edit iAssign activity
  1988. static function get_update_files ($context_id, $component, $filearea, $iassign_statement, $fs) {
  1989. // $fs is the reference to all files in Moodle data
  1990. echo "<br/><br/><br/><br/><br/>get_update_files: iassign_statement: " . $context_id . ", " . $component . ", " . $filearea . ", " .
  1991. "id=" . $iassign_statement->id . ", file=" . $iassign_statement->file . ", filesid=" . $iassign_statement->filesid .
  1992. ", iassign_ilmid =" . $iassign_statement->iassign_ilmid . ",name=" . $iassign_statement->name . "<br/>\n";//D2022
  1993. $msgAux = ""; $must_update_files_itemid = 0;
  1994. // To consider old versions with improper association 'files.itemid': try 'iassign_statement.id' (correct one), 'iassign_statement.file' and 'iassign_statement.filesid'
  1995. // Correct association: {files}->itemid = $iassign_statement->id and {files}->id=$iassign_statement->fileid;
  1996. $files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->id); // try: 'iassign_statement.id'
  1997. if (!$files) { // Could not find with 'iassign_statement.id'
  1998. $msgAux .= "- Nao com 'iassign_statement.id'<br/>\n"; $must_update_files_itemid = 1;
  1999. $files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->file); // try with 'iassign_statement.file'
  2000. if (!$files) { // Could not find with 'iassign_statement.file'
  2001. $msgAux .= "- Nao com 'iassign_statement.file'<br/>\n";
  2002. $files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->filesid); // try with 'iassign_statement.filesid'
  2003. if (!$files) { // Could not find with 'iassign_statement.file'
  2004. //$files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->filesid-1); // try with 'iassign_statement.filesid'-1
  2005. //if (!$files) { // Could not find with 'iassign_statement.file'
  2006. // $msgAux .= "- Nao com 'iassign_statement.filesid'-1<br/>\n";
  2007. echo "ERRO completo: " . $msgAux;//D2022
  2008. return NULL;
  2009. // Desisto! $files = $fs->get_area_files($context_id, $component, $filearea, $iassign_statement->filesid); // try with 'iassign_statement.filesid'
  2010. // }
  2011. //else { $must_update_files_itemid = $iassign_statement->filesid-1; echo "OK 4, nao com {'id,file,filesid'), mas pegou com 'iassign_statement.filesid'-1=" . $iassign_statement->filesid . "-1<br/>\n"; }
  2012. }
  2013. else { $must_update_files_itemid = $iassign_statement->filesid; echo "OK 3, nao com 'id', nem com 'file', mas pegou com 'iassign_statement.filesid'=" . $iassign_statement->filesid . "<br/>\n"; }
  2014. }
  2015. else { $must_update_files_itemid = $iassign_statement->file; echo "OK 2, nao com 'id', pegou com 'iassign_statement.file'=" . $iassign_statement->file . "<br/>\n"; }
  2016. }
  2017. else echo "OK 1, pegou com 'iassign_statement.id'=" . $iassign_statement->id . "<br/>\n";//D2022
  2018. if ($must_update_files_itemid!=0) {
  2019. $res_update = iassign::update_iassign_statement_files($iassign_statement->id, $context_id, $component, $filearea, $must_update_files_itemid);
  2020. }
  2021. foreach ($files as $file) { if ($file->get_filename() != '.') break; }
  2022. //$files_itemid = $file->get_itemid(); // /var/www/html/saw2021_1/lib/filestorage/stored_file.php: devolve 'files.itemid'
  2023. //$files_id = $file->get_id(); // file_record
  2024. echo "files[.]: id=" . $files_id . ", itemid=" . $files_itemid . "<br/>\n"; //D2022
  2025. return $file;
  2026. } // function get_update_files($context_id, $component, $filearea, $iassign_statement)
  2027. //2022: Recuperacao {files} {iassign_statement}
  2028. //2022: ---------------------------------------------------------------------------------------------------------------------------------
  2029. /// Add or Edit interactive activities
  2030. // Get here when editing form and and submitted form data
  2031. // @calledby $this->action()
  2032. function add_edit_iassign () {
  2033. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2034. require_once('iassign_form.php');
  2035. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  2036. $iassignid = $this->iassign->id;
  2037. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  2038. $param->action = $this->action; // hidden
  2039. $param->id = $id; // hidden
  2040. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  2041. $COURSE->cm = $id;
  2042. $COURSE->iassignid = $iassignid;
  2043. $COURSE->iassign_file_id = NULL;
  2044. $context = context_module::instance($this->cm->id);
  2045. $contextuser = context_user::instance($USER->id);
  2046. $component = 'mod_iassign';
  2047. $filearea = 'exercise';
  2048. if (!empty($this->iassign_current))
  2049. $COURSE->iassign_id = $this->iassign_current;
  2050. else
  2051. $COURSE->iassign_id = 0;
  2052. $total_of_activities = 0; // get the total number of activities in this iAssign block
  2053. if ($this->action == 'add') {
  2054. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  2055. $params_temp = array('iassignid' => $iassignid);
  2056. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  2057. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  2058. $total_of_activities = count($iassign_statement);
  2059. $param->iassignid = $iassignid;
  2060. $param->name = "";
  2061. $param->oldname = "";
  2062. $param->type_iassign = 3;
  2063. $param->proposition = "";
  2064. $author = $DB->get_record("user", array("id" => $USER->id));
  2065. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  2066. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  2067. $param->author = $param->author_name;
  2068. $param->author_modified = $param->author_modified_name;
  2069. $COURSE->iassign_list = array();
  2070. $param->iassign_list = array();
  2071. if ($iassign_statement) {
  2072. foreach ($iassign_statement as $iassign) {
  2073. $iassignid = $iassign->id;
  2074. $param->iassign_list[$iassignid] = 0;
  2075. $COURSE->iassign_list[$iassignid] = new stdClass();
  2076. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  2077. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  2078. $COURSE->iassign_list[$iassignid]->enable = 1;
  2079. } // foreach ($iassign_statement as $iassign)
  2080. }
  2081. $param->iassign_ilmid = 0;
  2082. $param->file = 0;
  2083. $param->fileold = 0;
  2084. $param->filename = "";
  2085. $param->grade = $iassign_data->grade;
  2086. $param->timemodified = time();
  2087. $param->timecreated = time();
  2088. $param->timeavailable = $iassign_data->timeavailable;
  2089. $param->timedue = $iassign_data->timedue;
  2090. $param->preventlate = $iassign_data->preventlate;
  2091. $param->test = $iassign_data->test;
  2092. $param->special_param1 = 0;
  2093. $param->visible = 1;
  2094. $param->max_experiment = $iassign_data->max_experiment;
  2095. $param->dependency = 0;
  2096. $param->automatic_evaluate = 1;
  2097. $param->show_answer = 1;
  2098. } // if ($this->action == 'add')
  2099. elseif ($this->action == 'edit') {
  2100. $COURSE->iassign_list = array();
  2101. $this_activity = $this->activity->get_activity();
  2102. if ($this_activity != null) { // first enter here: fill form data
  2103. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  2104. $param->iassign_id = $iassign_statement_current->id; // oculto
  2105. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  2106. $param->name = $iassign_statement_current->name;
  2107. $param->oldname = $iassign_statement_current->name;
  2108. $param->type_iassign = $iassign_statement_current->type_iassign;
  2109. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  2110. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  2111. $param->author_name = $iassign_statement_current->author_name; // oculto
  2112. $param->author = $iassign_statement_current->author_name;
  2113. $author = $DB->get_record("user", array('id' => $USER->id));
  2114. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  2115. $param->author_modified = $param->author_modified_name;
  2116. $dependency = explode(';', $iassign_statement_current->dependency);
  2117. $param->iassign_list = array();
  2118. // Select all other iAssign activities inside this block with dependency
  2119. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  2120. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  2121. $array_dependency = array();
  2122. $subdependency = "";
  2123. $sub_subdependency = "";
  2124. // Dependents on this exercise
  2125. if ($iassign_statement_dependency) {
  2126. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  2127. // to whom this exercise depends
  2128. foreach ($inter as $tmp)
  2129. $sub_subdependency .= $this->search_sub_dependency($tmp);
  2130. $list_dependency = $subdependency . $sub_subdependency;
  2131. $array_dependency = explode(";", $list_dependency);
  2132. }
  2133. // Get all activities in the same iAssigment block:
  2134. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  2135. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  2136. $total_of_activities = count($all_others_iassign_statement) + 1;
  2137. $inter = array();
  2138. if ($all_others_iassign_statement) {
  2139. foreach ($all_others_iassign_statement as $iassign)
  2140. if (in_array($iassign->id, $dependency))
  2141. $inter[] = $iassign->id;
  2142. }
  2143. if ($all_others_iassign_statement) {
  2144. foreach ($all_others_iassign_statement as $iassign) {
  2145. $iassignid = $iassign->id;
  2146. $COURSE->iassign_list[$iassignid] = new stdClass();
  2147. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  2148. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  2149. if (in_array($iassignid, $dependency))
  2150. $param->iassign_list[$iassignid] = 1;
  2151. else
  2152. $param->iassign_list[$iassignid] = 0;
  2153. if (in_array($iassignid, $array_dependency))
  2154. $COURSE->iassign_list[$iassignid]->enable = 0;
  2155. else
  2156. $COURSE->iassign_list[$iassignid]->enable = 1;
  2157. } // foreach ($all_others_iassign_statement as $iassign)
  2158. } // if ($all_others_iassign_statement)
  2159. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  2160. $param->fileold = 0;
  2161. $param->filesid = 0;
  2162. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  2163. $param->filename = '';
  2164. $param->grade = $iassign_statement_current->grade;
  2165. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  2166. $param->timeavailable = $iassign_statement_current->timeavailable;
  2167. $param->timedue = $iassign_statement_current->timedue;
  2168. $param->preventlate = $iassign_statement_current->preventlate;
  2169. $param->test = $iassign_statement_current->test;
  2170. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  2171. $param->position = $iassign_statement_current->position; // hidden
  2172. $param->visible = $iassign_statement_current->visible;
  2173. $param->max_experiment = $iassign_statement_current->max_experiment;
  2174. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  2175. $param->show_answer = $iassign_statement_current->show_answer;
  2176. // Association {iassign_statement} with {files}
  2177. // Attention to the {files}.contextid and {files}.itemid used: "{files}.itemid" must be "{iassign_statement}.id" (and {iassign_statement}.filesid={files}.id)
  2178. // Old version used: {iassign_statement}.files = {files}.itemid with a randam value...
  2179. // ./lib/filestorage/file_storage.php: public function get_area_files($contextid, $component, $filearea, $itemid = false,...)
  2180. $fs = get_file_storage(); // Get reference to all files in Moodle data
  2181. //2021/12 $files_list = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  2182. //2022/02 $files_list = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id); // em alguns "_files.id" tem 'file' NAO 'id'
  2183. // It must have: {files}->id=$iassign_statement_current->file
  2184. //if ($iassign_statement_current->filesid) // new association {files}.itemid = {iassign_statement}.id //TODO: depois deixar apenas este
  2185. // $files_list = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id); //TODO: depois deixar apenas este
  2186. //else
  2187. if ($iassign_statement_current->file) // old association {files}.itemid = {iassign_statement}.file
  2188. $files_list = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  2189. // ------------------------------------------------------------------------------------------------------------------------------------
  2190. // Recover association {iassign_statement}/{files}
  2191. // It uses "files_functions.php ! update_iassignstatement_files(...)" to (eventually) reconstruct relation
  2192. //D echo "<br/><br/><br/><br/><br/><br/><br/><br/>locallib.php: add_edit_iassign(): #files_list=" . count($files_list) . "<br/>\n";
  2193. if (!$files_list) { // try with 'iassign_statement->filesid'
  2194. //D echo "locallib.php: add_edit_iassign(): com iassign_statement->id=" . $iassign_statement->id . " resulta vazio! Tente com iassign_statement->filesid=" . $iassign_statement->filesid . "<br/>\n";
  2195. //$files_list = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  2196. $files_list = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_current->filesid);
  2197. if (!$files_list) { // try with 'iassign_statement->id'
  2198. //D echo "locallib.php: add_edit_iassign(): com iassign_statement->id=" . $iassign_statement->id . " resulta vazio! Tente com iassign_statement->id=" . $iassign_statement->id . "<br/>\n";
  2199. $files_list = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_current->id);
  2200. }
  2201. //$files_list = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  2202. $files_list = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_current->filesid);
  2203. if ($files_list) {
  2204. // Redefine fields {iassign_statement}.filesid and {files}.itemid such as: {iassign_statement}.filesid={files}.id; {files}.itemid={iassign_statement}.id
  2205. $is_obj = $iassign_statement_current;
  2206. $count_fs = 0;
  2207. foreach ($files_list as $one_files) {
  2208. if ($count_fs==0) $f1_obj = $one_files; // $files_list[0]; // from {files}
  2209. else if ($count_fs==1) $f2_obj = $one_files; // $files_list[1]; // from {files}
  2210. $count_fs++;
  2211. }
  2212. //D_ echo " + #files_list = " . count($files_list) . "<br/>\n";
  2213. //D_ echo " + is_obj: " . $is_obj->name . ", id=" . $is_obj->id . ", files=" . $is_obj->files . ", filesid=" . $is_obj->filesid . ", iassignid=" . $is_obj->iassignid
  2214. //D_ . ", type_iassign=" . $is_obj->type_iassign . ", author_name=" . $is_obj->author_name . ", iassign_ilmid=" . $is_obj->iassign_ilmid
  2215. //D_ . ", automatic_evaluate=" . $is_obj->automatic_evaluate . ", show_answer=" . $is_obj->show_answer . ", filesid=" . $is_obj->filesid
  2216. //D_ . ", store_all_submissions=" . $is_obj->store_all_submissions . "<br/>\n";
  2217. //D_ echo " + f1_obj: filename = '" . $f1_obj->get_filename() . "', id=" . $f1_obj->get_id()
  2218. //D_ . "', contenthash=" . $f1_obj->get_contenthash() . "', contextid=" . $f1_obj->get_contextid() . "', filearea=" . $f1_obj->get_filearea()
  2219. //D_ . "', itemid=" . $f1_obj->get_itemid() . "', userid=" . $f1_obj->get_userid() . "', author=" . $f1_obj->get_author()
  2220. //D_ . "', timecreated=" . date("d/m/Y H:i:s", $f1_obj->get_timecreated()) . "<br/>\n";
  2221. //D_ echo " + f2_obj: filename = '" . $f2_obj->get_filename() . "', id=" . $f2_obj->get_id()
  2222. //D_ . "', contenthash=" . $f2_obj->get_contenthash() . "', contextid=" . $f2_obj->get_contextid() . "', filearea=" . $f2_obj->get_filearea()
  2223. //D_ . "', itemid=" . $f2_obj->get_itemid() . "', userid=" . $f2_obj->get_userid() . "', author=" . $f2_obj->get_author()
  2224. //D_ . "', timecreated=" . date("d/m/Y H:i:s", $f2_obj->get_timecreated()) . "<br/>\n";
  2225. require_once('files_functions.php'); // Get auxiliary functions to manage {iassign_statement}/{files}
  2226. $result = update_iassignstatement_files($DB, $is_obj->id, $f1_obj->get_id(), $is_obj, $f1_obj, $f2_obj); // ./files_functions.php
  2227. if (!$result) print "Could not change {iassign_statement}.filesid=" . $is_obj->id . " or {files}.itemid=" . $f1_obj->itemid . "<br/>";
  2228. }
  2229. } // if (!$files_list)
  2230. //D //echo "locallib.php: add_edit_iassign(): contextid=" . ($this->cm->id)->id . ", iassign_statement->id=" . $iassign_statement->id . ", iassign_statement->filesid=" . $iassign_statement->filesid . ", #files_list=" . count($files_list) . "<br/>\n";
  2231. //D echo "locallib.php: add_edit_iassign(): contextid=" . $context->id . ", iassign_statement_current->id=" . $iassign_statement_current->id . ", iassign_statement_current->filesid=" . $iassign_statement_current->filesid . ", #files_list=" . count($files_list) . "<br/>\n";
  2232. // $files_list = iassign::get_update_files($context->id, $component, $filearea, $iassign_statement_current, $fs); //2022: tentativa de recupearar arquivos se perdido
  2233. if ($files_list) { // get the first {files} with real "filename"
  2234. foreach ($files_list as $file_item) {
  2235. if ($file_item->get_filename() != '.') {
  2236. $param->filename = $file_item->get_filename();
  2237. $param->file = $file_item->get_id();
  2238. $param->fileold = $file_item->get_id();
  2239. $COURSE->iassign_file_id = $file_item->get_id();
  2240. break; // stop at the first with a "real" filename
  2241. }
  2242. }
  2243. }
  2244. //TODO //MOOC2014 -- inicio
  2245. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  2246. //D if ($iassign_ilm_configs) {
  2247. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  2248. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  2249. //D } //MOOC2014 -- fim
  2250. } // if ($this_activity != null)
  2251. } // elseif ($this->action == 'edit')
  2252. // Get all iActivity in the iAssign block with id = $this->iassign->id
  2253. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  2254. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  2255. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  2256. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  2257. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  2258. $param->position = $total_of_activities;
  2259. // Create form and associate its data
  2260. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  2261. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  2262. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  2263. if (isset($param->iassign_ilmid)) {
  2264. // array is additional atributes to 'form'
  2265. // '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)"
  2266. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  2267. }
  2268. else {
  2269. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  2270. }
  2271. $mform->set_data($param); // define data in the form
  2272. if ($mform->is_cancelled()) {
  2273. $this->return_home_course('iassign_cancel');
  2274. exit;
  2275. }
  2276. else { // else if ($mform->is_cancelled())
  2277. $result = $mform->get_data();
  2278. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  2279. if ($result) {
  2280. $result->context = $context;
  2281. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  2282. $result->grade = 0;
  2283. if ($result->type_iassign == 1) {
  2284. $result->automatic_evaluate = 0;
  2285. $result->show_answer = 0;
  2286. }
  2287. elseif ($result->automatic_evaluate == 0)
  2288. $result->show_answer = 0;
  2289. // $_POST['iassign_list']
  2290. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  2291. if ($result->iassign_list) {
  2292. foreach ($result->iassign_list as $key => $value)
  2293. $result->dependency .= $key . ';';
  2294. }
  2295. else
  2296. $result->dependency = 0;
  2297. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  2298. //TODO Then get it directly from the form data $_POST!
  2299. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  2300. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  2301. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  2302. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  2303. if ($this->action == 'add') {
  2304. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  2305. if ($iassign_statement_name) {
  2306. $this->return_home_course('error_iassign_name');
  2307. die();
  2308. }
  2309. // Really insert the new iActivity in table '*_iassign_statement'
  2310. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  2311. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  2312. // Trigger module viewed event.
  2313. $event = \mod_iassign\event\iassign_created::create(array(
  2314. 'objectid' => $iassignid,
  2315. 'context' => $context
  2316. ));
  2317. $event->add_record_snapshot('course', $this->course);
  2318. $event->trigger();
  2319. $this->return_home_course('iassign_add');
  2320. } // if ($this->action == 'add')
  2321. elseif ($this->action == 'edit') {
  2322. $iassignid = $this->activity->update_iassign($result);
  2323. $this->activity->update_calendar($iassignid, $result->oldname);
  2324. // Trigger module viewed event.
  2325. $event = \mod_iassign\event\iassign_updated::create(array(
  2326. 'objectid' => $iassignid,
  2327. 'context' => $context
  2328. ));
  2329. $event->add_record_snapshot('course', $this->course);
  2330. $event->trigger();
  2331. $this->return_home_course('iassign_update');
  2332. } // elseif ($this->action == 'edit')
  2333. die();
  2334. } // if ($result)
  2335. } // else if ($mform->is_cancelled())
  2336. print $OUTPUT->header();
  2337. $mform->display();
  2338. print $OUTPUT->footer();
  2339. die();
  2340. } // function add_edit_iassign()
  2341. /// Search for dependencies
  2342. function search_dependency ($search_iassing_id, $iassign_statement) {
  2343. global $DB, $OUTPUT;
  2344. $dependency = "";
  2345. if ($iassign_statement)
  2346. foreach ($iassign_statement as $iassign) {
  2347. $inter_dependency = explode(';', $iassign->dependency);
  2348. if (in_array($search_iassing_id, $inter_dependency)) {
  2349. $dependency .= $iassign->id . ";";
  2350. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2351. } // if (in_array($search_iassing_id, $inter_dependency))
  2352. } // foreach ($iassign_statement as $iassign)
  2353. return $dependency;
  2354. }
  2355. /// Search for "sub"dependency
  2356. function search_sub_dependency ($search_iassing_id) {
  2357. global $DB, $OUTPUT;
  2358. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2359. $dependency = "";
  2360. if ($iassign_statement) {
  2361. $inter_dependency = explode(';', $iassign_statement->dependency);
  2362. foreach ($inter_dependency as $tmp) {
  2363. if ($tmp != 0)
  2364. $dependency .= $tmp . ";";
  2365. $dependency .= $this->search_sub_dependency($tmp);
  2366. } // foreach ($inter_dependency as $tmp)
  2367. } // if ($iassign_statement)
  2368. return $dependency;
  2369. } // function search_sub_dependency($search_iassing_id)
  2370. // Warning message
  2371. static function warning_message_iassign ($strcode) {
  2372. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2373. }
  2374. /// Update grade of iAssign
  2375. // Called always any iAssign activity is created
  2376. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2377. static function update_grade_iassign ($iassignid) {
  2378. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2379. require_once($CFG->libdir . '/gradelib.php');
  2380. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2381. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2382. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2383. // Each iAssign item is associated with one item on the "gradebook"
  2384. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2385. //$sum_grade = 0;
  2386. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2387. //foreach($grade as $tmp) {
  2388. // $sum_grade += $tmp->grade;
  2389. // }
  2390. //1 Solution 1
  2391. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2392. //1 $sum_grade = 0; //1
  2393. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2394. //2 Solution 2
  2395. $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
  2396. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2397. if (key($array_sum_grade))
  2398. $sum_grade = key($array_sum_grade); //2
  2399. else
  2400. $sum_grade = 0; //2
  2401. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2402. $grades = NULL;
  2403. $params_temp = array('itemname' => $grade_iassign->name);
  2404. $params_temp['iteminstance'] = $iassignid;
  2405. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2406. //2016 if ($sum_grade != 0) {
  2407. $params_temp['grademax'] = $sum_grade;
  2408. $params_temp['rawgrademax'] = $sum_grade;
  2409. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2410. $params_temp['grademin'] = 0;
  2411. // @calls /lib/gradelib.php: call to grade_item->insert()
  2412. //TODO: is there any error here in Moodle version 3.0?
  2413. //TODO: Incorrect property 'grademax' found when inserting grade object
  2414. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2415. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2416. }
  2417. /// Update grade of student
  2418. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2419. global $CFG, $DB, $OUTPUT;
  2420. require_once($CFG->libdir . '/gradelib.php');
  2421. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2422. // Review all the student submission for this iAssign activity
  2423. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2424. $total_grade = 0;
  2425. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2426. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2427. if ($iassign_submission)
  2428. $total_grade += $iassign_submission->grade;
  2429. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2430. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2431. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2432. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2433. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2434. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2435. $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
  2436. if (key($array_sum_grade))
  2437. $sum_grade = key($array_sum_grade); //2
  2438. else
  2439. $sum_grade = 0; //2
  2440. $grades['userid'] = $userid;
  2441. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2442. $params_temp = array('itemname' => $grade_iassign->name);
  2443. $params_temp['iteminstance'] = $iassignid;
  2444. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2445. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2446. $params_temp['grademax'] = $sum_grade;
  2447. $params_temp['rawgrademax'] = $sum_grade;
  2448. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2449. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2450. }
  2451. /// Display caption of icons - to the bottom page of teacher's report
  2452. function view_legend_icons () {
  2453. global $USER, $CFG, $DB, $OUTPUT;
  2454. $id = $this->cm->id;
  2455. if ($this->action == 'print')
  2456. print '<table border=1 width=100%><tr>';
  2457. else
  2458. print '<table width=100%><tr>';
  2459. print '<td >';
  2460. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2461. if ($this->action != 'print') {
  2462. $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>\n";
  2463. $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>\n";
  2464. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2465. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2466. } // if ($this->action != 'print')
  2467. print '</tr></table>' . "\n";
  2468. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2469. print '</td></tr></table>' . "\n";
  2470. } // function view_legend_icons()
  2471. /// Display activity current
  2472. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2473. function view_iassign_current () {
  2474. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2475. $id = $this->cm->id;
  2476. $iassignid = $this->iassign->id;
  2477. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2478. $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
  2479. // 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 ...
  2480. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2481. if (!$iassign_statement_activity_item) {
  2482. print $OUTPUT->header();
  2483. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2484. print $OUTPUT->footer();
  2485. exit;
  2486. }
  2487. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2488. $ilm_name = '';
  2489. if ($ilm->ilm)
  2490. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2491. // 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
  2492. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2493. // log record
  2494. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2495. //Trigger module viewed event.
  2496. $event = \mod_iassign\event\submission_viewed::create(array(
  2497. 'objectid' => $iassign->id,
  2498. 'context' => $this->context,
  2499. 'other' => $info
  2500. ));
  2501. $event->add_record_snapshot('course', $this->course);
  2502. $event->trigger();
  2503. // Search of iLM data used in the current activity
  2504. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2505. // Add actual activity to navbar:
  2506. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2507. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2508. print $OUTPUT->header();
  2509. if ($this->action == 'viewsubmission') {
  2510. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2511. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2512. else
  2513. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2514. } else {
  2515. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2516. }
  2517. if ($iassign_submission)
  2518. $this->update_comment($iassign_submission->id);
  2519. //2021/12 $file = $iassign_statement_activity_item->filesid;
  2520. $file = $iassign_statement_activity_item->id;
  2521. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2522. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2523. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2524. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2525. $this->bottonPost = 0; // hide submit button
  2526. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2527. $this->view_iassign = false; // disable visualization of activity
  2528. $repeat = "";
  2529. $last_iassign = "";
  2530. $student_answer = "";
  2531. $comment = "";
  2532. // *** Teacher access (view learner's submission)
  2533. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2534. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2535. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2536. // ---> access teacher for test
  2537. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2538. $this->bottonPost = 1;
  2539. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2540. $this->activity->view_dates();
  2541. $USER->iassignEdit = $this->bottonPost;
  2542. $this->activity->show_info_iassign();
  2543. if ($iassign_submission) {
  2544. //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;
  2545. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2546. } else {
  2547. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2548. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2549. }
  2550. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2551. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2552. // Prepare tags to present the iLM
  2553. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2554. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2555. // *** (end) Teacher access (view the activity)
  2556. // *** Teacher access (view learner's submission to the activity)
  2557. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2558. // It is teacher or 'nonediting teacher' that can evaluate
  2559. // ----> area teacher evaluate
  2560. $row = optional_param('row', 0, PARAM_INT);
  2561. $column = optional_param('column', 0, PARAM_INT);
  2562. $link_next = iassign_icons::insert('right_disable');
  2563. $link_previous = iassign_icons::insert('left_disable');
  2564. $link_up = iassign_icons::insert('up_disable');
  2565. $link_down = iassign_icons::insert('down_disable');
  2566. if (isset($USER->matrix_iassign[$row][$column])) {
  2567. $has_row_column = True;
  2568. $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
  2569. }
  2570. else {
  2571. $has_row_column = False;
  2572. $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
  2573. }
  2574. $msgViewAction = "view.php?action=viewsubmission&id=$id&iassign_submission_current=";
  2575. $msgUserId_current = "&userid_iassign=" . $this->userid_iassign . "&iassign_current=";
  2576. // next_activity
  2577. if ($has_row_column && $element_matrix_iassign->iassign_next != - 1) {
  2578. $url_next = $msgViewAction . $USER->matrix_iassign[$row][$column + 1]->iassign_submission_current . $msgUserId_current . $element_matrix_iassign->iassign_next . "&view_iassign=report&row=" . ($row) . "&column=" . ($column + 1);
  2579. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2580. }
  2581. // previous_activity
  2582. if ($has_row_column && $element_matrix_iassign->iassign_previous != - 1) {
  2583. $url_previous = $msgViewAction . $USER->matrix_iassign[$row][$column - 1]->iassign_submission_current . $msgUserId_current . $element_matrix_iassign->iassign_previous . "&view_iassign=report&row=" . ($row) . "&column=" . ($column - 1);
  2584. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2585. }
  2586. // previous_student
  2587. if ($has_row_column && $element_matrix_iassign->user_next != - 1) {
  2588. $url_down = $msgViewAction . $USER->matrix_iassign[$row + 1][$column]->iassign_submission_current . "&userid_iassign=" . $element_matrix_iassign->user_next . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row + 1) . "&column=" . ($column);
  2589. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2590. }
  2591. // next_student
  2592. if ($has_row_column && $element_matrix_iassign->user_previous != - 1) {
  2593. $url_up = $msgViewAction . $USER->matrix_iassign[$row - 1][$column]->iassign_submission_current . "&userid_iassign=" . $element_matrix_iassign->user_previous . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row - 1) . "&column=" . ($column);
  2594. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2595. }
  2596. if ($iassign_submission) {
  2597. $student_answer = $iassign_submission->answer;
  2598. }
  2599. $last_iassign = get_string('last_iassign', 'iassign');
  2600. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2601. // Messages related to due date (and user role)
  2602. $this->activity->view_dates();
  2603. print $OUTPUT->box_start();
  2604. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2605. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2606. if ($user_data) // additional security (if occurs programming errors in $$url_next, $url_previous...)
  2607. print $OUTPUT->user_picture($user_data);
  2608. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2609. print '</td>' . "\n";
  2610. print '<td width=20% align=right>' . "\n";
  2611. print '<table width=50 cellpadding="0">';
  2612. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2613. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2614. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2615. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2616. print '</table>' . "\n";
  2617. print '</td></tr></table>' . "\n";
  2618. print $OUTPUT->box_end();
  2619. print $OUTPUT->box_start();
  2620. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2621. print '<td width=60% valign="top">' . "\n";
  2622. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2623. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2624. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2625. $resp = get_string('yes');
  2626. else
  2627. $resp = get_string('no');
  2628. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2629. if ($iassign_statement_activity_item->show_answer == 1)
  2630. $resp = get_string('yes');
  2631. else
  2632. $resp = get_string('no');
  2633. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2634. print '</td>';
  2635. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2636. print '<td width=40% valign="top" align="left">';
  2637. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2638. // check status of solution sent by the student
  2639. if ($iassign_submission) {
  2640. switch ($iassign_submission->status) {
  2641. case 3 :
  2642. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2643. break;
  2644. case 2 :
  2645. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2646. break;
  2647. case 1 :
  2648. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2649. break;
  2650. default :
  2651. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2652. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2653. } // switch ($iassign_submission->status)
  2654. }
  2655. else { // if ($iassign_submission)
  2656. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2657. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2658. }
  2659. // update_status
  2660. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2661. $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);
  2662. print " <script type='text/javascript'>
  2663. //<![CDATA[
  2664. function overwriteStatus (newstatus) {
  2665. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2666. document.formEditStatus.return_status.value=newstatus;
  2667. document.formEditStatus.submit();
  2668. }
  2669. else
  2670. document.formEditStatus.return_status.value=-1;
  2671. }
  2672. //]]>
  2673. </script>";
  2674. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2675. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2676. 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";
  2677. print " <input type='hidden' name='return_status'>\n";
  2678. print "</form>\n";
  2679. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2680. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2681. $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);
  2682. print "
  2683. <script type='text/javascript'>
  2684. //<![CDATA[
  2685. function overwriteGrade (newgrade,maxgrade) {
  2686. if (newgrade<0 || newgrade>maxgrade) {
  2687. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2688. document.formEditGrade.return_grade.value=-1;
  2689. document.formEditGrade.submit();
  2690. }
  2691. else {
  2692. document.formEditGrade.return_grade.value=newgrade;
  2693. document.formEditGrade.submit();
  2694. }
  2695. }
  2696. //]]>
  2697. </script>";
  2698. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2699. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2700. print " <input type='text' name='grade' size='6'>";
  2701. print " <input type='hidden' name='return_grade'> ";
  2702. 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";
  2703. print "</form>";
  2704. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2705. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2706. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2707. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2708. if ($teacher)
  2709. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2710. } // if ($iassign_submission->experiment > 0)
  2711. print '</td>';
  2712. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2713. print '</tr></table>';
  2714. print $OUTPUT->box_end();
  2715. $USER->iassignEdit = $this->bottonPost;
  2716. print activity::toggle_columns_script();
  2717. if ($iassign_submission && $allow_resubmission) {
  2718. // Put the iLM to
  2719. print $OUTPUT->box_start();
  2720. print '<p><strong>' . $last_iassign . '</strong></p>';
  2721. //d if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2722. $enderecoPOST = "";
  2723. // Prepare tags to present the iLM
  2724. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2725. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2726. print $OUTPUT->box_end();
  2727. } // if ($iassign_submission && $allow_resubmission)
  2728. else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2729. // If '$student_answer' is empty, then the student does not submit any solution to the exercice
  2730. // ATTENTION: exception used by iGeom (exercise with "script")
  2731. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2732. if (substr($ilm_name, 0, 5)=="igeom") {
  2733. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2734. $loadTeacherActivity = true;
  2735. }
  2736. else
  2737. if (!$student_answer) { //2022/01 this student does not submit any soluction => load the teacher content
  2738. $loadTeacherActivity = true;
  2739. }
  2740. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2741. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2742. print activity::toggle_columns_script();
  2743. // Prepare tags to present the iLM
  2744. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2745. }
  2746. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2747. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2748. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2749. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2750. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2751. // *** (end) Teacher access (view learner's submission to the activity)
  2752. // *** Student access (view the activity)
  2753. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2754. // It could be the learner (he could send or resend the activity)
  2755. // ---> access student
  2756. $time_now = time();
  2757. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2758. // activity of type example - not submit button for submission
  2759. $this->view_iassign = true;
  2760. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2761. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2762. // activity of type test - iLM automatic evaluator - submit button for submission
  2763. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2764. $this->bottonPost = 1;
  2765. $this->view_iassign = true;
  2766. } else
  2767. $this->view_iassign = false;
  2768. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2769. // activity of type exercise (learner can send his answer, if yet open...)
  2770. $this->view_iassign = true;
  2771. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2772. $this->view_iassign = false;
  2773. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2774. $this->bottonPost = 1; // allow the submit button
  2775. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2776. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2777. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2778. if (!$iassign_submission) {
  2779. $str_iassign_submission_id = '';
  2780. $str_iassign_submission_answer = '';
  2781. }
  2782. else {
  2783. $str_iassign_submission_id = $iassign_submission->id;
  2784. $str_iassign_submission_answer = $iassign_submission->answer;
  2785. }
  2786. if ($this->action != 'repeat') {
  2787. $repeat = "<a href='view.php?action=repeat&id="
  2788. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2789. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2790. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2791. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2792. }
  2793. $this->bottonPost = 1;
  2794. $this->write_solution = 1; // can register his submission
  2795. $student_answer = $str_iassign_submission_answer;
  2796. }
  2797. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2798. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2799. $last_iassign = get_string('last_iassign', 'iassign');
  2800. if ($iassign_submission) {
  2801. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2802. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2803. $student_answer = $iassign_submission->answer;
  2804. } else {
  2805. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2806. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2807. }
  2808. }
  2809. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2810. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2811. $this->bottonPost = 1;
  2812. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2813. } else {
  2814. $last_iassign = get_string('last_iassign', 'iassign');
  2815. if ($iassign_submission) {
  2816. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2817. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2818. $student_answer = $iassign_submission->answer;
  2819. } else {
  2820. // Symbol of "redo activity"
  2821. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2822. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2823. }
  2824. }
  2825. } // elseif ($iassign_statement_activity_item->test == 1)
  2826. elseif ($iassign_statement_activity_item->test == 0)
  2827. $this->view_iassign = false;
  2828. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2829. if ($iassign_submission)
  2830. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2831. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2832. else
  2833. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2834. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2835. $this->activity->view_dates(); // prints "Type of activity:", "Available from:"
  2836. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2837. print $OUTPUT->box_start();
  2838. print '<table width=100% border=0 valign="top">' . "\n";
  2839. print '<tr><td width=60% valign="top">' . "\n";
  2840. $flag_dependency = true;
  2841. if ($iassign_statement_activity_item->type_iassign == 3) {
  2842. if ($iassign_statement_activity_item->dependency == 0) {
  2843. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2844. } else {
  2845. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2846. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2847. foreach ($dependencys as $dependency) {
  2848. if ($dependency) {
  2849. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2850. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2851. if ($dependencysubmissions) {
  2852. if ($dependencysubmissions->status == 3)
  2853. $icon = iassign_icons::insert('correct');
  2854. elseif ($dependencysubmissions->status == 2) {
  2855. $icon = iassign_icons::insert('incorrect');
  2856. $flag_dependency = false;
  2857. } elseif ($dependencysubmissions->status == 1) {
  2858. $icon = iassign_icons::insert('post');
  2859. $flag_dependency = false;
  2860. } elseif ($dependencysubmissions->status == 0) {
  2861. $icon = iassign_icons::insert('not_post');
  2862. $flag_dependency = false;
  2863. }
  2864. } else {
  2865. $icon = iassign_icons::insert('not_post');
  2866. $flag_dependency = false;
  2867. } // if ($dependencysubmissions)
  2868. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2869. } // if ($dependency)
  2870. } // foreach ($dependencys as $dependency)
  2871. } // if ($iassign_statement_activity_item->dependency == 0)
  2872. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2873. if ($flag_dependency == false) {
  2874. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2875. $this->view_iassign = false;
  2876. print '</tr></table>' . "\n";
  2877. }
  2878. else {
  2879. $this->view_iassign = true;
  2880. print '</td>' . "\n";
  2881. } // if ($flag_dependency == false)
  2882. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2883. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2884. // receiver=1 - message to teacher
  2885. // receiver=2 - message to student
  2886. if ($iassign_submission) {
  2887. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2888. if ($verify_message)
  2889. $comment = iassign_icons::insert('comment_unread');
  2890. }
  2891. print '<td width=40% valign="top" align="left">';
  2892. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2893. if ($iassign_statement_activity_item->show_answer == 1) {
  2894. // check status of solution sent by the student
  2895. if ($iassign_submission) {
  2896. switch ($iassign_submission->status) {
  2897. case 3 :
  2898. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2899. break;
  2900. case 2 :
  2901. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2902. break;
  2903. case 1 :
  2904. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2905. break;
  2906. default :
  2907. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2908. $repeat = "";
  2909. $last_iassign = "";
  2910. } // switch ($iassign_submission->status)
  2911. } else {
  2912. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2913. $repeat = "";
  2914. $last_iassign = "";
  2915. }
  2916. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2917. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2918. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2919. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2920. if ($iassign_statement_activity_item->max_experiment == 0)
  2921. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2922. else {
  2923. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2924. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2925. $repeat = "";
  2926. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2927. $this->bottonPost = 0;
  2928. $this->write_solution = 0;
  2929. }
  2930. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2931. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2932. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2933. if ($teacher)
  2934. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2935. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2936. } // if ($iassign_statement_activity_item->show_answer==1)
  2937. else {
  2938. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2939. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2940. $repeat = "";
  2941. $last_iassign = "";
  2942. } elseif ($iassign_submission->status == 1) {
  2943. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2944. }
  2945. }
  2946. print '</td>';
  2947. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2948. print '</tr></table>' . "\n";
  2949. // Presents the iLM
  2950. print '<table width=100% border=0 valign="top">' . "\n";
  2951. print '<td width=80% align="left">';
  2952. 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\".
  2953. print '<td width=20% align="rigth">';
  2954. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2955. print $repeat; // symbol of "redo activity"
  2956. print '</td></tr></table>' . "\n";
  2957. //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)'
  2958. print activity::toggle_columns_script();
  2959. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2960. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2961. $output = $OUTPUT->box_start();
  2962. $USER->iassignEdit = $this->bottonPost;
  2963. // ---
  2964. // Presents the iLM
  2965. // Prepare tags to present the iLM
  2966. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2967. $student_answer = ""; //?
  2968. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2969. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2970. $student_answer = "";
  2971. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2972. } else {
  2973. // When student is redoing his activity
  2974. // ATTENTION: exception used by iGeom (exercise with "script")
  2975. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2976. if (substr($ilm_name, 0, 5)=="igeom") {
  2977. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2978. $loadTeacherActivity = true;
  2979. }
  2980. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2981. }
  2982. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2983. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2984. //1 $history_comment = '';
  2985. //1 if ($iassign_submission) {
  2986. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2987. //1 }
  2988. //1 if (!empty($history_comment)) {
  2989. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2990. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2991. //1 $output .= $history_comment;
  2992. //1 $output .= "</table>\n";
  2993. //1 }
  2994. //1 $output .= "</form></center>\n";
  2995. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2996. //1 }
  2997. $output .= $OUTPUT->box_end();
  2998. print $output;
  2999. } // if ($this->view_iassign)
  3000. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  3001. } // if ($this->view_iassign)
  3002. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  3003. else
  3004. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  3005. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3006. print '<table width=100% border=0 valign="top">' . "\n";
  3007. print '<tr><td width=60% valign="top">' . "\n";
  3008. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  3009. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  3010. print '</tr></table>' . "\n";
  3011. $student_answer = "";
  3012. $enderecoPOST = "";
  3013. // Prepare tags to present the iLM
  3014. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  3015. print $output;
  3016. }
  3017. //2020 Frame with area to send and read comments (in this point to allow everyone read)
  3018. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  3019. 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
  3020. // Put a block with area to sent/answer comments
  3021. $output = '';
  3022. $history_comment = '';
  3023. $row = optional_param('row', 0, PARAM_INT);
  3024. $column = optional_param('column', 0, PARAM_INT);
  3025. if ($iassign_submission) {
  3026. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  3027. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  3028. $history_comment = $this->search_comment_submission($iassign_submission->id);
  3029. }
  3030. else {
  3031. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  3032. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  3033. }
  3034. $output .= $OUTPUT->box_start();
  3035. //if (!empty($history_comment)) {
  3036. $output .= "<a id='comments'></a>";
  3037. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  3038. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  3039. $output .= "</table>";
  3040. print " <script type='text/javascript'>
  3041. //<![CDATA[
  3042. function submit_comment(url) {
  3043. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  3044. var formData = new FormData();
  3045. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  3046. var request = new XMLHttpRequest();
  3047. request.open('POST', url);
  3048. document.getElementById('comments_history').innerHTML = '';
  3049. request.onload = function (e) {
  3050. if (request.readyState === 4) {
  3051. if (request.status === 200) {
  3052. document.getElementById('comments_history').innerHTML = request.responseText;
  3053. document.getElementById('check-message-success').style.visibility = 'visible';
  3054. setTimeout(function(){
  3055. document.getElementById('check-message-success').style.visibility = 'hidden';
  3056. }, 3000);
  3057. }
  3058. }
  3059. };
  3060. document.formEnvioComment.submission_comment.value = '';
  3061. request.send(formData);
  3062. }
  3063. function event_text_area (event) {
  3064. if (event.ctrlKey && event.keyCode == 13)
  3065. submit_comment('" . $enderecoPOSTcomment . "');
  3066. }
  3067. //]]>
  3068. </script>";
  3069. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  3070. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
  3071. $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";
  3072. $output .= "</form> </center>\n";
  3073. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  3074. // }
  3075. $output .= $OUTPUT->box_end();
  3076. print $output;
  3077. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3078. // final block 'studant'
  3079. print $OUTPUT->footer();
  3080. die();
  3081. } // function view_iassign_current()
  3082. /// Export the data from performance report into CSV file format
  3083. function export_csv () {
  3084. global $USER, $CFG, $DB, $OUTPUT;
  3085. $str = "";
  3086. $fields = "student_id, student_name";
  3087. // Finding all iassign activities for the iassign:
  3088. $id = $this->cm->id;
  3089. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3090. $c = 1;
  3091. foreach ($iassign_list as $iassign) {
  3092. $fields .= ", activity_id_" . $c . ", activity_name_" . $c . ", total_submissions_activity_" . $c . ", grade_activity_" . $c . ""
  3093. . ", status_activity_" . $c . ", ilm_id_activity_" . $c . ", ilm_name_activity_" . $c;
  3094. $c++;
  3095. }
  3096. // Finding enrolled students:
  3097. $params_temp = array('shortname' => 'student');
  3098. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  3099. $context = context_course::instance($this->course->id);
  3100. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3101. $students = $DB->get_records_sql(
  3102. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3103. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3104. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3105. foreach ($students as $student) {
  3106. $str .= $student->userid . ',';
  3107. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  3108. foreach ($iassign_list as $iassign) {
  3109. $str .= ',' . $iassign->id . ',';
  3110. $str .= '"' . $iassign->name . '",';
  3111. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  3112. if ($student_submissions) {
  3113. $str .= $student_submissions->experiment . ',';
  3114. $str .= $student_submissions->grade . ',';
  3115. switch ($student_submissions->status) {
  3116. case 3:
  3117. $str .= '"correct",';
  3118. break;
  3119. case 2:
  3120. $str .= '"incorrect",';
  3121. break;
  3122. case 1:
  3123. $str .= '"post",';
  3124. break;
  3125. case 0:
  3126. $str .= '"not_post",';
  3127. break;
  3128. }
  3129. }
  3130. else {
  3131. $str .= ',,"not_post",';
  3132. }
  3133. $str .= $iassign->iassign_ilmid . ',';
  3134. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  3135. $str .= '"' . $ilm_activity->name . '"';
  3136. }
  3137. $str .= "\n";
  3138. }
  3139. $str = $fields . "\n" . $str;
  3140. header("Content-type: text/csv");
  3141. header("Content-disposition: attachment; filename=report.csv");
  3142. header("Pragma: no-cache");
  3143. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  3144. header('Content-Length: ' . strlen($str));
  3145. header('Connection: close');
  3146. print $str;
  3147. flush();
  3148. } // function export_csv()
  3149. /// Display report of performance
  3150. function report () {
  3151. global $USER, $CFG, $DB, $OUTPUT;
  3152. $id = $this->cm->id;
  3153. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3154. if ($this->action != 'print') {
  3155. $title = get_string('report', 'iassign');
  3156. print $OUTPUT->header();
  3157. } // if ($this->action != 'print')
  3158. $this->print_main_menu();
  3159. print $OUTPUT->box_start();
  3160. $this->view_legend_icons();
  3161. print $OUTPUT->box_end();
  3162. if ($this->action == 'print')
  3163. print '<table border=1 width="100%">' . "\n";
  3164. else
  3165. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
  3166. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3167. // $num = array();
  3168. $i = 1;
  3169. $num = array();
  3170. $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;";
  3171. foreach ($iassign_list as $iassign) { // for all exercise in this block
  3172. $test_exercise = "";
  3173. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3174. if (($iassign_submission) && $iassign->type_iassign < 3) {
  3175. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  3176. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  3177. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  3178. $num[$i] = new stdClass();
  3179. $num[$i]->name = $iassign->name;
  3180. $num[$i]->id = $i;
  3181. $num[$i]->iassignid = $iassign->id;
  3182. print ' <tr >' . "\n";
  3183. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  3184. print "<td class=\"cell c0 actvity\">";
  3185. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  3186. print ' </tr>' . "\n";
  3187. $i++;
  3188. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  3189. } // foreach ($iassign_list as $iassign)
  3190. $num_exerc = $i; // total of exercises
  3191. print "</table>";
  3192. print "<p></p>";
  3193. if ($this->action == 'print')
  3194. print '<table border=1 width="100%">' . "\n";
  3195. else // ./theme/boost/style/moodle.css: .generaltable
  3196. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  3197. $context = context_course::instance($this->course->id);
  3198. if ($num_exerc > 1) {
  3199. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3200. $params_temp = array('shortname' => 'student');
  3201. $role = $DB->get_record_sql(
  3202. "SELECT s.id, s.shortname FROM {role} s " .
  3203. " WHERE s.shortname = :shortname", $params_temp);
  3204. // $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");
  3205. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3206. $students = $DB->get_records_sql(
  3207. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3208. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3209. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3210. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  3211. $width = 90/$num_exerc;
  3212. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  3213. $sum_iassign_correct[$j] = 0;
  3214. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  3215. }
  3216. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  3217. $sum_iassign = $j - 1;
  3218. print '</tr>' . "\n";
  3219. $total = 0;
  3220. $sum_student = 0;
  3221. $comment = iassign_icons::insert('comment_read');
  3222. $sum_comment = 0;
  3223. $sum_correct_iassign = array();
  3224. $sum_correct_student = array();
  3225. $USER->matrix_iassign = array();
  3226. if ($students) {
  3227. $w = 0;
  3228. foreach ($students as $tmp) { // count students
  3229. $users_array[$w] = $tmp;
  3230. $w++;
  3231. }
  3232. for ($x=0; $x<$w; $x++) { // for all students
  3233. print '<tr>' . "\n";
  3234. $sum_student++;
  3235. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  3236. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  3237. $total_student = 0;
  3238. $tentativas = 0;
  3239. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  3240. $sum_comment = $sum_verify_message = 0;
  3241. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  3242. if ($student_submissions) {
  3243. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  3244. $tentativas = $student_submissions->experiment;
  3245. // Get student comments
  3246. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  3247. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  3248. $student_submissions_comment = $DB->get_record_sql(
  3249. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3250. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  3251. if ($student_submissions_comment) // student has comment
  3252. foreach ($student_submissions_comment as $tmp)
  3253. $sum_comment = $tmp;
  3254. // informations to previous activities
  3255. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  3256. else $iassign_previous = $num[$j - 1]->iassignid;
  3257. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3258. else $user_previous = $users_array[$x - 1]->userid;
  3259. // next
  3260. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3261. else $iassign_next = "-1";
  3262. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3263. else $user_next = "-1";
  3264. $position = "&row= $x&column=$j";
  3265. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  3266. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3267. $url .= $position;
  3268. // receiver=1 - message to teacher
  3269. // receiver=2 - message to student
  3270. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  3271. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  3272. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  3273. $verify_message = $DB->get_record_sql(
  3274. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3275. "WHERE iassign_submissionid = :iassign_submissionid " .
  3276. " AND return_status= :return_status " .
  3277. " AND receiver= :receiver", $params_temp);
  3278. if ($verify_message)
  3279. foreach ($verify_message as $tmp)
  3280. $sum_verify_message = $tmp;
  3281. if ($sum_verify_message > 0)
  3282. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  3283. else
  3284. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  3285. if ($student_submissions->status == 3) {
  3286. $sum_iassign_correct[$j]++;
  3287. $total_student++;
  3288. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  3289. }
  3290. elseif ($student_submissions->status == 2) {
  3291. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  3292. }
  3293. elseif ($student_submissions->status == 1) {
  3294. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3295. }
  3296. elseif ($student_submissions->status == 0) {
  3297. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3298. }
  3299. if ($this->action != 'print') {
  3300. if ($tentativas > 0)
  3301. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3302. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3303. . $feedback
  3304. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3305. . $tentativas
  3306. . '</span> </button>'
  3307. . '</a>' . "\n";
  3308. else
  3309. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3310. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3311. . $feedback
  3312. .'</button>'
  3313. . '</a>' . "\n";
  3314. if ($sum_comment > 0 && $sum_verify_message > 0)
  3315. print '<a href="' . $url . '"> '
  3316. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3317. . $comment
  3318. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3319. . $sum_verify_message . '/' . $sum_comment
  3320. . '</span> </button>'
  3321. . '</a>';
  3322. else if ($sum_comment > 0)
  3323. print '<a href="' . $url . '"> '
  3324. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  3325. . $comment
  3326. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3327. . $sum_comment
  3328. . '</span> </button>'
  3329. . '</a>';
  3330. print '</td>' . "\n";
  3331. }
  3332. if ($this->action == 'print')
  3333. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3334. } // if ($student_submissions)
  3335. else { // if ($student_submissions)
  3336. // Student does not have any submission
  3337. // informations to browse previous activities
  3338. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3339. else $iassign_previous = $num[$j - 1]->iassignid;
  3340. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3341. else $user_previous = $users_array[$x - 1]->userid;
  3342. // next
  3343. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3344. else $iassign_next = "-1";
  3345. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3346. else $user_next = "-1";
  3347. $position = "&row= $x&column=$j";
  3348. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3349. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3350. $url .= $position;
  3351. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3352. if ($this->action == 'print')
  3353. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3354. else {
  3355. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3356. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3357. . $feedback
  3358. .'</button>'
  3359. . '</a>' . "\n";
  3360. // print '<td> &nbsp;</td>';
  3361. if ($sum_comment > 0)
  3362. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3363. // else print '<td> &nbsp;</td>';
  3364. print '</td>';
  3365. }
  3366. } // else if ($student_submissions)
  3367. $USER->matrix_iassign[$x][$j] = new stdClass();
  3368. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3369. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3370. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3371. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3372. if ($student_submissions)
  3373. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3374. else
  3375. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3376. //print '</td>' . "\n";
  3377. } // for ($j=1; $j<$num_exerc; $j++)
  3378. $total = $total + $total_student;
  3379. $porcentagem = ($total_student / ($j - 1)) * 100;
  3380. if ($tentativas != 0 && $tentativas != null) {
  3381. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3382. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3383. }
  3384. else {
  3385. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3386. }
  3387. print '</tr>' . "\n";
  3388. $sum_correct_student[$sum_student] = new stdClass();
  3389. $sum_correct_student[$sum_student]->name = $name;
  3390. $sum_correct_student[$sum_student]->sum = $total_student;
  3391. } // for ($x = 0; $x < $w; $x++)
  3392. for ($i = 1; $i < $j; $i++) {
  3393. if (is_null($sum_iassign_correct[$i]))
  3394. $sum_iassign_correct[$i] = 0;
  3395. $sum_correct_iassign[$i] = new stdClass();
  3396. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3397. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3398. }
  3399. // print '</tr></table>' . "\n";
  3400. }
  3401. } // if ($i>1)
  3402. else {
  3403. print_string('no_activity', 'iassign');
  3404. }
  3405. print "</table>\n";
  3406. print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . "</p>\n"; // the number of atemps is...
  3407. print '<p>' . get_string('ps_comment', 'iassign') . "</p>\n"; // the total number of messages is...
  3408. if ($this->action != 'print')
  3409. print $OUTPUT->footer();
  3410. die();
  3411. } // function report()
  3412. /// Display graphics of performance
  3413. function stats () {
  3414. global $USER, $CFG, $DB, $OUTPUT;
  3415. $id = $this->cm->id;
  3416. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3417. if ($this->action != 'printstats')
  3418. $title = get_string('graphic', 'iassign');
  3419. $num = array();
  3420. $sum_correct_iassign = array();
  3421. $sum_correct_student = array();
  3422. $sum_student = 0;
  3423. $i = 1;
  3424. foreach ($iassign_list as $iassign) {
  3425. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3426. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3427. $sum_iassign_correct[$i] = 0;
  3428. $num[$i] = new stdClass();
  3429. $num[$i]->name = $iassign->name;
  3430. $num[$i]->id = $i;
  3431. $num[$i]->iassignid = $iassign->id;
  3432. $i++;
  3433. } // if ($iassign->type_iassign == 3)
  3434. } // foreach ($iassign_list as $iassign)
  3435. $sum_iassign = $i - 1;
  3436. $context = context_course::instance($this->course->id);
  3437. if ($i > 1) {
  3438. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3439. $params_temp = array('shortname' => 'student');
  3440. $role = $DB->get_record_sql(
  3441. "SELECT s.id, s.shortname FROM {role} s " .
  3442. " WHERE s.shortname = :shortname", $params_temp);
  3443. // $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");
  3444. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3445. $students = $DB->get_records_sql(
  3446. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3447. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3448. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3449. $total = 0;
  3450. $sum_student = 0;
  3451. $j = 0;
  3452. $sum_correct_iassign = array();
  3453. $sum_correct_student = array();
  3454. $sum_experiment = array();
  3455. if ($students) {
  3456. foreach ($students as $users) {
  3457. $sum_student++;
  3458. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3459. // rows
  3460. $total_student = 0;
  3461. for ($j = 1; $j < $i; $j++) {
  3462. $total_experiment = 0;
  3463. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3464. if ($student_submissions) {
  3465. if ($student_submissions->status == 3) {
  3466. $sum_iassign_correct[$j]++;
  3467. $total_student++;
  3468. } // if ($student_submissions->status == 3)
  3469. $total_experiment += $student_submissions->experiment;
  3470. }
  3471. $sum_experiment[$j] = $total_experiment;
  3472. } // for ($j=1; $j<$i; $j++)
  3473. $total = $total + $total_student;
  3474. $sum_correct_student[$sum_student] = new stdClass();
  3475. $sum_correct_student[$sum_student]->name = $name;
  3476. $sum_correct_student[$sum_student]->sum = $total_student;
  3477. } // foreach ($students as $users)
  3478. }
  3479. for ($i = 1; $i < $j; $i++) {
  3480. if (is_null($sum_iassign_correct[$i]))
  3481. $sum_iassign_correct[$i] = 0;
  3482. $sum_correct_iassign[$i] = new stdClass();
  3483. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3484. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3485. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3486. } // for ($i = 1; $i < $j; $i++)
  3487. } // if ($i > 1)
  3488. print $OUTPUT->header();
  3489. $this->print_main_menu();
  3490. if ($this->action != 'printstats') {
  3491. $title = get_string('graphic', 'iassign');
  3492. $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>";
  3493. $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>";
  3494. print '<table width=100%><tr>';
  3495. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3496. print '<td width=15% align="right">' . $link_report . '</td>';
  3497. print '</td></tr></table>' . "\n";
  3498. print "<br><br>";
  3499. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3500. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3501. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3502. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3503. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3504. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3505. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3506. print '</tr>' . "\n";
  3507. $sum_correct = 0;
  3508. if ($sum_correct_iassign) {
  3509. foreach ($sum_correct_iassign as $iassign) {
  3510. if (is_null($iassign->experiment))
  3511. $iassign->experiment = 0;
  3512. $bar = "";
  3513. $sum = $iassign->sum;
  3514. $percent = ($sum / $sum_student) * 100;
  3515. $text = number_format($percent, 1) . '%';
  3516. $sum_correct += $sum;
  3517. if ($sum > 0) {
  3518. for ($i = 1; $i < $percent * 2; $i++)
  3519. $bar .= iassign_icons::insert('hbar_blue');
  3520. $bar .= iassign_icons::insert('hbar_blue_r');
  3521. } // if ($sum > 0)
  3522. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3523. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3524. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3525. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3526. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3527. print '</tr>' . "\n";
  3528. } // foreach ($sum_correct_iassign as $iassign)
  3529. }
  3530. print "</table>";
  3531. print "<br><br>";
  3532. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3533. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3534. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3535. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3536. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3537. print '</tr>' . "\n";
  3538. $sum_correct = 0;
  3539. foreach ($sum_correct_student as $student) {
  3540. $bar = "";
  3541. $sum = $student->sum;
  3542. $percent = ($sum / $sum_iassign) * 100;
  3543. $text = number_format($percent, 1) . '%';
  3544. $sum_correct += $sum;
  3545. if ($sum > 0) {
  3546. for ($i = 1; $i < $percent * 2; $i++)
  3547. $bar .= iassign_icons::insert('hbar_blue');
  3548. $bar .= iassign_icons::insert('hbar_blue_r');
  3549. } // if ($sum > 0)
  3550. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3551. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3552. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3553. print '</tr>' . "\n";
  3554. } // foreach ($sum_correct_student as $student)
  3555. print "</table>\n";
  3556. print "<br><br>\n";
  3557. $var = 0;
  3558. $cv = 0;
  3559. $dv = 0;
  3560. $avg = 0;
  3561. if ($sum_correct_student) {
  3562. $avg = $sum_correct / $sum_student;
  3563. if ($avg > 0) {
  3564. foreach ($sum_correct_student as $student)
  3565. $var += pow($student->sum - $avg, 2);
  3566. $var = $var / $sum_student;
  3567. $dv = sqrt($var);
  3568. $cv = ($dv / $avg) * 100;
  3569. }
  3570. }
  3571. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3572. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3573. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3574. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3575. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3576. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3577. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3578. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3579. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3580. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3581. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3582. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3583. print "</table>\n";
  3584. print $OUTPUT->footer();
  3585. } else {
  3586. print "<STYLE TYPE='text/css'>
  3587. <!--
  3588. .boldtable {
  3589. font-family:sans-serif;
  3590. font-size:10pt;
  3591. }
  3592. -->
  3593. </STYLE>\n";
  3594. print '<table border=1 width=100%>' . "\n";
  3595. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3596. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3597. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3598. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3599. print '</tr>' . "\n";
  3600. $sum_correct = 0;
  3601. foreach ($sum_correct_iassign as $iassign) {
  3602. $bar = "";
  3603. $sum = $iassign->sum;
  3604. $percent = ($sum / $sum_student) * 100;
  3605. $text = number_format($percent, 1) . '%';
  3606. $sum_correct += $sum;
  3607. if ($sum > 0) {
  3608. for ($i = 1; $i < $percent * 2; $i++)
  3609. $bar .= iassign_icons::insert('hbar_blue');
  3610. $bar .= iassign_icons::insert('hbar_blue_r');
  3611. } // if ($sum > 0)
  3612. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3613. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3614. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3615. print '</tr>' . "\n";
  3616. } // foreach ($sum_correct_iassign as $iassign)
  3617. print "</table>";
  3618. print "<br><br>";
  3619. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3620. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3621. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3622. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3623. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3624. print '</tr>' . "\n";
  3625. $sum_correct = 0;
  3626. foreach ($sum_correct_student as $student) {
  3627. $bar = "";
  3628. $sum = $student->sum;
  3629. $percent = ($sum / $sum_iassign) * 100;
  3630. $text = number_format($percent, 1) . '%';
  3631. $sum_correct += $sum;
  3632. if ($sum > 0) {
  3633. for ($i = 1; $i < $percent * 2; $i++)
  3634. $bar .= iassign_icons::insert('hbar_blue');
  3635. $bar .= iassign_icons::insert('hbar_blue_r');
  3636. } // if ($sum > 0)
  3637. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3638. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3639. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3640. print '</tr>' . "\n";
  3641. } // foreach ($sum_correct_student as $student)
  3642. print "</table>\n";
  3643. print "<br/><br/>\n";
  3644. $var = 0;
  3645. $cv = 0;
  3646. $dv = 0;
  3647. $avg = 0;
  3648. if ($sum_correct_student) {
  3649. $avg = $sum_correct / $sum_student;
  3650. if ($avg > 0) {
  3651. foreach ($sum_correct_student as $student)
  3652. $var += pow($student->sum - $avg, 2);
  3653. $var = $var / $sum_student;
  3654. $dv = sqrt($var);
  3655. $cv = ($dv / $avg) * 100;
  3656. }
  3657. }
  3658. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3659. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3660. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3661. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3662. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3663. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3664. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3665. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3666. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3667. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3668. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3669. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3670. print "</table>\n";
  3671. } // if ($this->action != 'printstats')
  3672. die();
  3673. }
  3674. /// Display graphics of performance for students
  3675. function stats_students () {
  3676. global $USER, $CFG, $DB, $OUTPUT;
  3677. $id = $this->cm->id;
  3678. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3679. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3680. $title = get_string('results', 'iassign');
  3681. $sum_correct = 0;
  3682. $sum_incorrect = 0;
  3683. $sum_post = 0;
  3684. $sum_nopost = 0;
  3685. $sum_iassign = count($iassign_statement_list);
  3686. $bar_nopost = "";
  3687. $bar_correct = "";
  3688. $bar_incorrect = "";
  3689. $bar_post = "";
  3690. $text_nopost = "";
  3691. $text_correct = "";
  3692. $text_incorrect = "";
  3693. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3694. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3695. if ($iassign_submission) {
  3696. if ($iassign_submission->status == 3)
  3697. $sum_correct++;
  3698. elseif ($iassign_submission->status == 2)
  3699. $sum_incorrect++;
  3700. elseif ($iassign_submission->status == 1)
  3701. $sum_post++;
  3702. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3703. $sum_nopost++;
  3704. } // if ($iassign_submission)
  3705. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3706. if ($sum_iassign > 0) {
  3707. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3708. $text_correct = number_format($percent_correct, 1) . '%';
  3709. }
  3710. if ($sum_correct > 0) {
  3711. for ($i = 1; $i < $percent_correct * 2; $i++)
  3712. $bar_correct .= iassign_icons::insert('hbar_green');
  3713. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3714. } // if ($sum_correct > 0)
  3715. if ($sum_iassign > 0) {
  3716. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3717. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3718. }
  3719. if ($sum_incorrect > 0) {
  3720. for ($i = 1; $i < $percent_incorrect * 2; $i++)
  3721. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3722. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3723. } // if ($sum_incorrect > 0)
  3724. if ($sum_iassign > 0) {
  3725. $percent_post = ($sum_post / $sum_iassign) * 100;
  3726. $text_post = number_format($percent_post, 1) . '%';
  3727. }
  3728. if ($sum_post > 0) {
  3729. for ($i = 1; $i < $percent_post * 2; $i++)
  3730. $bar_post .= iassign_icons::insert('hbar_blue');
  3731. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3732. } // if ($sum_post > 0)
  3733. if ($sum_iassign > 0) {
  3734. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3735. $text_nopost = number_format($percent_nopost, 1) . '%';
  3736. }
  3737. if ($sum_nopost > 0) {
  3738. for ($i = 1; $i < $percent_nopost * 2; $i++)
  3739. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3740. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3741. } // if ($sum_nopost > 0)
  3742. print $OUTPUT->header();
  3743. $this->print_main_menu();
  3744. //2021/12 $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3745. //2021/12 print '<table width=100%><tr>';
  3746. //2021/12 print '<td align="right">' . $link_return . '</td>' . "\n";
  3747. //2021/12 print '</td></tr></table>' . "\n";
  3748. print "<br/><br/>\n";
  3749. print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
  3750. print '<tr><th colspan=3 class="header c1">' . "\n";
  3751. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3752. // $imagetext = '');
  3753. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3754. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3755. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3756. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3757. print '</tr>' . "\n";
  3758. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3759. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3760. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3761. print '</tr>' . "\n";
  3762. if ($sum_post) {
  3763. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3764. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3765. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3766. print '</tr>' . "\n";
  3767. } // if ($sum_post)
  3768. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3769. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3770. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3771. print '</tr>' . "\n";
  3772. print "</table>";
  3773. print "<br><br>";
  3774. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3775. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3776. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3777. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3778. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3779. $sum_grade = 0;
  3780. $sum_grade_student = 0;
  3781. $avg = 0;
  3782. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3783. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3784. if (!$iassign_submission) {
  3785. $iassign_submission = new stdClass();
  3786. $iassign_submission->grade = 0;
  3787. }
  3788. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3789. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3790. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3791. print '</tr>' . "\n";
  3792. $sum_grade += $iassign_statement_activity_item->grade;
  3793. $sum_grade_student += $iassign_submission->grade;
  3794. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3795. if ($sum_grade > 0)
  3796. $avg = $sum_grade_student / $sum_grade * 100;
  3797. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3798. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3799. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3800. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3801. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3802. print "</table>";
  3803. print $OUTPUT->footer();
  3804. die();
  3805. } // function stats_students()
  3806. function get_total_notifications () {
  3807. global $DB, $USER, $COURSE;
  3808. $total_messages = 0;
  3809. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3810. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3811. $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 "
  3812. . " 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);
  3813. }
  3814. else {
  3815. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3816. $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 "
  3817. . " 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);
  3818. }
  3819. return $total_messages->total;
  3820. }
  3821. function get_iassign_statement_messages () {
  3822. global $DB, $USER, $COURSE;
  3823. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3824. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3825. $totais = array();
  3826. $messages = $DB->get_records_sql("SELECT c.id AS commentid, st.id AS stid, s.userid AS user, ias.id AS iasid, s.id AS subid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3827. . " 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);
  3828. foreach($messages as $item) {
  3829. if (isset($totais[$item->subid])) {
  3830. $totais[$item->subid]->total++;
  3831. }
  3832. else {
  3833. $totais[$item->subid] = new stdclass();
  3834. $item->total = 1;
  3835. $totais[$item->subid] = $item;
  3836. }
  3837. }
  3838. return $totais;
  3839. }
  3840. else {
  3841. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3842. $totais = array();
  3843. $messages = $DB->get_records_sql("SELECT c.id as commentid, s.id AS subid, st.id AS stid, ias.id AS iasid, s.userid AS userid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3844. . " 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);
  3845. foreach($messages as $item) {
  3846. if (isset($totais[$item->subid])) {
  3847. $totais[$item->subid]->total++;
  3848. }
  3849. else {
  3850. $totais[$item->subid] = new stdclass();
  3851. $item->total = 1;
  3852. $totais[$item->subid] = $item;
  3853. }
  3854. }
  3855. return $totais;
  3856. }
  3857. }
  3858. function view_notifications_teachers () {
  3859. global $OUTPUT, $USER, $DB;
  3860. $messages = $this->get_iassign_statement_messages();
  3861. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3862. // 1º. listar as mensagens recebidas no bloco atual:
  3863. $actual_block = $this->iassign->id;
  3864. $id = $this->cm->id;
  3865. $total_include = 0;
  3866. $activities_actual_block = array();
  3867. if ($messages)
  3868. foreach ($messages as $item)
  3869. if ($item->iasid == $actual_block)
  3870. if (!in_array($item->stid, $activities_actual_block))
  3871. array_push($activities_actual_block, $item->stid);
  3872. if ($activities_actual_block)
  3873. foreach ($activities_actual_block as $activity_id) {
  3874. $printed = false;
  3875. foreach ($messages as $item) {
  3876. if ($item->stid == $activity_id) {
  3877. if (!$printed) {
  3878. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
  3879. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3880. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3881. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3882. $printed = true;
  3883. }
  3884. $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
  3885. $user = $DB->get_record('user', array('id' => $item->user));
  3886. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3887. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3888. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3889. '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td>'
  3890. .'</tr>';
  3891. $total_include++;
  3892. }
  3893. }
  3894. print '</td></tr></table>';
  3895. }
  3896. print '</table>';
  3897. if (count($activities_actual_block) == 0) {
  3898. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3899. print '<hr class="my-4">';
  3900. }
  3901. if ($messages && $total_include == count($messages)) {
  3902. print $OUTPUT->footer();
  3903. return;
  3904. }
  3905. print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
  3906. $iassign_ids = array();
  3907. if ($messages)
  3908. foreach ($messages as $item)
  3909. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3910. array_push($iassign_ids, $item->iasid);
  3911. foreach ($iassign_ids as $id_iassign) {
  3912. $printed = false;
  3913. $activities_in_block = array();
  3914. foreach ($messages as $subitem)
  3915. if ($subitem->iasid == $id_iassign)
  3916. if (!in_array($item->stid, $activities_in_block))
  3917. array_push($activities_in_block, $item->stid);
  3918. foreach ($messages as $item) {
  3919. if ($item->iasid == $id_iassign) {
  3920. if (!$printed) {
  3921. $printed = true;
  3922. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3923. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3924. }
  3925. foreach ($activities_in_block as $id_activity) {
  3926. $print = false;
  3927. foreach ($messages as $subitem) {
  3928. if ($subitem->stid == $id_activity) {
  3929. if (!$print) {
  3930. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
  3931. $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
  3932. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3933. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3934. $print = true;
  3935. }
  3936. foreach ($messages as $comment_student) {
  3937. if ($comment_student->stid == $id_activity) {
  3938. $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
  3939. $user = $DB->get_record('user', array('id' => $comment_student->user));
  3940. $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3941. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3942. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3943. '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$comment_student->total.'</span> </span></a></td>'
  3944. .'</tr>';
  3945. }
  3946. }
  3947. break;
  3948. }
  3949. }
  3950. }
  3951. print '</table></td></tr></table>';
  3952. break;
  3953. }
  3954. }
  3955. }
  3956. print $OUTPUT->footer();
  3957. }
  3958. function view_notifications () {
  3959. global $OUTPUT, $USER;
  3960. print $OUTPUT->header();
  3961. $this->print_main_menu();
  3962. print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
  3963. if ($this->get_total_notifications() == 0) {
  3964. print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
  3965. print '<hr class="my-4">';
  3966. print $OUTPUT->footer();
  3967. return;
  3968. }
  3969. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3970. $this->view_notifications_teachers();
  3971. return;
  3972. }
  3973. $messages = $this->get_iassign_statement_messages();
  3974. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3975. // 1º. listar as mensagens recebidas no bloco atual:
  3976. $actual_block = $this->iassign->id;
  3977. $id = $this->cm->id;
  3978. $total_include = 0;
  3979. if ($messages)
  3980. foreach ($messages as $item) {
  3981. if ($item->iasid == $actual_block) {
  3982. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3983. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3984. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3985. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td></tr>';
  3986. $total_include++;
  3987. }
  3988. }
  3989. print '</table>';
  3990. if ($total_include == 0) {
  3991. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3992. print '<hr class="my-4">';
  3993. }
  3994. if ($messages && $total_include == count($messages)) {
  3995. print $OUTPUT->footer();
  3996. return;
  3997. }
  3998. print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
  3999. // 2º. listar as mensagens recebidas nos demais blocos do curso:
  4000. $iassign_ids = array();
  4001. if ($messages)
  4002. foreach ($messages as $item)
  4003. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  4004. array_push($iassign_ids, $item->iasid);
  4005. foreach ($iassign_ids as $id_iassign) {
  4006. $printed = false;
  4007. foreach ($messages as $item) {
  4008. if ($item->iasid == $id_iassign) {
  4009. if (!$printed) {
  4010. $printed = true;
  4011. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  4012. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  4013. }
  4014. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  4015. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  4016. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  4017. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a> </td></tr>';
  4018. }
  4019. }
  4020. print '</table>';
  4021. }
  4022. print $OUTPUT->footer();
  4023. }
  4024. function print_main_menu () {
  4025. global $USER;
  4026. $id = $this->cm->id;
  4027. $actual_action = optional_param('action', '', PARAM_TEXT);
  4028. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  4029. $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
  4030. $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
  4031. $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
  4032. $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
  4033. $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
  4034. $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
  4035. $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
  4036. $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
  4037. $url_import_activity = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'import_activity', 'iassignid' => $this->iassign->id));
  4038. print '<div class="btn-group" role="group" aria-label="">';
  4039. print '<a href="' . $url_home . '" class="btn btn-outline-primary ' . ($actual_action == '' ? 'active' : '') . '">' . "\n";
  4040. print ' <i class="fa fa-home" aria-hidden="true"></i> ' . get_string('activities_page', 'iassign') . "</a>\n";
  4041. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4042. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  4043. // Has capability to see "report": teacher or up
  4044. 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>';
  4045. print '<div class="btn-group"><div class="btn-group">
  4046. <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">
  4047. <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
  4048. <div class="dropdown-menu">
  4049. <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>
  4050. <div class="dropdown-divider"></div>
  4051. <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>
  4052. <div class="dropdown-divider"></div>
  4053. <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>
  4054. </div>
  4055. </div>
  4056. '; // "
  4057. 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>';
  4058. 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>';
  4059. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4060. $notifications = $this->get_total_notifications();
  4061. print '<a href="' . $url_notifications . '" class="btn btn-outline-primary ' . ($actual_action == 'notifications' ? 'active' : '') . '">' . "\n"; // '
  4062. print ' <i class="fa fa-bell" aria-hidden="true"></i> ' . get_string('notifications', 'iassign');
  4063. if ($notifications > 0)
  4064. print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
  4065. print '</a></div><div class="btn-group">';
  4066. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  4067. print '<a href="' . $url_add . '" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i> ' . get_string('add_iassign', 'iassign') . "</a>\n";
  4068. print '
  4069. <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  4070. </button>
  4071. <div class="dropdown-menu">
  4072. <a class="dropdown-item" href="' . $url_import_activity . '">' . get_string('import_activity', 'iassign') . '</a>
  4073. </div>'; // "
  4074. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4075. print '</div></div>' . "\n";
  4076. }
  4077. /// Display page of iAssign's block of activities
  4078. function view_iassigns () {
  4079. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  4080. $id = $this->cm->id;
  4081. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  4082. $notice = optional_param('notice', '', PARAM_TEXT);
  4083. if (strpos($notice, 'error'))
  4084. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  4085. else if ($notice != '')
  4086. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  4087. $this->print_main_menu(); // teachers' menu: Page of activities; About iLM; Report; Results; Reevaluation; Notifications
  4088. print $OUTPUT->box_start();
  4089. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  4090. print '<div class="border float-right">' . "\n";
  4091. if ($iassign_list) {
  4092. // $USER->iassignEdit == 0 view 'Turn editing off'
  4093. // $USER->iassignEdit == 1 view 'Turn editing on'
  4094. if (!isset($USER->iassignEdit))
  4095. $USER->iassignEdit = 0;
  4096. if ($USER->iassignEdit == 0) {
  4097. $bottonEdit_message = get_string('turneditingon', 'iassign');
  4098. $botton = 1;
  4099. }
  4100. elseif ($USER->iassignEdit == 1) {
  4101. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  4102. $botton = 0;
  4103. }
  4104. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  4105. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  4106. print " <input class='btn btn-primary' type=submit value='" . $bottonEdit_message . "'/>\n";
  4107. print "</form>\n";
  4108. } // if ($iassign_list)
  4109. print "</div>\n";
  4110. }
  4111. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4112. // $this->view_legend_icons();
  4113. print $OUTPUT->box_end();
  4114. $iassign_array_exercise = array();
  4115. $i_exercise = 0; // count total number of activities of type 'exercise' inside the block
  4116. $iassign_array_test = array();
  4117. $i_test = 0; // count total number of activities of type 'test' inside the block
  4118. $iassign_array_example = array();
  4119. $i_example = 0; // count total number of activities of type 'example' inside the block
  4120. $iassign_array_general = array();
  4121. $i_general = 0;
  4122. if ($iassign_list) {
  4123. if ($this->iassign->activity_group == 0) {
  4124. foreach ($iassign_list as $iassign) {
  4125. $iassign_array_general[$i_general] = $iassign;
  4126. $i_general++;
  4127. }
  4128. } // if ($this->iassign->activity_group == 0)
  4129. else {
  4130. foreach ($iassign_list as $iassign) {
  4131. if ($iassign->type_iassign == 3) {
  4132. $iassign_array_exercise[$i_exercise] = $iassign;
  4133. $i_exercise++;
  4134. } // if ($iassign->type_iassign == 3)
  4135. if ($iassign->type_iassign == 2) {
  4136. $iassign_array_test[$i_test] = $iassign;
  4137. $i_test++;
  4138. } // if ($iassign->type_iassign == 2)
  4139. if ($iassign->type_iassign == 1) {
  4140. $iassign_array_example[$i_example] = $iassign;
  4141. $i_example++;
  4142. } // if ($iassign->type_iassign == 1)
  4143. }
  4144. }
  4145. if ($iassign_array_exercise) {
  4146. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  4147. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  4148. }
  4149. if ($iassign_array_test) {
  4150. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  4151. $this->show_iassign($title, $iassign_array_test, $i_test);
  4152. }
  4153. if ($iassign_array_example) {
  4154. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  4155. $this->show_iassign($title, $iassign_array_example, $i_example);
  4156. }
  4157. if ($iassign_array_general) {
  4158. $title = "";
  4159. $this->show_iassign($title, $iassign_array_general, $i_general);
  4160. }
  4161. } else { // if ($iassign_list)
  4162. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  4163. }
  4164. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  4165. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4166. print $OUTPUT->box_start();
  4167. print '<table width=100% border=0><tr>' . "\n";
  4168. print '<td width=10% align="left">' . "\n";
  4169. print $link_report;
  4170. print '</td>' . "\n";
  4171. print '</tr></table>' . "\n";
  4172. print $OUTPUT->box_end();
  4173. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4174. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  4175. print $OUTPUT->box_start();
  4176. print '<table width=100% border=0><tr>' . "\n";
  4177. print '<td align="left">' . "\n";
  4178. print $link_add;
  4179. print '</td>' . "\n";
  4180. print '</tr></table>' . "\n";
  4181. print $OUTPUT->box_end();
  4182. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4183. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  4184. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4185. // $this->view_legend_icons();
  4186. } // function view_iassigns()
  4187. /// Display all iAssigns: the list of activities inside the iAssign block
  4188. // HTTP: ./mod/iassign/view.php?id= <$id>
  4189. function show_iassign ($title, $iassign_array, $total_of_activities) {
  4190. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  4191. $id = $this->cm->id; // ID of iAssign block (accessed throgh table "couse_module")
  4192. print $OUTPUT->box_start();
  4193. print " <script type='text/javascript'>
  4194. //<![CDATA[
  4195. function validate_move () {
  4196. var radios = document.getElementsByName('iassign_destiny');
  4197. var formValid = false;
  4198. //alert('aqui validate_move()');
  4199. var i = 0;
  4200. while (!formValid && i < radios.length) {
  4201. if (radios[i].checked) formValid = true;
  4202. i++;
  4203. }
  4204. if (!formValid) {
  4205. document.getElementById('move_dest').classList.add('alert-danger');
  4206. }
  4207. return formValid;
  4208. }
  4209. var modal;
  4210. function load_move(id_ias) {
  4211. document.form_move_activity.iassign_current.value = id_ias;
  4212. modal.style.display = 'block';
  4213. var radios = document.getElementsByName('iassign_destiny');
  4214. var i = 0;
  4215. while (i < radios.length) {
  4216. radios[i].checked = false;
  4217. i++;
  4218. }
  4219. document.getElementById('move_dest').classList.remove('alert-danger');
  4220. }
  4221. function closeModal () {
  4222. modal.style.display = 'none';
  4223. }
  4224. function load_modal_elements () {
  4225. modal = document.getElementById('myModal');
  4226. var span = document.getElementById('close_modal');
  4227. span.onclick = function() {
  4228. modal.style.display = 'none';
  4229. }
  4230. window.onclick = function(event) {
  4231. if (event.target == modal) {
  4232. modal.style.display = 'none';
  4233. }
  4234. }
  4235. }
  4236. window.onload = load_modal_elements;
  4237. //]]>
  4238. </script>\n";
  4239. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  4240. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  4241. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  4242. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  4243. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  4244. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  4245. <input type='hidden' name='iassign_current' value='' />";
  4246. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  4247. $section = $course_sections[0];
  4248. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  4249. for ($k = 0; $k < count($ids_sections); $k++) {
  4250. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  4251. for ($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  4252. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  4253. if ($c_cm) {
  4254. if ($ccm->instance == $c_cm->instance) {
  4255. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4256. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4257. }
  4258. else {
  4259. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4260. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4261. }
  4262. }
  4263. }
  4264. $radio_buttons .= "</ul>";
  4265. }
  4266. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  4267. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
  4268. </form>
  4269. </div></div> </div></div>\n";
  4270. print " <style>.modal {
  4271. display: none;
  4272. position: fixed;
  4273. z-index: 1;
  4274. left: 0;
  4275. top: 0;
  4276. width: 100%;
  4277. height: 100%;
  4278. overflow: scroll;
  4279. background-color: rgb(0,0,0);
  4280. background-color: rgba(0,0,0,0.4);
  4281. }
  4282. .modal-content {
  4283. background-color: #fefefe;
  4284. margin: 15% auto;
  4285. padding: 10px 10px;
  4286. border: 1px solid #888;
  4287. width: 50%;
  4288. }
  4289. #close_modal {
  4290. color: #aaa;
  4291. float: right;
  4292. font-size: 28px;
  4293. font-weight: bold;
  4294. margin-top: -15px;
  4295. margin-right: -3px;
  4296. }
  4297. #close_modal:hover,
  4298. #close_modal:focus {
  4299. color: black;
  4300. text-decoration: none;
  4301. cursor: pointer;
  4302. }
  4303. #modal_title {
  4304. min-height: 3rem;
  4305. color: initial;
  4306. background: initial;
  4307. font-size: 1.5rem;
  4308. line-height: 1.5;
  4309. padding: 15px;
  4310. border-bottom: 1px solid #e5e5e5;
  4311. }
  4312. .input_move {
  4313. width: 90%;
  4314. padding: 2px;
  4315. }
  4316. .input_move:hover {
  4317. background: #eff0ef;
  4318. }
  4319. </style>";
  4320. $action_links = "";
  4321. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4322. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4323. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4324. for ($j=0; $j<$total_of_activities; $j++) {
  4325. $iassign_current = $iassign_array[$j]->id;
  4326. // receiver=1 - message to teacher
  4327. // receiver=2 - message to student
  4328. $sum_comment = 0;
  4329. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  4330. foreach ($iassign_submissions as $iassign_submission) {
  4331. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  4332. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4333. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4334. if ($verify_message)
  4335. foreach ($verify_message as $tmp)
  4336. $sum_comment += $tmp;
  4337. } // foreach ($iassign_submissions as $iassign_submission)
  4338. if ($sum_comment == 0)
  4339. $comment_unread = "";
  4340. else {
  4341. $comment_unread_message = get_string('comment_unread', 'iassign');
  4342. if ($sum_comment == 1)
  4343. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4344. $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '">' .
  4345. ' <span class="badge bg-danger ml-2" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message .
  4346. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . '</span> </span></a>' . "\n";
  4347. }
  4348. if ($j == $total_of_activities - 1)
  4349. $iassign_down = $iassign_array[$j]->id;
  4350. else
  4351. $iassign_down = $iassign_array[$j + 1]->id;
  4352. if ($j > 0)
  4353. $iassign_up = $iassign_array[$j - 1]->id;
  4354. else
  4355. $iassign_up = $iassign_array[$j]->id;
  4356. if ($iassign_array[$j]->visible == 0)
  4357. $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>\n";
  4358. else
  4359. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4360. $links .= $comment_unread;
  4361. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  4362. $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>\n";
  4363. $str_aux = "&id=" . $id . "&iassign_current=" . $iassign_current . "&iassign_up=" . $iassign_up . "&iassign_down=" . $iassign_down;
  4364. $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>\n";
  4365. if ($j==0) // first activity
  4366. $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>\n";
  4367. else
  4368. $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>\n";
  4369. $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>\n";
  4370. $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>\n";
  4371. $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>\n";
  4372. $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>\n";
  4373. $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>\n";
  4374. $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>\n";
  4375. if (count($iassign_array) > 1) {
  4376. if ($j == 0)
  4377. $action_links .= $link_down;
  4378. elseif ($j == $total_of_activities - 1)
  4379. $action_links .= $link_up;
  4380. else
  4381. $action_links .= $link_up . $link_down;
  4382. } // if (count($iassign_array) > 1)
  4383. $action_links .= $link_edit . $link_delete;
  4384. if ($iassign_array[$j]->visible == 0)
  4385. $action_links .= $link_visible_show;
  4386. else
  4387. $action_links .= $link_visible_hide;
  4388. $action_links .= $link_duplicate_activity . $link_move_activity;
  4389. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4390. $action_links .= "</ul></nav>\n";
  4391. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle">' . $action_links . "</td></tr>\n";
  4392. } // for ($j=0; $j<$total_of_activities; $j++)
  4393. //D echo "locallib.php: show_iassign():<br/>";
  4394. //EXTRA: This for is to correct error in ordem inside the block, to detect (and fix it) 'iassign_statement.position' errors
  4395. $vector_final_order = array(); // get the final order to be used to correct existent one
  4396. for ($j=0; $j<$total_of_activities; $j++) { // List all iAssign activity inside this block
  4397. //D echo $j . ": id=" . $iassign_array[$j]->id . ", position=" . $iassign_array[$j]->position . "<br/>";
  4398. if ($iassign_array[$j]->position!=($j+1)) {
  4399. activity::move_change_activity_position($DB, $iassign_array[$j]->id, $iassign_array[$j]->id, $j+1, $j+1);
  4400. }
  4401. }
  4402. print "</tbody></table>\n";
  4403. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4404. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  4405. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4406. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4407. for ($j=0; $j<$total_of_activities; $j++) {
  4408. $icon_status = "";
  4409. $icon_comment = "";
  4410. if ($iassign_array[$j]->visible == 1) {
  4411. $iassign_current = $iassign_array[$j]->id;
  4412. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  4413. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4414. $icon_status = "";
  4415. $icon_comment = "";
  4416. if ($iassign_submission) {
  4417. // receiver=1 - message to teacher
  4418. // receiver=2 - message to student
  4419. // $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");
  4420. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  4421. $verify_message = $DB->get_record_sql(
  4422. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4423. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4424. if ($verify_message)
  4425. foreach ($verify_message as $tmp)
  4426. $sum_comment = $tmp;
  4427. if ($sum_comment > 0) {
  4428. $comment_unread_message = get_string('comment_unread', 'iassign');
  4429. if ($sum_comment == 1)
  4430. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4431. $icon_comment = "<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "#comments'>\n" .
  4432. ' <span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . "\n" .
  4433. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . "</span> </span></a>\n";
  4434. }
  4435. // $icon_comment = iassign_icons::insert('comment_unread');
  4436. if ($iassign_array[$j]->type_iassign == 3) {
  4437. if ($iassign_array[$j]->show_answer == 1) {
  4438. if ($iassign_submission->status == 3)
  4439. $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('correct', 'iassign') . '"></i>' . "\n";
  4440. elseif ($iassign_submission->status == 2)
  4441. $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('incorrect', 'iassign') . '"></i>' . "\n";
  4442. elseif ($iassign_submission->status == 1)
  4443. $icon_status = '<i class="fa fa-question" style="color: #77229; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4444. //2021/12 $icon_status = iassign_icons::insert('post');
  4445. elseif ($iassign_submission->status == 0)
  4446. $icon_status = '<i class="fa fa-question" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4447. } // if ($iassign_array[$j]->show_answer==1)
  4448. else {
  4449. if ($iassign_submission->status == 0) {
  4450. //TODO: $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4451. $icon_status = iassign_icons::insert('not_post');
  4452. }
  4453. else {
  4454. //TODO: $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4455. $icon_status = iassign_icons::insert('post');
  4456. }
  4457. }
  4458. } // if ($iassign_array[$j]->type_iassign == 3)
  4459. } // if ($iassign_submission)
  4460. elseif ($iassign_array[$j]->type_iassign == 3) {
  4461. $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4462. //2021/12 $icon_status = iassign_icons::insert('not_post');
  4463. } // if ($iassign_array[$j]->type_iassign == 3)
  4464. 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;">'
  4465. . $links . '</td><td>' . $icon_comment . '</td></tr>' . "\n";
  4466. //print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  4467. } // if ($iassign_array[$j]->visible == 1)
  4468. } // for ($j=0; $j<$total_of_activities; $j++)
  4469. print "</table>\n";
  4470. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4471. else if (isguestuser()) {
  4472. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  4473. print '<table width=100% ><tr>' . "\n";
  4474. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  4475. print '</tr></table>' . "\n";
  4476. for ($j=0; $j<$total_of_activities; $j++) {
  4477. $icon_status = "";
  4478. $icon_comment = "";
  4479. if ($iassign_array[$j]->visible == 1) {
  4480. $iassign_current = $iassign_array[$j]->id;
  4481. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4482. print '<p>' . $links . '</p>' . "\n";
  4483. } // if ($iassign_array[$j]->visible == 1)
  4484. }
  4485. }
  4486. print $OUTPUT->box_end();
  4487. } // function show_iassign($title, $iassign_array, $total_of_activities)
  4488. /// Show message of return
  4489. function return_home_course ($message) {
  4490. //D global $DB, $OUTPUT;
  4491. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4492. //D echo $OUTPUT->box_start();
  4493. //D echo '<table width=100% border=0 valign="top">' . "\n";
  4494. //D echo '<tr><td align="left"><strong>' . "\n";
  4495. //D print_string($message, 'iassign');
  4496. //D echo '</strong></td>' . "\n";
  4497. //D echo '<td width=20% align="right">' . "\n";
  4498. //D echo $link_return;
  4499. //D echo '</td></tr></table>' . "\n";
  4500. //D echo $OUTPUT->box_end();
  4501. //D // echo $OUTPUT->footer();
  4502. redirect(new moodle_url($this->return . '&notice=' . $message));
  4503. exit;
  4504. }
  4505. /// Search comment of activity
  4506. function search_comment_submission ($iassign_submissionid) {
  4507. global $USER, $DB, $OUTPUT, $COURSE;
  4508. // $context = context_course::instance($COURSE->id);
  4509. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  4510. $colorEdit2 = "#d2e5fc";
  4511. $has_capability = 0;
  4512. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  4513. $text = "";
  4514. if ($comments) {
  4515. $even = 1;
  4516. foreach ($comments as $tmp) {
  4517. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  4518. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  4519. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  4520. // $text .= $tmp->comment . "</td></tr>";
  4521. //} else {
  4522. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  4523. $avatar = new user_picture($user_data);
  4524. $avatar->courseid = $COURSE->id;
  4525. $avatar->link = true;
  4526. $user_picture = $OUTPUT->render($avatar);
  4527. $user_picture = str_replace('"35"', '"45"', $user_picture);
  4528. if ($even) {
  4529. $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";
  4530. $even = 0;
  4531. } else {
  4532. $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";
  4533. $even = 1;
  4534. }
  4535. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  4536. } // foreach ($comments as $tmp)
  4537. }
  4538. return $text;
  4539. }
  4540. /// Update comment of activity
  4541. function update_comment ($iassign_submissionid) {
  4542. global $USER, $DB, $OUTPUT;
  4543. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  4544. $receiver = 1; // student message to teacher
  4545. else
  4546. $receiver = 2; // teacher message to student
  4547. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  4548. if ($verify_message) {
  4549. foreach ($verify_message as $message) {
  4550. if ($message->receiver == $receiver) {
  4551. $newentry = new stdClass();
  4552. $newentry->id = $message->id;
  4553. $newentry->return_status = 1;
  4554. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  4555. print_error('error_update', 'iassign');
  4556. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  4557. } // if ($message->receiver == $receiver)
  4558. // Trigger module viewed event.
  4559. $event = \mod_iassign\event\submission_comment_updated::create(array(
  4560. 'objectid' => $this->iassign->id,
  4561. 'context' => $this->context
  4562. ));
  4563. $event->add_record_snapshot('course', $this->course);
  4564. $event->trigger();
  4565. } // foreach ($verify_message as $message)
  4566. }
  4567. }
  4568. /// Record comment of activity
  4569. function write_comment_submission () {
  4570. global $USER, $CFG, $DB;
  4571. $id = $this->cm->id;
  4572. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  4573. $row = optional_param('row', 0, PARAM_INT);
  4574. $column = optional_param('column', 0, PARAM_INT);
  4575. $sum_comment = 0;
  4576. $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);
  4577. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  4578. $str1 = trim($submission_comment);
  4579. $str2 = trim(get_string('box_comment_message', 'iassign'));
  4580. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  4581. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  4582. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  4583. $receiver = 1; // student message to teacher
  4584. $this->action = 'view';
  4585. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  4586. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  4587. } else {
  4588. $receiver = 2; // teacher message to student
  4589. $this->action = 'viewsubmission';
  4590. //D $tousers = array(); //MOOC 2016
  4591. //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
  4592. }
  4593. //MOOC 2016: foi p/ 15 linhas acima:
  4594. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  4595. // verificar se existe uma submissão para o exercício e aluno informados
  4596. if (!$iassign_submission) {
  4597. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  4598. }
  4599. if (!$iassign_submission) {
  4600. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  4601. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  4602. $this->iassign_submission_current = $id_submission;
  4603. }
  4604. else {
  4605. $id_submission = $iassign_submission->id;
  4606. } // if (!$iassign_submission)
  4607. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4608. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4609. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4610. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4611. $comments = $DB->get_record_sql(
  4612. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4613. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4614. if ($comments)
  4615. foreach ($comments as $tmp)
  4616. $sum_comment = $tmp;
  4617. if ($sum_comment == 0) {
  4618. $newentry = new stdClass();
  4619. $newentry->iassign_submissionid = $id_submission;
  4620. $newentry->comment_authorid = $USER->id;
  4621. $newentry->timecreated = time();
  4622. $newentry->comment = $submission_comment;
  4623. $newentry->receiver = $receiver;
  4624. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4625. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  4626. // Trigger module viewed event
  4627. $event = \mod_iassign\event\submission_comment_created::create(array(
  4628. 'objectid' => $this->iassign->id,
  4629. 'context' => $this->context
  4630. ));
  4631. $event->add_record_snapshot('course', $this->course);
  4632. $event->trigger();
  4633. }
  4634. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4635. // if ($this->action=='viewsubmission') {
  4636. // echo $OUTPUT->header();
  4637. // $this->return_last('confirm_add_comment', $link_return);
  4638. // die;
  4639. // }
  4640. return true;
  4641. } // function write_comment_submission()
  4642. /// Writes a new submission
  4643. // The first student answer is under 'function get_answer()'
  4644. function new_submission ($iassignid, $id_user, $receiver) {
  4645. global $USER, $DB, $OUTPUT;
  4646. $newentry = new stdClass();
  4647. $newentry->iassign_statementid = $iassignid;
  4648. $newentry->userid = $id_user;
  4649. $newentry->timecreated = time();
  4650. $newentry->timemodified = time();
  4651. $newentry->answer = 0; // student only submit message
  4652. if ($receiver == 2) // teacher message to student (write id teacher)
  4653. $newentry->teacher = $USER->id;
  4654. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4655. return_home_course('error_insert_submissions');
  4656. else {
  4657. // Trigger module view event
  4658. $event = \mod_iassign\event\submission_created::create(array(
  4659. 'objectid' => $this->iassign->id,
  4660. 'context' => $this->context
  4661. ));
  4662. $event->add_record_snapshot('course', $this->course);
  4663. $event->trigger();
  4664. }
  4665. return $newentry->id;
  4666. }
  4667. /// Return to a specific address of page
  4668. function return_last ($message, $link_return) {
  4669. global $DB, $OUTPUT;
  4670. print $OUTPUT->box_start();
  4671. print '<table width=100% border=0 valign="top">' . "\n";
  4672. print '<tr><td align="left"><strong>' . "\n";
  4673. print_string($message, 'iassign');
  4674. print '</strong></td>' . "\n";
  4675. print '<td width=20% align="right">' . "\n";
  4676. print $link_return;
  4677. print '</td></tr></table>' . "\n";
  4678. print $OUTPUT->box_end();
  4679. print $OUTPUT->footer();
  4680. die();
  4681. } // function return_last($message, $link_return)
  4682. } // class iassign
  4683. /// Class for manage activities
  4684. class activity {
  4685. var $activity;
  4686. /// Constructor of class.
  4687. // @param int $id Id of activity
  4688. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4689. // public function activity($id) { self::__construct($id); }
  4690. function __construct ($id) {
  4691. global $DB;
  4692. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4693. if (empty($this->activity))
  4694. $this->activity = null;
  4695. }
  4696. /// Get an activity
  4697. // @return NULL
  4698. function get_activity () {
  4699. if ($this->activity != null)
  4700. return $this->activity;
  4701. else
  4702. return null;
  4703. }
  4704. /// Delete interactive activities
  4705. function delete ($return) {
  4706. global $USER, $CFG, $DB, $OUTPUT;
  4707. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4708. print $OUTPUT->header();
  4709. $output .= $OUTPUT->box_start();
  4710. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4711. if ($iassign_submission_currents) {
  4712. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4713. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4714. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4715. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4716. $output .= $OUTPUT->box_end();
  4717. $output .= $OUTPUT->footer();
  4718. print $output;
  4719. die();
  4720. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4721. } // if ($iassign_submission_currents)
  4722. else
  4723. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>\n";
  4724. $output .= '<table width=50% border=0>';
  4725. $output .= '<tr valign="top"><td>';
  4726. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>\n";
  4727. $output .= '</td><td>';
  4728. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4729. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4730. $output .= "<form name='formDelete' id='formDelete' method='post' action='" . $deleteiassignyes . "' enctype='multipart/form-data'>\n";
  4731. $output .= " <input type=submit value='" . $bottonDelete_yes . "'/>\n";
  4732. $output .= "</form>\n";
  4733. $output .= '</td><td>';
  4734. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4735. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4736. $output .= "<form name='formDelete' id='formDelete' method='post' action='" . $deleteiassignno . "' enctype='multipart/form-data'>\n";
  4737. $output .= " <p><input type=submit value='" . $bottonDelete_no . "'/></p>\n";
  4738. $output .= "</form>\n";
  4739. $output .= '</td></tr></table>' . "\n";
  4740. $output .= $OUTPUT->box_end();
  4741. $output .= $OUTPUT->footer();
  4742. print $output;
  4743. } // function delete($return)
  4744. /// Function for confirm the delete of activity
  4745. // @param String $return Url of return
  4746. // @param Object $iassign Object content an activity
  4747. function deleteyes ($return, $iassign) {
  4748. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4749. $msg = '';
  4750. if (!empty($this->activity->id)) {
  4751. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4752. if ($iassign_submission_currents) {
  4753. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4754. foreach ($iassign_submission_currents as $iassign_submission)
  4755. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4756. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4757. } // if ($iassign_submission_currents)
  4758. }
  4759. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4760. // Remove all files associated to this activity:
  4761. $fs = get_file_storage();
  4762. //TODO 2022: nao deveria ser "$this->activity->file" no lugar de "$this->activity->id"?
  4763. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4764. $this->delete_calendar($this->activity->id);
  4765. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4766. iassign::update_grade_iassign($this->activity->iassignid);
  4767. if ($delete_iassign_current) {
  4768. $iassign->return_home_course('confirm_delete_iassign');
  4769. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4770. }
  4771. else {
  4772. $iassign->return_home_course('error_confirm_delete_iassign');
  4773. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4774. }
  4775. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4776. }
  4777. } // function deleteyes($return, $iassign)
  4778. /// Change fields 'iassign_statement.position' between 2 activities
  4779. // @calledby : class this->move_iassign($move_action, $target, $return)
  4780. // @calledby : class iassign show_iassign($title, $iassign_array, $total_of_activities) - this is used only to fix 'position' erros (e.g. {1,2,2,3} to {1,2,3,4})
  4781. static function move_change_activity_position ($DB, $idFrom, $idTo, $posFrom, $posTo) { //1
  4782. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4783. $newentry->id = $idFrom; // ID of the "source activity" //1 $this->activity->id -> $idFrom
  4784. $newentry->position = $posFrom; // final position to source //1 $final_position_source -> $posFrom
  4785. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4786. print_error('error_update_move_iassign', 'iassign');
  4787. }
  4788. // If $idFrom == $idTo then came here from 'this->show_iassign(.)' above, to correct order!
  4789. if ($idFrom != $idTo) { // if $idFrom != $idTo then must update also the targe position
  4790. $newentry->id = $idTo; //1 $iassign_target->id -> $idTo
  4791. $newentry->position = $posTo; //1 $final_position_target -> $posTo
  4792. if (!$DB->update_record('iassign_statement', $newentry))
  4793. print_error('error_update_move_iassign', 'iassign');
  4794. }
  4795. }
  4796. /// Changes position of activities (between those inside a group of interactive activities)
  4797. // @param $move_action = must be "up" or "down"
  4798. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4799. function move_iassign ($move_action, $target, $return) {
  4800. global $DB, $OUTPUT;
  4801. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4802. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4803. if ($move_action=="firstdown") {
  4804. $final_position_source = 2;
  4805. $final_position_target = 1;
  4806. }
  4807. else
  4808. if ($move_action=="down") {
  4809. $final_position_target = $this->activity->position;
  4810. $final_position_source = $final_position_target + 1;
  4811. }
  4812. else
  4813. if ($move_action=="up") {
  4814. $final_position_target = $this->activity->position;
  4815. $final_position_source = $final_position_target - 1;
  4816. }
  4817. else { // error:
  4818. print_error('error_update_move_iassign', 'iassign');
  4819. exit;
  4820. }
  4821. activity::move_change_activity_position($DB, $this->activity->id, $iassign_target->id, $final_position_source, $final_position_target); // efectively exchange 'position'
  4822. redirect($return);
  4823. } // function move_iassign($move_action, $target, $return)
  4824. /// Enable or disable the display of interactive activities
  4825. function visible_iassign ($return) {
  4826. global $DB;
  4827. $newentry = new stdClass();
  4828. $newentry->id = $this->activity->id;
  4829. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4830. if (!$DB->update_record('iassign_statement', $newentry))
  4831. print_error('error_update_visible_iassign', 'iassign');
  4832. redirect($return);
  4833. }
  4834. /// Add new interactive activities (register in table 'iassign_statement')
  4835. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4836. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4837. function new_iassign ($param) {
  4838. global $DB;
  4839. $newentry = new stdClass();
  4840. $newentry->iassignid = $param->iassignid;
  4841. $newentry->name = $param->name;
  4842. $newentry->type_iassign = $param->type_iassign;
  4843. $newentry->store_all_submissions = $param->store_all_submissions;
  4844. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4845. $proposition = $param->proposition;
  4846. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4847. else $proposition_text = $proposition;
  4848. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4849. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4850. //TODO Then get it directly from the form data $_POST!
  4851. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4852. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4853. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4854. $newentry->author_name = $param->author_name;
  4855. $newentry->author_modified_name = $param->author_modified_name;
  4856. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4857. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4858. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4859. $newentry->grade = $param->grade;
  4860. $newentry->timemodified = time();
  4861. $newentry->timecreated = time();
  4862. if ($param->type_iassign == 1) {
  4863. $newentry->timedue = 0;
  4864. $newentry->timeavailable = 0;
  4865. } // if ($param->type_iassign == 1)
  4866. else {
  4867. $newentry->timedue = $param->timedue;
  4868. $newentry->timeavailable = $param->timeavailable;
  4869. }
  4870. $newentry->preventlate = $param->preventlate;
  4871. $newentry->test = $param->test;
  4872. $newentry->special_param1 = $param->special_param1;
  4873. $newentry->visible = $param->visible;
  4874. $newentry->position = $param->position;
  4875. $newentry->max_experiment = $param->max_experiment;
  4876. $newentry->dependency = $param->dependency;
  4877. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4878. $newentry->show_answer = $param->show_answer;
  4879. $id = $DB->insert_record("iassign_statement", $newentry);
  4880. if ($id) {
  4881. $component = 'mod_iassign';
  4882. $filearea = 'exercise';
  4883. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4884. $file = $fs->get_file_by_id($param->file);
  4885. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4886. // ATTENTION: {files}.itemid must be equal to {iassign_statement}.id
  4887. // $itemid = $id;
  4888. // File already inserted in other context!
  4889. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4890. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4891. $updateentry = new stdClass();
  4892. $updateentry->id = $id;
  4893. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4894. $updateentry->filesid = $newfile->get_itemid();
  4895. if (!$DB->update_record("iassign_statement", $updateentry))
  4896. print_error('error_add', 'iassign');
  4897. if ($param->type_iassign == 3)
  4898. iassign::update_grade_iassign($param->iassignid);
  4899. //TODO iLM_HTML5 :: //MOOC2014
  4900. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4901. //D if ($iassign_ilm_configs) {
  4902. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4903. //D if ($iassign_ilm_config->param_type != 'static') {
  4904. //D $newentry = new stdClass();
  4905. //D $newentry->iassign_statementid = $id;
  4906. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4907. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4908. //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});
  4909. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4910. //D print_error('error_add_param', 'iassign');
  4911. //D }
  4912. //D }
  4913. //D }
  4914. // log event --------------------------------------------------------------------------------------
  4915. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4916. // log event --------------------------------------------------------------------------------------
  4917. return $id;
  4918. }
  4919. else
  4920. print_error('error_add', 'iassign');
  4921. } // function new_iassign($param)
  4922. /// Add the calendar entries for this iassign
  4923. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4924. // @return bool
  4925. static function add_calendar ($iassignid) {
  4926. global $DB, $CFG;
  4927. require_once($CFG->dirroot . '/calendar/lib.php');
  4928. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4929. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4930. $event = new stdClass();
  4931. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4932. $event->description = $iassign_statement_activity_item->name;
  4933. $event->courseid = $iassign->course;
  4934. $event->groupid = 0;
  4935. $event->userid = 0;
  4936. $event->modulename = 'iassign';
  4937. $event->instance = $iassign->id;
  4938. $event->eventtype = 'due';
  4939. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4940. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4941. calendar_event::create($event);
  4942. }
  4943. /// Update the calendar entries for this iassign
  4944. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4945. // @return bool
  4946. function update_calendar ($iassignid, $olddescription) {
  4947. global $DB, $CFG;
  4948. require_once($CFG->dirroot . '/calendar/lib.php');
  4949. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4950. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4951. $event = new stdClass();
  4952. $event->id = 0;
  4953. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4954. if ($events) {
  4955. foreach ($events as $value) {
  4956. if ($value->description == $olddescription) {
  4957. $event->id = $value->id;
  4958. }
  4959. }
  4960. }
  4961. if ($event->id != 0) {
  4962. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4963. $event->description = $iassign_statement_activity_item->name;
  4964. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4965. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4966. $calendarevent = calendar_event::load($event->id);
  4967. $calendarevent->update($event);
  4968. } else
  4969. $this->add_calendar($iassignid);
  4970. }
  4971. /// Update the calendar entries for this iassign
  4972. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4973. // @return bool
  4974. function delete_calendar ($iassignid) {
  4975. global $DB, $CFG;
  4976. require_once($CFG->dirroot . '/calendar/lib.php');
  4977. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4978. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4979. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4980. if ($events) {
  4981. foreach ($events as $value) {
  4982. if ($value->description == $iassign_statement_activity_item->name) {
  4983. $DB->delete_records('event', array('id' => $value->id));
  4984. }
  4985. }
  4986. }
  4987. }
  4988. /// Update interactive activities
  4989. function update_iassign ($param) {
  4990. global $DB;
  4991. $component = 'mod_iassign';
  4992. $filearea = 'exercise';
  4993. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4994. $file = $fs->get_file_by_id($param->file);
  4995. $fileold = $fs->get_file_by_id($param->fileold);
  4996. if ($param->file != $param->fileold) {
  4997. if ($fileold) {
  4998. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4999. foreach ($fileoldarea as $value) {
  5000. $value->delete();
  5001. }
  5002. }
  5003. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  5004. $itemid = $file->get_itemid() + $param->iassign_id;
  5005. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  5006. $param->file = $newfile->get_itemid();
  5007. }
  5008. else
  5009. $param->file = $file->get_itemid();
  5010. }
  5011. else {
  5012. $param->file = $file->get_itemid();
  5013. }
  5014. $newentry = new stdClass();
  5015. $newentry->id = $param->iassign_id;
  5016. $newentry->name = $param->name;
  5017. $newentry->type_iassign = $param->type_iassign;
  5018. $newentry->store_all_submissions = $param->store_all_submissions;
  5019. //2019 $newentry->proposition = $param->proposition;
  5020. $proposition = $param->proposition;
  5021. if (is_array($proposition))
  5022. $proposition_text = $proposition['text'];
  5023. else
  5024. $proposition_text = $proposition;
  5025. $newentry->proposition = $proposition_text;
  5026. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5027. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  5028. $newentry->grade = $param->grade;
  5029. $newentry->author_modified_name = $param->author_modified_name;
  5030. $newentry->timemodified = time();
  5031. if ($param->type_iassign == 1) {
  5032. $newentry->timedue = 0;
  5033. $newentry->timeavailable = 0;
  5034. } // if ($param->type_iassign == 1)
  5035. else {
  5036. $newentry->timedue = $param->timedue;
  5037. $newentry->timeavailable = $param->timeavailable;
  5038. }
  5039. $newentry->preventlate = $param->preventlate;
  5040. $newentry->test = $param->test;
  5041. if (isset($param->special_param1))
  5042. $newentry->special_param1 = $param->special_param1;
  5043. else
  5044. $newentry->special_param1 = NULL;
  5045. $newentry->visible = $param->visible;
  5046. $newentry->max_experiment = $param->max_experiment;
  5047. $newentry->dependency = $param->dependency;
  5048. $newentry->automatic_evaluate = $param->automatic_evaluate;
  5049. $newentry->show_answer = $param->show_answer;
  5050. if (!$DB->update_record("iassign_statement", $newentry))
  5051. print_error('error_update', 'iassign');
  5052. if ($param->type_iassign == 3) {
  5053. iassign::update_grade_iassign($param->iassignid);
  5054. }
  5055. //$id = $newentry->id; // MOOC 2016 --- inicio
  5056. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  5057. //if ($iassign_activity_item_configs) {
  5058. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  5059. // $newentry = new stdClass();
  5060. // $newentry->id = $iassign_activity_item_config->id;
  5061. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  5062. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  5063. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  5064. // if (!$DB->update_record("iassign_statement_config", $newentry))
  5065. // print_error('error_edit_param', 'iassign');
  5066. // }
  5067. // } // MOOC 2016 --- final
  5068. // log event --------------------------------------------------------------------------------------
  5069. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  5070. // log event --------------------------------------------------------------------------------------
  5071. return $newentry->id;
  5072. // if ($param->type_iassign==3)
  5073. // $this->update_grade_iassign($param->iassignid);
  5074. } // function update_iassign($param)
  5075. /// Show information of activity
  5076. function show_info_iassign () {
  5077. global $DB, $OUTPUT;
  5078. $output = '';
  5079. if ($this->activity->type_iassign == 3) {
  5080. if ($this->activity->dependency == 0) {
  5081. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  5082. } else {
  5083. $dependencys = explode(';', $this->activity->dependency);
  5084. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  5085. foreach ($dependencys as $dependency) {
  5086. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  5087. if ($dependencyiassign)
  5088. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  5089. } // foreach ($dependencys as $dependency)
  5090. } // if ($iassign_statement_activity_item->dependency == 0)
  5091. if ($this->activity->max_experiment == 0)
  5092. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  5093. else
  5094. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  5095. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  5096. } // if ($iassign_statement_activity_item->type_iassign == 3)
  5097. $output .= $this->toggle_columns_script();
  5098. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  5099. print $OUTPUT->box($output);
  5100. } // function show_info_iassign()
  5101. /// Provide script to toggle columns
  5102. static function toggle_columns_script () {
  5103. $output = "";
  5104. $output .= '<script>
  5105. function toLeft () {
  5106. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  5107. document.getElementsByClassName("proposition")[0].style.width = "40%";
  5108. document.getElementById("fullscreen").style.marginTop = "-3rem";
  5109. document.getElementById("columnsbutton").style.color = "#1da075";
  5110. }
  5111. function toDefault () {
  5112. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  5113. document.getElementsByClassName("proposition")[0].style.width = "100%";
  5114. document.getElementById("fullscreen").style.marginTop = "0";
  5115. document.getElementById("columnsbutton").style.color = "#343a40";
  5116. }
  5117. var activate = false;
  5118. function toggleColumns () {
  5119. if (activate) {
  5120. activate = false;
  5121. toDefault();
  5122. } else {
  5123. activate = true;
  5124. toLeft();
  5125. }
  5126. }
  5127. </script>'; // '
  5128. $output .= '<span tabindex="0" data-toggle="tooltip" title="' . get_string('enable_disable_columns', 'iassign')
  5129. . '" style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>' . "\n";
  5130. return $output;
  5131. } // function write_comment_submission()
  5132. static function get_latest_array_item ($DB, $iassignid, $position) { //TODO: may be search for the greatest grade?
  5133. $iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'position' => $position));
  5134. $item = NULL;
  5135. foreach ($iassign_statement as $item) ; // get the last item!
  5136. if ($item) return $item; // return the last one
  5137. return NULL;
  5138. }
  5139. /// Shows date of opening and closing activities
  5140. function view_dates () {
  5141. global $USER, $CFG, $DB, $OUTPUT;
  5142. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  5143. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  5144. $status_iassign = "";
  5145. $status_iassign1 = "";
  5146. $status_iassign2 = "";
  5147. if ($this->activity->type_iassign == 1) // activity of type example
  5148. $type_iassign = get_string('example_iassign', 'iassign');
  5149. elseif ($this->activity->type_iassign == 2) { // activity of type test
  5150. $type_iassign = get_string('test_iassign', 'iassign');
  5151. if ($this->activity->timeavailable > time()) {
  5152. $status_iassign = get_string('previous_timeavailable', 'iassign');
  5153. } elseif ($this->activity->timedue < time()) {
  5154. $status_iassign = get_string('last_timedue', 'iassign');
  5155. }
  5156. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  5157. $type_iassign = get_string('exercise_iassign', 'iassign');
  5158. if ($this->activity->timeavailable > time()) {
  5159. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  5160. } elseif ($this->activity->timedue < time()) { // after delivery
  5161. $status_iassign = get_string('last_timedue', 'iassign');
  5162. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  5163. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  5164. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  5165. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  5166. if ($this->activity->test == 1) // allowed to test after of deadline
  5167. $status_iassign2 = get_string('test_preventlate', 'iassign');
  5168. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  5169. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  5170. } // elseif ($iassign_statement_activity_item->test == 0)
  5171. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  5172. } // elseif ($iassign_statement_activity_item->timedue < time())
  5173. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  5174. $output = '<table width=100% >' . "\n";
  5175. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  5176. $output .= '<tr>' . "\n";
  5177. //leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  5178. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  5179. //leo $output .= '<td width=80%>' . $type_iassign;
  5180. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  5181. // $output .= '</td>' . "\n";
  5182. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  5183. // Link (with icon) to report survey (to present all interactivy exercises inside this block)
  5184. $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>";
  5185. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  5186. }
  5187. else {
  5188. // Get all previous/next solution sent by this student (present link to his last answer)
  5189. // $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  5190. $iassign_previous = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position-1); // previous activity of this student inside this block
  5191. // $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  5192. $iassign_next = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position+1); // next activity of this student inside this block
  5193. $link_next = "";
  5194. $link_previous = "";
  5195. if ($iassign_previous) { // previous_activity
  5196. $url_previous = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_previous->id;
  5197. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>\n";
  5198. }
  5199. if ($iassign_next) { // next_activity
  5200. $url_next = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_next->id;
  5201. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>\n";
  5202. }
  5203. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  5204. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  5205. $output .= '</tr></table>' . "\n";
  5206. $output .= '<table width=100% >' . "\n";
  5207. if ($this->activity->type_iassign > 1) {
  5208. if ($this->activity->timeavailable)
  5209. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  5210. if ($this->activity->timedue)
  5211. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  5212. } // if ($iassign_statement_activity_item->type_iassign > 1)
  5213. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  5214. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  5215. $output .= '</table>' . "\n";
  5216. print $OUTPUT->box($output);
  5217. } // function view_dates()
  5218. } // class activity
  5219. /// Class to manage Interactive Learning Module (iLM)
  5220. class ilm {
  5221. var $ilm;
  5222. /// Constructor of class
  5223. // @param int $id Id of iLM
  5224. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  5225. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  5226. function __construct ($id) {
  5227. global $DB;
  5228. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  5229. if (empty($this->ilm))
  5230. $this->ilm = null;
  5231. }
  5232. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  5233. // @calledby view_iassign_current()
  5234. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  5235. global $USER, $CFG, $DB;
  5236. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  5237. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5238. $typec = strtolower($iassign_ilm->type);
  5239. require_once 'ilm_handlers/' . $typec . '.php';
  5240. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  5241. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  5242. return $retorno;
  5243. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  5244. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  5245. // @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);
  5246. // @param int $iassign_statement_activity_itemid Id of iassign statement
  5247. // @param Object $file File in use in activity
  5248. // @return int Return the id of log
  5249. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  5250. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  5251. $newentry = new stdClass();
  5252. $newentry->iassign_statementid = $iassign_activity_itemid;
  5253. $newentry->userid = $USER->id;
  5254. $newentry->filesid = $content_or_id_from_ilm_security;
  5255. $newentry->timecreated = time();
  5256. $newentry->view = 1;
  5257. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  5258. if (!$id_iLM_security) {
  5259. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  5260. } // from (!$DB->insert_record("iassign_security", $newentry))
  5261. return $id_iLM_security;
  5262. }
  5263. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  5264. // @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);
  5265. // @param int $userid
  5266. // @param int $iassign_activity_itemid Id of iassign statement
  5267. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  5268. global $DB;
  5269. // 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")
  5270. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  5271. }
  5272. } // class ilm
  5273. /// Class to manage settings of iLM.
  5274. class ilm_settings {
  5275. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  5276. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5277. // @param int $ilm_id Id of iLM
  5278. // @param array $options An array with options for create dynamic tag html APPLET
  5279. // @return string Return with a tag html APPLET created
  5280. static function build_ilm_tags ($ilm_id, $options = array()) {
  5281. global $DB;
  5282. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5283. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5284. $typec = strtolower($iassign_ilm->type);
  5285. require_once 'ilm_handlers/' . $typec . '.php';
  5286. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  5287. return $retorno;
  5288. } // static function build_ilm_tags($ilm_id, $options = array())
  5289. /// Function for get modified date of iLM file
  5290. // @param string $file_jar String with Ids of iLM files
  5291. // @return string Return with the filenames and modified date
  5292. static function applet_filetime ($file_jar) {
  5293. $filetime = "";
  5294. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5295. $files_jar = explode(",", $file_jar);
  5296. foreach ($files_jar as $one_file) {
  5297. $file = $fs->get_file_by_id($one_file);
  5298. if ($file)
  5299. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  5300. }
  5301. return $filetime;
  5302. }
  5303. /// Function for verify an default applet
  5304. // @param String $file_jar String containing an list de ids of applet files
  5305. // @return boolean Return true or fale if applet is default
  5306. static function applet_default ($file_jar) {
  5307. $is_default = true;
  5308. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5309. $files_jar = explode(",", $file_jar);
  5310. foreach ($files_jar as $one_file) {
  5311. $file = $fs->get_file_by_id($one_file);
  5312. if ($file)
  5313. $is_default &= ($file->get_itemid() == 0);
  5314. }
  5315. return $is_default;
  5316. }
  5317. /// Function for get form variables for add, edit, or copy iLM
  5318. // This function is called to fill in the iLM data to the form
  5319. // The function 'edit_ilm(.)' bellow is responsible to process edited data
  5320. // @calledby settings_ilm.php: On the first call $ilm_id is defined: the calling is necessary to fill in data to the form
  5321. // @calledby settings_ilm.php: On the second call $ilm_id empty (however must be used)
  5322. // @see settings_form.php
  5323. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  5324. // @see locallib.php : static function edit_ilm ($param,$itemid): perform the data register (files and database) in edition process
  5325. // @param int $ilm_id Id of iLM
  5326. // @param string $action String with the action
  5327. // @return object Return an object with forms variables
  5328. static function add_edit_copy_ilm ($ilm_id, $action) {
  5329. global $USER, $DB, $CFG;
  5330. require_once('settings_form.php'); // put the form
  5331. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5332. $param = new stdClass();
  5333. $param->action = $action;
  5334. $param->ilm_id = $ilm_id;
  5335. $CFG->action_ilm = $action;
  5336. $CFG->ilm_id = $ilm_id;
  5337. if ($action == 'add') {
  5338. $param->title = get_string('add_ilm', 'iassign');
  5339. $param->name = "";
  5340. $param->version = "";
  5341. $param->url = "";
  5342. $param->description = "";
  5343. $param->extension = "";
  5344. $param->author = $USER->id;
  5345. $param->file_jar = "";
  5346. $param->file_jar_static = "";
  5347. $param->file_class = "";
  5348. $param->width = 800;
  5349. $param->height = 600;
  5350. $param->enable = 0; // 0 - hide / 1 - show
  5351. $param->timecreated = time();
  5352. $param->timemodified = time();
  5353. $param->evaluate = 0; // evaluate = 1 => iLM has auto-evaluation method
  5354. $param->reevaluate = 0; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
  5355. $param->editingbehavior = 0; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
  5356. $param->submissionbehavior = 0; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
  5357. $param->parent = 0;
  5358. }
  5359. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  5360. if ($iassign_ilm) {
  5361. //D echo "* entrou no iassign_ilm="; print_r($iassign_ilm); echo "<br/>\n"; //exit;
  5362. $description = json_decode($iassign_ilm->description);
  5363. $param->title = get_string('edit_ilm', 'iassign');
  5364. $param->id = $iassign_ilm->id;
  5365. $param->name_ilm = $iassign_ilm->name;
  5366. $param->name = $iassign_ilm->name;
  5367. $param->version = $iassign_ilm->version;
  5368. $param->ilm_type = $iassign_ilm->type;
  5369. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5370. $param->url = $iassign_ilm->url; // iLM official URL
  5371. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  5372. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  5373. $param->editingbehavior = $iassign_ilm->editingbehavior;
  5374. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  5375. if (!isset($description->{current_language()})) {
  5376. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  5377. else
  5378. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  5379. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  5380. }
  5381. else
  5382. $param->description = $description->{current_language()};
  5383. $param->description_lang = $iassign_ilm->description;
  5384. $param->extension = $iassign_ilm->extension;
  5385. $param->author = $iassign_ilm->author;
  5386. $param->file_jar = $iassign_ilm->file_jar;
  5387. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  5388. $param->file_class = $iassign_ilm->file_class;
  5389. $param->width = $iassign_ilm->width;
  5390. $param->height = $iassign_ilm->height;
  5391. $param->enable = $iassign_ilm->enable;
  5392. $param->timecreated = $iassign_ilm->timecreated;
  5393. $param->timemodified = time();
  5394. $param->evaluate = $iassign_ilm->evaluate; // evaluate = 1 => iLM has auto-evaluation method
  5395. $param->reevaluate = $iassign_ilm->reevaluate; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
  5396. $param->editingbehavior = $iassign_ilm->editingbehavior; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
  5397. $param->submissionbehavior = $iassign_ilm->submissionbehavior; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
  5398. $param->parent = $iassign_ilm->parent;
  5399. } // if ($iassign_ilm)
  5400. } // elseif ($action == 'edit')
  5401. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  5402. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  5403. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5404. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  5405. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  5406. // echo "Sem dados<br/>"; exit;
  5407. return;
  5408. }
  5409. $description = json_decode($iassign_ilm->description);
  5410. if ($iassign_ilm) {
  5411. if ($iassign_ilm->parent == 0)
  5412. $iassign_ilm->parent = $ilm_id;
  5413. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  5414. $param->title = get_string('new_version_ilm', 'iassign');
  5415. $param->name_ilm = $iassign_ilm->name;
  5416. $param->name = $iassign_ilm->name;
  5417. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  5418. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  5419. $param->version = $iassign_ilm->version; // do not erase field 'version'
  5420. $param->ilm_type = $iassign_ilm->type;
  5421. $param->url = $iassign_ilm->url;
  5422. $param->description = $description->{current_language()};
  5423. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  5424. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5425. $param->extension = $iassign_ilm->extension;
  5426. $param->author = $USER->id;
  5427. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  5428. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  5429. $param->file_jar_static = '';
  5430. $param->file_class = $iassign_ilm->file_class;
  5431. $param->width = $iassign_ilm->width;
  5432. $param->height = $iassign_ilm->height;
  5433. $param->enable = 0;
  5434. $param->timecreated = time();
  5435. $param->timemodified = time();
  5436. $param->evaluate = $iassign_ilm->evaluate;
  5437. $param->reevaluate = $iassign_ilm->reevaluate; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
  5438. $param->editingbehavior = $iassign_ilm->editingbehavior; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
  5439. $param->submissionbehavior = $iassign_ilm->submissionbehavior; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
  5440. $param->parent = $iassign_ilm->parent;
  5441. } // if ($iassign_ilm)
  5442. } // elseif ($action == 'new_version')
  5443. elseif ($action == 'copy') {
  5444. $description = json_decode($iassign_ilm->description);
  5445. if ($iassign_ilm) {
  5446. if ($iassign_ilm->parent == 0)
  5447. $iassign_ilm->parent = $ilm_id;
  5448. $param->title = get_string('copy_ilm', 'iassign');
  5449. $param->id = $iassign_ilm->id;
  5450. $param->name_ilm = $iassign_ilm->name;
  5451. $param->name = $iassign_ilm->name;
  5452. $param->version = "";
  5453. $param->ilm_type = $iassign_ilm->type;
  5454. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5455. $param->url = $iassign_ilm->url;
  5456. $param->description = $description->{current_language()};
  5457. $param->description_lang = $iassign_ilm->description;
  5458. $param->extension = $iassign_ilm->extension;
  5459. $param->author = $USER->id;
  5460. $param->file_jar = '';
  5461. $param->file_jar_static = '';
  5462. $param->file_class = $iassign_ilm->file_class;
  5463. $param->width = $iassign_ilm->width;
  5464. $param->height = $iassign_ilm->height;
  5465. $param->enable = 0;
  5466. $param->timecreated = time();
  5467. $param->timemodified = time();
  5468. $param->evaluate = $iassign_ilm->evaluate;
  5469. $param->reevaluate = $iassign_ilm->reevaluate; // reevaluate = 1 => allows to the teacher calls method to re-evaluate (does it in batch, to all students)
  5470. $param->editingbehavior = $iassign_ilm->editingbehavior; // editingbehavior = 1 => iLM auto-evaluation remains working over a solution sent by the student (iGeom does not work, iVProg does)
  5471. $param->submissionbehavior = $iassign_ilm->submissionbehavior; // 0 => 'After submission, this iLM remains on the same page'; 1 => 'After submission, this iLM changes the current page'
  5472. $param->parent = $iassign_ilm->parent;
  5473. } // if ($iassign_ilm)
  5474. } // elseif ($action == 'copy'
  5475. //D debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
  5476. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  5477. //D var_dump(debug_backtrace());
  5478. //D print_r(debug_backtrace()); echo "param="; print_r($param); echo "<br/>\n";
  5479. //D echo "<br/>---------------------------------<br/>"; exit;
  5480. return $param;
  5481. } // static function add_edit_copy_ilm($ilm_id, $action)
  5482. /// Function for save iLM file in moodledata
  5483. // @param int $itemid Itemid of file save in draft (upload file)
  5484. // @param int $ilm_id Id of iLM
  5485. // @return string Return an string with ids of iLM files
  5486. static function new_file_ilm ($itemid, $iassign_ilm) {
  5487. global $CFG, $USER, $DB;
  5488. $return = null;
  5489. $file_jar = array();
  5490. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5491. $contextuser = context_user::instance($USER->id);
  5492. $contextsystem = context_system::instance();
  5493. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  5494. if ($files_ilm) {
  5495. foreach ($files_ilm as $value) {
  5496. // CHECK IF file is HTML type
  5497. if ($iassign_ilm->type == 1) {
  5498. // Check if the file extension is ZIP
  5499. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  5500. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  5501. if ((strtolower($ext) == 'zip')) {
  5502. // Coping...:
  5503. $destination = 'ilm_debug/' . $value->get_filename();
  5504. $value->copy_content_to($destination);
  5505. // Extracting content...:
  5506. $zip = new ZipArchive();
  5507. $extracted = './ilm';
  5508. $dir = "";
  5509. if ($zip->open($destination) === TRUE) {
  5510. $dir = './ilm/' . trim($zip->getNameIndex(0));
  5511. if (is_dir($dir)) {
  5512. $i = 1;
  5513. $previous = str_replace("/", "", $zip->getNameIndex(0));
  5514. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  5515. $i++;
  5516. }
  5517. $name = $previous . "_" . $i;
  5518. $dir = './ilm/' . $name . "/";
  5519. $j = 0;
  5520. while ($item_name = $zip->getNameIndex($j)) {
  5521. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  5522. $j++;
  5523. }
  5524. $zip->close();
  5525. }
  5526. $zip->open($destination);
  5527. $zip->extractTo($extracted);
  5528. $zip->close();
  5529. // After the extraction, remove it from DEBUG
  5530. unlink($destination);
  5531. } else { // Error trying to open destination...
  5532. // After the extraction error, also remove it from DEBUG
  5533. unlink($destination);
  5534. print_error('error_add_ilm_zip', 'iassign');
  5535. }
  5536. return $dir;
  5537. }
  5538. } // if ($iassign_ilm->type == 1)
  5539. if ($value->get_filename() != '.') {
  5540. $file_ilm = array(
  5541. 'userid' => $USER->id,
  5542. 'contextid' => $contextsystem->id,
  5543. 'component' => 'mod_iassign',
  5544. 'filearea' => 'ilm',
  5545. 'itemid' => rand(1, 999999999),
  5546. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  5547. 'filename' => $value->get_filename());
  5548. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  5549. array_push($file_jar, $file_ilm->get_id());
  5550. }
  5551. }
  5552. if (!empty($file_jar)) {
  5553. $return = implode(",", $file_jar);
  5554. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  5555. foreach ($old_file_jar as $value) {
  5556. $file = $fs->get_file_by_id($value);
  5557. if ($file)
  5558. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  5559. }
  5560. }
  5561. }
  5562. else // if ($files_ilm)
  5563. $return = $iassign_ilm->file_jar;
  5564. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  5565. return $return;
  5566. } // static function new_file_ilm($itemid, $iassign_ilm)
  5567. /// Function for save in database an new iLM
  5568. // @param object $param An object with iLM params
  5569. static function new_ilm ($itemid) {
  5570. global $CFG, $USER, $OUTPUT;
  5571. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5572. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5573. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5574. }
  5575. $pathtemp = $CFG->dataroot . '/temp/';
  5576. $contextuser = context_user::instance($USER->id);
  5577. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5578. $zip = new zip_packer();
  5579. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5580. foreach ($files as $file) {
  5581. if (!$file->is_directory())
  5582. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5583. }
  5584. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5585. // Verifica se o pacote possui o XML
  5586. if (!$application_xml) {
  5587. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5588. return;
  5589. } else {
  5590. $missing = "";
  5591. if (!isset($application_xml->name)) {
  5592. $missing .= "name";
  5593. }
  5594. if (!isset($application_xml->version)) {
  5595. $missing .= ", version";
  5596. }
  5597. if (!isset($application_xml->type)) {
  5598. $missing .= ", type";
  5599. }
  5600. if (!isset($application_xml->extension)) {
  5601. $missing .= ", extension";
  5602. }
  5603. if (!isset($application_xml->file_jar)) {
  5604. $missing .= ", file_jar";
  5605. }
  5606. if (!isset($application_xml->file_class)) {
  5607. $missing .= ", file_class";
  5608. }
  5609. if (!isset($application_xml->width)) {
  5610. $missing .= ", width";
  5611. }
  5612. if (!isset($application_xml->height)) {
  5613. $missing .= ", height";
  5614. }
  5615. if (!isset($application_xml->evaluate)) {
  5616. $missing .= ", evaluate";
  5617. }
  5618. if (strlen($missing) > 2) {
  5619. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5620. return;
  5621. }
  5622. }
  5623. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5624. $typec = strtolower($application_xml->type);
  5625. require_once 'ilm_handlers/' . $typec . '.php';
  5626. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5627. return $retorno;
  5628. } // static function new_ilm($itemid)
  5629. /// Function for save in database an iLM edit
  5630. // The above function 'add_edit_copy_ilm(.)' is responsible to provide the iLM data in this form
  5631. // The data stored through 'ilm_handlers/html5.php' (or 'java.php')
  5632. // @param object $param An object with iLM params
  5633. // @calledby settings_ilm.php: ilm_settings::edit_ilm($formdata, $formdata->file);
  5634. static function edit_ilm ($param, $itemid) {
  5635. // Descobrir o tipo de iLM:
  5636. global $DB, $USER, $CFG;
  5637. //D debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); //exit;
  5638. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5639. $pathtemp = $CFG->dataroot . '/temp/';
  5640. $contextuser = context_user::instance($USER->id);
  5641. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5642. $zip = new zip_packer();
  5643. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5644. $files_extract = null;
  5645. foreach ($files as $file) {
  5646. if (!$file->is_directory())
  5647. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5648. }
  5649. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5650. $typec = strtolower($iassign_t->type);
  5651. require_once 'ilm_handlers/' . $typec . '.php';
  5652. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5653. }
  5654. /// Function for register the new iLM (in database and in the directory)
  5655. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5656. // @param object $param An object with iLM params
  5657. static function copy_new_version_ilm ($param) {
  5658. global $DB, $CFG, $USER;
  5659. $itemid = $param->file;
  5660. $pathtemp = $CFG->dataroot . '/temp/';
  5661. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5662. //D echo "pathtemp=$pathtemp<br/>";
  5663. $contextuser = context_user::instance($USER->id);
  5664. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5665. $zip = new zip_packer();
  5666. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5667. $files_extract = null;
  5668. foreach ($files as $file) {
  5669. if (!$file->is_directory())
  5670. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5671. }
  5672. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5673. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5674. $typec = strtolower($iassign_t->type);
  5675. require_once 'ilm_handlers/' . $typec . '.php';
  5676. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5677. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5678. } // static function copy_new_version_ilm($param)
  5679. //VER::
  5680. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5681. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5682. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5683. /// Function for change visibility of iLM
  5684. // @param int $ilm_id Id of iLM
  5685. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5686. static function visible_ilm ($ilm_id, $status) {
  5687. global $DB;
  5688. if ($status == 0)
  5689. $visible = 1;
  5690. else
  5691. $visible = 0;
  5692. $newentry = new stdClass();
  5693. $newentry->id = $ilm_id;
  5694. $newentry->enable = $visible;
  5695. if (!$DB->update_record("iassign_ilm", $newentry))
  5696. error(get_string('error_edit_ilm', 'iassign'));
  5697. }
  5698. /// Function for confirm change default iLM
  5699. // @param int $ilm_id Id of iLM
  5700. // @param int $ilm_parent Id of parent iLM
  5701. // @return string Return with an string for create default page confirmation
  5702. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5703. global $OUTPUT, $DB;
  5704. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5705. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5706. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5707. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5708. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5709. return $return;
  5710. }
  5711. /// Function for change the default iLM
  5712. // @see settings_ilm.php
  5713. // @param int $ilm_id Id of iLM
  5714. // @return int Return Id of default iLM
  5715. static function default_ilm ($ilm_id) {
  5716. global $DB;
  5717. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5718. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5719. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5720. $iassign_ilm_default->id = $iassign_ilm->id;
  5721. $iassign_ilm_default->parent = 0;
  5722. $iassign_ilm->parent = $iassign_ilm_default->id;
  5723. $iassign_ilm->id = 0;
  5724. $iassign_ilm_default->enable = 1;
  5725. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5726. print_error('error_edit_ilm', 'iassign');
  5727. }
  5728. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5729. if (!$inserted) {
  5730. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5731. print_error($msg_error);
  5732. //xx print_error('error_add_ilm', 'iassign');
  5733. }
  5734. return $iassign_ilm_default->id;
  5735. } // static function default_ilm ($ilm_id)
  5736. /// Function for confirm delete iLM
  5737. // @param int $ilm_id Id of iLM
  5738. // @param int $ilm_parent Id of parent iLM
  5739. // @return string Return with an string for create delete page confirmation
  5740. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5741. global $OUTPUT, $DB;
  5742. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5743. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5744. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5745. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5746. }
  5747. /// Function for delete directory where the iLM is allocated.
  5748. // @param string $dirPath
  5749. // @throws InvalidArgumentException
  5750. public static function delete_dir ($dirPath) {
  5751. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5752. $dirPath .= '/';
  5753. }
  5754. $files = glob($dirPath . '*', GLOB_MARK);
  5755. foreach ($files as $file) {
  5756. if (is_dir($file)) {
  5757. ilm_settings::delete_dir($file);
  5758. } else {
  5759. unlink($file);
  5760. }
  5761. }
  5762. rmdir($dirPath);
  5763. }
  5764. /// Function for delete iLM
  5765. // @param int $ilm_id Id of iLM
  5766. // @return int Return Id of parent iLM
  5767. static function delete_ilm ($ilm_id) {
  5768. global $DB;
  5769. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5770. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5771. $typec = strtolower($iassign_ilm->type);
  5772. require_once 'ilm_handlers/' . $typec . '.php';
  5773. $retorno = $typec::delete_ilm($ilm_id);
  5774. return $retorno;
  5775. }
  5776. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5777. // @param int $ilm_id Id of iLM
  5778. static function export_ilm ($ilm_id) {
  5779. global $DB;
  5780. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5781. if (!$iassign_ilm) return; // security debug...
  5782. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5783. $typec = strtolower($iassign_ilm->type);
  5784. if (!$typec) $typec = "html5"; // security debug...
  5785. require_once 'ilm_handlers/' . $typec . '.php';
  5786. $typec::export_ilm($ilm_id);
  5787. } // static function export_ilm($ilm_id)
  5788. //TODO iLM_HTML5 :: //MOOC 2016
  5789. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5790. // @param int $ilm_id Id of iLM
  5791. static function export_update_ilm ($ilm_id) {
  5792. global $DB, $CFG;
  5793. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5794. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5795. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5796. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5797. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5798. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5799. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5800. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5801. $upgrade_descriptor .= '</upgrade>' . "\n";
  5802. file_put_contents($xml_filename, $upgrade_descriptor);
  5803. header("Pragma: public");
  5804. header("Expires: 0");
  5805. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5806. header("Cache-Control: private", false);
  5807. header('Content-Type: application/xml; charset=utf-8');
  5808. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5809. header("Content-Length: " . @filesize($xml_filename));
  5810. set_time_limit(0);
  5811. @readfile("$xml_filename") || die("File not found.");
  5812. unlink($xml_filename);
  5813. exit;
  5814. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5815. /// Function for save iLM from XML descriptor
  5816. // @param array $application_xml Data of XML descriptor
  5817. // @param array $files_extract Filenames of extract files
  5818. // @return array Return an array content id of JAR files
  5819. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5820. global $CFG, $USER;
  5821. // Tratamento diferenciado se for do tipo HTML5:
  5822. $source = "";
  5823. $diretorio = "";
  5824. if (strtolower($application_xml->type) == 'html5') {
  5825. $i = 0;
  5826. foreach ($files_extract as $key => $value) {
  5827. $file = $CFG->dataroot . '/temp/' . $key;
  5828. // Verifica se já existe a pasta no diretório dos iLM:
  5829. if ($i == 0) {
  5830. $source = $file;
  5831. if (file_exists("ilm/" . basename($file))) {
  5832. $j = 1;
  5833. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5834. $j++;
  5835. }
  5836. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5837. // mkdir($diretorio, 0777, true);
  5838. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5839. }
  5840. else {
  5841. $diretorio = 'ilm/' . basename($file);
  5842. // mkdir($diretorio, 0777, true);
  5843. mkdir($diretorio, 0755, true);
  5844. }
  5845. break;
  5846. }
  5847. $i++;
  5848. }
  5849. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5850. if ($item->isDir()) {
  5851. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5852. }
  5853. else {
  5854. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5855. }
  5856. }
  5857. ilm_settings::delete_dir($source);
  5858. return "./" . $diretorio;
  5859. }
  5860. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5861. $file_jar = array();
  5862. $files_ilm = explode(",", $application_xml->file_jar);
  5863. $contextsystem = context_system::instance();
  5864. foreach ($files_ilm as $value) {
  5865. $file_ilm = array(
  5866. 'userid' => $USER->id,
  5867. 'contextid' => $contextsystem->id,
  5868. 'component' => 'mod_iassign',
  5869. 'filearea' => 'ilm',
  5870. 'itemid' => rand(1, 999999999),
  5871. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5872. 'filename' => $value);
  5873. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5874. array_push($file_jar, $file_ilm->get_id());
  5875. }
  5876. foreach ($files_extract as $key => $value) {
  5877. $file = $CFG->dataroot . '/temp/' . $key;
  5878. if (file_exists($file))
  5879. unlink($file);
  5880. }
  5881. return $file_jar;
  5882. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5883. /// Function for import the iLM from an package
  5884. // @param int $itemid Itemid of zip file
  5885. static function import_ilm ($itemid) {
  5886. global $CFG, $USER, $OUTPUT;
  5887. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5888. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5889. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5890. }
  5891. $pathtemp = $CFG->dataroot . '/temp/';
  5892. $contextuser = context_user::instance($USER->id);
  5893. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5894. $zip = new zip_packer();
  5895. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5896. foreach ($files as $file) {
  5897. if (!$file->is_directory())
  5898. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5899. }
  5900. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5901. // Verifica se o pacote possui o XML
  5902. if (!$application_xml) {
  5903. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5904. return;
  5905. } else {
  5906. $missing = "";
  5907. if (!isset($application_xml->name)) {
  5908. $missing .= "name";
  5909. }
  5910. if (!isset($application_xml->version)) {
  5911. $missing .= ", version";
  5912. }
  5913. if (!isset($application_xml->type)) {
  5914. $missing .= ", type";
  5915. }
  5916. if (!isset($application_xml->extension)) {
  5917. $missing .= ", extension";
  5918. }
  5919. if (!isset($application_xml->file_jar)) {
  5920. $missing .= ", file_jar";
  5921. }
  5922. if (!isset($application_xml->file_class)) {
  5923. $missing .= ", file_class";
  5924. }
  5925. if (!isset($application_xml->width)) {
  5926. $missing .= ", width";
  5927. }
  5928. if (!isset($application_xml->height)) {
  5929. $missing .= ", height";
  5930. }
  5931. if (!isset($application_xml->evaluate)) {
  5932. $missing .= ", evaluate";
  5933. }
  5934. if (strlen($missing) > 2) {
  5935. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5936. return;
  5937. }
  5938. }
  5939. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5940. $typec = strtolower($application_xml->type);
  5941. require_once 'ilm_handlers/' . $typec . '.php';
  5942. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5943. } // static function import_ilm($itemid)
  5944. /// Function for list iLM defaults
  5945. // @return string Return an string with a table of iLM
  5946. static function list_ilm () {
  5947. global $DB, $OUTPUT;
  5948. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5949. $str = '';
  5950. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5951. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5952. if ($iassign_ilm) {
  5953. foreach ($iassign_ilm as $ilm) {
  5954. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5955. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5956. $str .= '<tr><td>';
  5957. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5958. $str .= '<tr>';
  5959. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5960. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5961. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5962. $str .= '</tr>';
  5963. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5964. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5965. $str .= '</table>';
  5966. $str .= '</td></tr>';
  5967. }
  5968. }
  5969. $str .= '</table>';
  5970. return $str;
  5971. }
  5972. /// Function for download and install an upgrade of an iLM
  5973. // @param int $ilm_id Id of iLM
  5974. static function upgrade_ilm ($ilm_id) {
  5975. global $DB, $CFG, $USER;
  5976. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5977. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5978. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5979. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5980. if (!$result)
  5981. print_error('error_upgrade_ilm', 'iassign');
  5982. else {
  5983. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5984. $extension = explode(".", $zip_filename);
  5985. if ($extension[count($extension) - 1] != 'ipz') {
  5986. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5987. die;
  5988. }
  5989. $zip = new zip_packer();
  5990. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5991. $contextuser = context_user::instance($USER->id);
  5992. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5993. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5994. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5995. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5996. if (file_exists($zip_filename))
  5997. unlink($zip_filename);
  5998. if (empty($file_jar)) {
  5999. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  6000. print_error($msg_error);
  6001. //xx print_error('error_add_ilm', 'iassign');
  6002. }
  6003. else {
  6004. $newentry = new stdClass();
  6005. $newentry->name = (String) $application_xml->name;
  6006. $newentry->version = (String) $application_xml->version;
  6007. $newentry->url = (String) $application_xml->url;
  6008. $newentry->description = $description_str;
  6009. $newentry->extension = strtolower((String) $application_xml->extension);
  6010. $newentry->file_jar = implode(",", $file_jar);
  6011. $newentry->file_class = (String) $application_xml->file_class;
  6012. $newentry->width = (String) $application_xml->width;
  6013. $newentry->height = (String) $application_xml->height;
  6014. $newentry->enable = 0;
  6015. $newentry->timemodified = time();
  6016. $newentry->author = $USER->id;
  6017. $newentry->timecreated = time();
  6018. $newentry->evaluate = (String) $application_xml->evaluate;
  6019. $newentry->parent = $ilm_id;
  6020. }
  6021. }
  6022. return $iassign_ilm->id;
  6023. } // static function upgrade_ilm($ilm_id)
  6024. //MOOC2014 -- inicio
  6025. //TODO: REVIEW
  6026. // static function confirm_move_iassign($ilmid, $ilm_parent)
  6027. // static function move_iassign($ilm_id)
  6028. //MOOC2014 -- final
  6029. /// Function for list iLM versions with all informations, under "admin" plugin view: .../mod/iassign/settings_ilm.php?action=view&ilm_id=".$ilmid."&from=admin
  6030. // @return string Return an string with a table of iLM
  6031. static function view_ilm ($ilmid, $from) {
  6032. global $DB;
  6033. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  6034. // Get the iLM type and calls its correspondent handler ('Java' or 'HTML5')
  6035. $typec = strtolower($iassign_ilm->type);
  6036. require_once 'ilm_handlers/' . $typec . '.php';
  6037. $retorno = $typec::view_ilm($ilmid, $from);
  6038. return $retorno;
  6039. }
  6040. /// Function for get form variables for add, edit, or copy iLM params
  6041. // @param int $ilm_param_id Id of iLM param
  6042. // @param string $action String with the action
  6043. // @return object Return an object with forms variables
  6044. static function add_edit_copy_param ($ilm_param_id, $action) {
  6045. global $DB;
  6046. require_once('params_form.php');
  6047. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  6048. $param = new stdClass();
  6049. $param->action = $action;
  6050. $param->ilm_param_id = $ilm_param_id;
  6051. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  6052. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  6053. $type = $iassign_ilm_config->param_type;
  6054. if ($action == 'add') {
  6055. $param->title = get_string('add_ilm', 'iassign');
  6056. $param->iassign_ilmid = $ilm_param_id;
  6057. $param->param_name = "";
  6058. $param->param_value = "";
  6059. $param->description = "";
  6060. $param->visible = 1;
  6061. }
  6062. elseif ($action == 'edit') {
  6063. if ($iassign_ilm_config) {
  6064. $param->title = get_string('edit_ilm', 'iassign');
  6065. $param->id = $iassign_ilm_config->id;
  6066. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  6067. $param->param_type = $type; //MOOC2014
  6068. $param->param_name = $iassign_ilm_config->param_name;
  6069. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  6070. $param->param_value = $iassign_ilm_config->param_value;
  6071. else //MOOC2014
  6072. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  6073. $param->param_value = $iassign_ilm_config->param_value;
  6074. $param->description = $iassign_ilm_config->description;
  6075. $param->visible = $iassign_ilm_config->visible;
  6076. }
  6077. }
  6078. elseif ($action == 'copy') {
  6079. if ($iassign_ilm_config) {
  6080. $param->title = get_string('copy_ilm', 'iassign');
  6081. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  6082. $param->param_type = $type; //MOOC2014
  6083. $param->param_name = $iassign_ilm_config->param_name;
  6084. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  6085. $param->param_value = $iassign_ilm_config->param_value;
  6086. else //MOOC2014
  6087. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  6088. $param->description = $iassign_ilm_config->description;
  6089. $param->visible = $iassign_ilm_config->visible;
  6090. }
  6091. }
  6092. return $param;
  6093. } // static function add_edit_copy_param($ilm_param_id, $action)
  6094. /// Function for change visibility of iLM param
  6095. // @param int $ilm_param_id Id of iLM param
  6096. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  6097. static function visible_param ($ilm_param_id, $status) {
  6098. global $DB, $CFG;
  6099. if ($status == 0)
  6100. $visible = 1;
  6101. else
  6102. $visible = 0;
  6103. $newentry = new stdClass();
  6104. $newentry->id = $ilm_param_id;
  6105. $newentry->visible = $visible;
  6106. if (!$DB->update_record("iassign_ilm_config", $newentry))
  6107. error(get_string('error_edit_param', 'iassign'));
  6108. }
  6109. /// Function for save in database an new iLM param
  6110. // @param object $param An object with iLM params
  6111. static function add_param ($param) {
  6112. global $DB;
  6113. $newentry = new stdClass();
  6114. $newentry->iassign_ilmid = $param->iassign_ilmid;
  6115. //MOOC2014 $newentry->param_name = $param->param_name;
  6116. $newentry->param_type = $param->param_type; //MOOC2014
  6117. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  6118. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  6119. $newentry->param_value = $param->param_value;
  6120. else //MOOC2014
  6121. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  6122. $newentry->description = $param->description;
  6123. $newentry->visible = $param->visible;
  6124. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  6125. if (!$newentry->id) {
  6126. print_error('error_add_param', 'iassign');
  6127. }
  6128. }
  6129. /// Function for save in database a iLM param edit
  6130. // @param object $param An object with iLM params
  6131. static function edit_param ($param) {
  6132. global $DB;
  6133. $updentry = new stdClass();
  6134. $updentry->id = $param->id;
  6135. $updentry->iassign_ilmid = $param->iassign_ilmid;
  6136. $updentry->param_type = $param->param_type; //MOOC2014
  6137. // $updentry->param_name = $param->param_name;
  6138. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  6139. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  6140. $updentry->param_value = $param->param_value;
  6141. else //MOOC2014
  6142. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  6143. $updentry->description = $param->description;
  6144. $updentry->visible = $param->visible;
  6145. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  6146. error(get_string('error_edit_param', 'iassign'));
  6147. }
  6148. }
  6149. /// Function for save in database a iLM param copy
  6150. // @param object $param An object with iLM params
  6151. static function copy_param ($param) {
  6152. global $DB;
  6153. $newentry = new stdClass();
  6154. $newentry->iassign_ilmid = $param->iassign_ilmid;
  6155. //$newentry->param_name = $param->param_name;
  6156. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  6157. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  6158. $newentry->param_value = $param->param_value;
  6159. else //MOOC2014
  6160. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  6161. $newentry->description = $param->description;
  6162. $newentry->visible = $param->visible;
  6163. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  6164. if (!$newentry->id) {
  6165. print_error('error_add_param', 'iassign');
  6166. }
  6167. }
  6168. /// Function for delete iLM param of database
  6169. // @param int $param_id Id of iLM param
  6170. static function delete_param ($param_id) {
  6171. global $DB;
  6172. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  6173. print_error('error_delete_param', 'iassign');
  6174. }
  6175. }
  6176. } // class ilm_settings
  6177. /// Class for manage iLM files (editor).
  6178. class ilm_manager {
  6179. var $id; // course id
  6180. var $url;
  6181. var $from;
  6182. /// Constructor for the base ilm_manager class
  6183. // 3.1 update PHP 7.0 compatibility for all moodle versions
  6184. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  6185. function __construct ($id, $url, $from) {
  6186. $this->id = $id; // course id
  6187. $this->url = $url;
  6188. $this->from = $from;
  6189. }
  6190. /// Function to get iAssign content file in Moodle data (exercise)
  6191. // @calledby x function preview_ilm($iassign_ilm) :
  6192. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  6193. function get_file_ilm () {
  6194. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6195. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6196. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  6197. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6198. $md_file = $fs->get_file_by_id($fileid);
  6199. $ilm_content_file = $md_file->get_content();
  6200. return $ilm_content_file;
  6201. }
  6202. /// Function for creating a new file from the iLM online editor
  6203. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  6204. function ilm_editor_new () {
  6205. global $CFG, $DB, $OUTPUT, $PAGE;
  6206. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6207. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6208. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6209. $context = context_course::instance($this->id);
  6210. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6211. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  6212. if (!$iassign) {
  6213. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  6214. die();
  6215. }
  6216. $temp = explode(",", $iassign->extension);
  6217. $extension = $temp[0]; // default extension for this iLM
  6218. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  6219. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6220. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  6221. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  6222. if ($stringArchiveContent != NULL) {
  6223. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  6224. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6225. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  6226. $filename = optional_param('filename', NULL, PARAM_RAW);
  6227. //Leo $filename = iassign_utils::format_filename($filename); //
  6228. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  6229. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  6230. //2019/02 $arrayfilename = explode(".", $filename);
  6231. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  6232. //2019/02 $count_dots = count($arrayfilename);
  6233. //2019/02 if ($count_dots > 0) { // at least one dot mark
  6234. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  6235. //2019/02 if ($last_name != $extension)
  6236. //2019/02 $filename = $filename . '.' . $extension;
  6237. //2019/02 }
  6238. //2019/02 else { // no extension...
  6239. //2019/02 $filename = $filename . '.' . $extension;
  6240. //2019/02 }
  6241. // Store the name of recent created file
  6242. $_SESSION['file_name'] = $filename;
  6243. //$this->write_file_iassign($string, $filename);
  6244. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  6245. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  6246. die();
  6247. }
  6248. else { // if ($stringArchiveContent != NULL)
  6249. // iLM On-line editor
  6250. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6251. $str_get_iLM = "window.frames.iLM";
  6252. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6253. }
  6254. else { // otherwise it is JAR named 'iLM'
  6255. $str_get_iLM = "document.iLM";
  6256. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6257. }
  6258. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6259. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  6260. $files_array = '';
  6261. foreach ($files as $value) {
  6262. if ($value->get_filename() != ".")
  6263. $files_array .= "'" . $value->get_filename() . "',";
  6264. }
  6265. $files_array .= "''";
  6266. $file = null;
  6267. $ia_content = "";
  6268. $filename = "";
  6269. $error_files_exists = get_string('error_file_exists', 'iassign');
  6270. $output = "<script type='text/javascript'>
  6271. //<![CDATA[
  6272. //D alert('locallib.php: ilm_editor_new');
  6273. function submit_iLM_Answer () {
  6274. var docFormOnLineEditor = document.formEnvio;
  6275. var resposta_exerc = new Array(3);
  6276. var valor_resposta = new Array(3);
  6277. var sessao = new Array(3);
  6278. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6279. resposta_exerc[0] = doc_iLM.getAnswer();
  6280. valor_resposta[0] = doc_iLM.getEvaluation();
  6281. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  6282. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  6283. var files = new Array(" . $files_array . ");
  6284. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  6285. if (docFormOnLineEditor.filename.value=='') {
  6286. // ERROR: the file name is empty
  6287. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  6288. return false;
  6289. }
  6290. // }
  6291. for (i=0; i<files.length; i++) {
  6292. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  6293. alert('" . $error_files_exists . "');
  6294. return false;
  6295. }
  6296. }
  6297. docFormOnLineEditor.submit();
  6298. return true;
  6299. }
  6300. //]]>
  6301. </script>\n";
  6302. $output .= "
  6303. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6304. $output .= $OUTPUT->box_start();
  6305. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  6306. $output .= "
  6307. <table width='100%' cellpadding='20'>
  6308. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  6309. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  6310. </tr>
  6311. </table>\n";
  6312. $output .= $OUTPUT->box_end();
  6313. $output .= "<center>\n";
  6314. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  6315. // Since it is the activity file, it is not necessary to use 'ilm_security'
  6316. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  6317. $output .= $output_ilm;
  6318. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  6319. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  6320. </center>
  6321. </form>\n";
  6322. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6323. $PAGE->navbar->add($title);
  6324. $PAGE->set_title($title);
  6325. $PAGE->set_heading($title); // insert title above the navigation bar
  6326. print $OUTPUT->header();
  6327. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6328. print $output;
  6329. print $OUTPUT->footer();
  6330. }
  6331. die();
  6332. } // function ilm_editor_new()
  6333. /// Function for editing an file in online editor
  6334. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  6335. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  6336. global $CFG, $DB, $OUTPUT, $PAGE;
  6337. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6338. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6339. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6340. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6341. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6342. // If iLM is not registered, error!
  6343. if (!$iassign) {
  6344. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  6345. die;
  6346. }
  6347. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  6348. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  6349. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  6350. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  6351. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6352. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6353. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  6354. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  6355. if ($stringArchiveContent != NULL) {
  6356. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  6357. die();
  6358. } else { // if ($stringArchiveContent != NULL)
  6359. $end_file = '';
  6360. if ($content_file) {
  6361. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  6362. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  6363. }
  6364. $temp = explode(",", $iassign->extension);
  6365. $extension = $temp[0]; // default extension for this iLM
  6366. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6367. $str_get_iLM = "window.frames.iLM";
  6368. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6369. } else { // otherwise it is JAR named 'iLM'
  6370. $str_get_iLM = "document.iLM";
  6371. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6372. }
  6373. $output = "<script type='text/javascript'>
  6374. //<![CDATA[
  6375. function submit_iLM_Answer () {
  6376. var docFormEditor = document.formEnvio;
  6377. var activityAnswer; // to get activity answer (text)
  6378. var activityValue; // to get activity answer value (float)
  6379. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6380. //activityAnswer = doc_iLM.getAnswer();
  6381. //activityValue = doc_iLM.getEvaluation();
  6382. activityAnswer = " . $str_get_iLM . ".getAnswer();
  6383. activityValue = " . $str_get_iLM . ".getEvaluation();
  6384. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  6385. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  6386. docFormEditor.submit();
  6387. return true;
  6388. }
  6389. //]]>
  6390. </script>\n";
  6391. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  6392. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  6393. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  6394. // return true;
  6395. // }
  6396. $output .= "
  6397. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6398. $output .= $OUTPUT->box_start();
  6399. $output .= "
  6400. <table width='100%' cellpadding='20'>
  6401. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  6402. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  6403. <input type='hidden' name='filename' value='$filename'/></td>
  6404. <td>
  6405. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  6406. </tr>
  6407. </table>\n";
  6408. $output .= $OUTPUT->box_end();
  6409. $output .= " <center>\n";
  6410. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  6411. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  6412. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  6413. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  6414. </center>
  6415. </form>\n";
  6416. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6417. $PAGE->navbar->add($title);
  6418. $PAGE->set_title($title);
  6419. $PAGE->set_heading($title); // insert title above the navigation bar
  6420. print $OUTPUT->header();
  6421. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6422. print $output;
  6423. print $OUTPUT->footer();
  6424. } // else if ($stringArchiveContent != NULL)
  6425. die();
  6426. } // function ilm_editor_update()
  6427. /// Function for write iAssign file in Moodle data (exercise)
  6428. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  6429. // @param string $stringArchiveContent Content of iassign file
  6430. // @param string $filename Filename of iassign file
  6431. function write_file_iassign ($stringArchiveContent, $filename) {
  6432. global $USER;
  6433. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6434. $context = context_course::instance($this->id);
  6435. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6436. $dirid = $this->get_dir_ilm('dirid');
  6437. $dir = $fs->get_file_by_id($dirid);
  6438. $fileinfo = array('contextid' => $context->id, // ID of course
  6439. 'component' => 'mod_iassign', // usually = table name
  6440. 'filearea' => 'activity', // usually = table name
  6441. 'itemid' => 0, // usually = ID of row in table
  6442. 'filepath' => '/', // any path beginning and ending whith '/'
  6443. 'userid' => $USER->id,
  6444. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6445. 'filename' => $filename); // any filename
  6446. // Create file containing text. '$stringArchiveContent'
  6447. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6448. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  6449. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  6450. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  6451. // 'Activité interactive enregistrée avec succès sous le nom:';
  6452. // 'Atividade interativa gravada com sucesso sob o nome:'
  6453. $output = "
  6454. <script type='text/javascript'>
  6455. //<![CDATA[
  6456. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  6457. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6458. //]]>
  6459. </script>";
  6460. print $output;
  6461. die();
  6462. }
  6463. /// Function for write iAssign file in Moodle data (exercise)
  6464. // @param string $stringArchiveContent Content of iassign file
  6465. // @param string $filename Filename of iassign file
  6466. // @param int $itemid Itemid of iassign file
  6467. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  6468. global $OUTPUT, $USER;
  6469. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6470. $context = context_course::instance($this->id);
  6471. $dirid = $this->get_dir_ilm('dirid');
  6472. if ($stringArchiveContent != (-1)) {
  6473. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6474. $file = $fs->get_file_by_id($fileid);
  6475. if (!$file) {
  6476. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  6477. die;
  6478. }
  6479. $fileinfo = array('contextid' => $context->id, // ID of context
  6480. 'component' => 'mod_iassign', // usually = table name
  6481. 'filearea' => 'activity', // usually = table name
  6482. 'itemid' => 0, // usually = ID of row in table
  6483. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  6484. 'userid' => $USER->id,
  6485. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6486. 'license' => 'allrightsreserved', // allrightsreserved
  6487. 'timecreated' => $file->get_timecreated(),
  6488. 'filename' => $file->get_filename()); // any filename
  6489. $file->delete();
  6490. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6491. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  6492. }
  6493. $output = "<script type='text/javascript'>
  6494. //<![CDATA[
  6495. alert('" . get_string('sucess_update', 'iassign') . "');\n
  6496. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6497. //]]>
  6498. </script>";
  6499. print $output;
  6500. die();
  6501. }
  6502. /// Function for create an tag for iAssign filter
  6503. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  6504. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6505. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  6506. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6507. // @param int $fileid Id of file
  6508. // @return string Return an string with an tag of iassign filter
  6509. function tag_ilm ($fileid) {
  6510. global $DB;
  6511. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6512. $width = '600';
  6513. $height = '400';
  6514. $file = $fs->get_file_by_id($fileid);
  6515. $filetype = explode(".", $file->get_filename());
  6516. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  6517. foreach ($iassign_ilm as $value) {
  6518. $extensions = explode(",", $value->extension);
  6519. if (in_array($filetype[1], $extensions)) {
  6520. $width = $value->width;
  6521. $height = $value->height;
  6522. }
  6523. }
  6524. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  6525. }
  6526. /// Function for delete iAssign file in Moodle data (exercise)
  6527. function delete_file_ilm () {
  6528. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6529. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6530. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  6531. $file = $fs->get_file_by_id($fileid);
  6532. if ($file)
  6533. $file->delete();
  6534. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6535. die();
  6536. }
  6537. /// Function for delete selected iAssign file in Moodle data (exercise)
  6538. function delete_selected_ilm () {
  6539. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6540. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6541. $context = context_course::instance($this->id);
  6542. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6543. $dirid = $this->get_dir_ilm('dirid');
  6544. foreach ($files_id as $file_id) {
  6545. $file = $fs->get_file_by_id($file_id);
  6546. if ($file) {
  6547. if (!$file->is_directory())
  6548. $file->delete();
  6549. else {
  6550. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6551. foreach ($files_delete as $value)
  6552. $value->delete();
  6553. $file->delete();
  6554. }
  6555. }
  6556. }
  6557. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6558. die();
  6559. }
  6560. /// Function for duplicate iAssign file from "online" edition
  6561. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  6562. function duplicate_file_ilm () {
  6563. global $USER, $COURSE;
  6564. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6565. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6566. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6567. $filename = optional_param('filename', NULL, PARAM_RAW);
  6568. $file = $fs->get_file_by_id($fileid);
  6569. $context = context_course::instance($this->id);
  6570. $fileinfo = array(
  6571. 'contextid' => $context->id, // ID of context
  6572. 'component' => 'mod_iassign', // usually = table name
  6573. 'filearea' => 'activity', // usually = table name
  6574. 'itemid' => 0, // usually = ID of row in table
  6575. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  6576. 'userid' => $USER->id,
  6577. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6578. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  6579. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  6580. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  6581. die();
  6582. }
  6583. /// Function for rename iAssign file
  6584. function rename_file_ilm () {
  6585. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6586. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6587. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6588. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6589. $file = $fs->get_file_by_id($fileid);
  6590. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  6591. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  6592. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6593. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  6594. die();
  6595. }
  6596. /// Function for get iassign file for iassign form
  6597. function add_ilm () {
  6598. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6599. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6600. $output = "
  6601. <script type='text/javascript'>
  6602. //<![CDATA[
  6603. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  6604. iassign_file_link.innerHTML = '$filename';
  6605. window.opener.document.forms['mform1'].file.value='$fileid';
  6606. window.opener.document.forms['mform1'].filename.value='$filename';
  6607. window.close();
  6608. //]]>
  6609. </script>";
  6610. print $output;
  6611. die();
  6612. }
  6613. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  6614. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  6615. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  6616. function preview_ilm ($courseid, $iassign_ilm) {
  6617. global $OUTPUT, $CFG, $USER;
  6618. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6619. $title = get_string('modulename', 'iassign'); // iAssign
  6620. print $OUTPUT->header();
  6621. print $OUTPUT->box_start();
  6622. $javascript = "
  6623. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  6624. <script type='text/javascript'>
  6625. //<![CDATA[
  6626. function submit_close () {
  6627. window.opener.location.reload();
  6628. window.close();
  6629. }
  6630. //]]>
  6631. </script>\n";
  6632. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6633. // to the complete "applet" tag
  6634. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6635. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6636. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6637. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6638. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6639. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6640. if ($ilm_name != "ivprog") {
  6641. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6642. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6643. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6644. } else {
  6645. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6646. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6647. $timecreated = time();
  6648. $token = md5($timecreated);
  6649. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6650. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6651. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6652. $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)
  6653. }
  6654. $html = "
  6655. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6656. <table border='1'>
  6657. <tr><td>
  6658. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6659. <!-- iLM calls : end -->
  6660. </td></tr>
  6661. </table>
  6662. <table>
  6663. <tr>
  6664. <td align='center'>
  6665. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6666. </td></tr>
  6667. </table>
  6668. </form>\n";
  6669. print $javascript . $html;
  6670. print $OUTPUT->box_end();
  6671. //NAO echo format_string($html); // Moodle 3.X
  6672. die();
  6673. } // function preview_ilm($courseid, $iassign_ilm)
  6674. //r_ function preview_ilm ($iassign_ilm)
  6675. //r_ /// Function for preview iassign file from iassign filter.
  6676. //r_ function preview_ilm() {
  6677. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6678. //r_ $tag_filter = $this->tag_ilm($fileid);
  6679. //r_ $javascript = "<script type='text/javascript'>
  6680. //r_ //<![CDATA[
  6681. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6682. //r_ //]]>
  6683. //r_ </script>";
  6684. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6685. //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>
  6686. //r_ </table></form></body></html>";
  6687. //r_ echo $javascript . format_text($html);
  6688. //r_ die;
  6689. //r_ }
  6690. /// Function for export an package (zip) of iassign files
  6691. function export_files_ilm () {
  6692. global $CFG;
  6693. $context = context_course::instance($this->id);
  6694. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6695. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6696. $zip = new zip_archive();
  6697. $zip->open($zip_filename);
  6698. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6699. foreach ($files_id as $file_id) {
  6700. $file = $fs->get_file_by_id($file_id);
  6701. if (!$file->is_directory())
  6702. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6703. else {
  6704. $zip->add_directory($file->get_filepath());
  6705. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6706. foreach ($files_zip as $value) {
  6707. if (!$value->is_directory())
  6708. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6709. else
  6710. $zip->add_directory($value->get_filepath());
  6711. }
  6712. }
  6713. }
  6714. $zip->close();
  6715. header("Pragma: public");
  6716. header("Expires: 0");
  6717. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6718. header("Cache-Control: private", false);
  6719. header("Content-Type: application/zip");
  6720. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6721. header("Content-Transfer-Encoding: binary");
  6722. header("Content-Length: " . @filesize($zip_filename));
  6723. set_time_limit(0);
  6724. @readfile("$zip_filename") || die("File not found.");
  6725. unlink($zip_filename);
  6726. exit;
  6727. }
  6728. /// Function of execute a command in button editor tinymce
  6729. // @param int $fileid Id of file
  6730. function tinymce_ilm ($fileid) {
  6731. $tag_filter = $this->tag_ilm($fileid);
  6732. $output = "<script type='text/javascript'>
  6733. //<![CDATA[
  6734. var tag_filter = '$tag_filter';
  6735. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6736. // all right, insert it
  6737. } else {
  6738. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6739. }
  6740. // window.close();
  6741. //]]>
  6742. </script>\n";
  6743. print $output;
  6744. die();
  6745. }
  6746. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6747. /// Function to add content to the Editor Window
  6748. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6749. // @param int $fileid Id of file
  6750. function editor_ilm ($fileid, $editor) {
  6751. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6752. $output1 = "<script type='text/javascript'>
  6753. //<![CDATA[
  6754. var tag_filter = '$tag_filter';\n";
  6755. if ($editor == 'atto') {
  6756. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6757. } elseif ($editor == 'tinyMCE') {
  6758. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6759. } else
  6760. $output2 = "";
  6761. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6762. window.close();
  6763. //]]>
  6764. </script>\n";
  6765. //D var_dump($output);
  6766. print $output1 . $output2 . $output3;
  6767. die();
  6768. }
  6769. /// Function to add content to the Atto Editor Window
  6770. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6771. // @param int $fileid Id of file
  6772. function atto_ilm ($fileid) {
  6773. global $CFG, $DB;
  6774. $tag_filter = $this->tag_ilm($fileid);
  6775. $output = "<script type='text/javascript'>
  6776. //<![CDATA[
  6777. var tag_filter = '$tag_filter';
  6778. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6779. // all right, insert iLM tag to this editor
  6780. } else {
  6781. // error trying to insert
  6782. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6783. }
  6784. //window.close();
  6785. //]]>
  6786. </script>\n";
  6787. print $output;
  6788. die();
  6789. }
  6790. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6791. // @param string $key Key for return information
  6792. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6793. function get_dir_ilm ($key) {
  6794. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6795. $context = context_course::instance($this->id);
  6796. $dirid = optional_param('dirid', 0, PARAM_INT);
  6797. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6798. if ($dirid == 0) {
  6799. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6800. $dirid = $dir->get_id();
  6801. }
  6802. else {
  6803. $dir = $fs->get_file_by_id($dirid);
  6804. $dir_base = $dir->get_filepath();
  6805. }
  6806. $dir_parent = $dir->get_parent_directory();
  6807. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6808. return $data[$key];
  6809. }
  6810. /// Function for create an new dir
  6811. function new_dir_ilm () {
  6812. global $USER;
  6813. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6814. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6815. $dir_base = $this->get_dir_ilm('dir_base');
  6816. $context = context_course::instance($this->id);
  6817. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6818. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6819. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6820. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6821. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6822. }
  6823. /// Function for delete an dir
  6824. function delete_dir_ilm () { //
  6825. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6826. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6827. $context = context_course::instance($this->id);
  6828. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6829. $dir_parent = $this->get_dir_ilm('dir_parent');
  6830. if ($dir) {
  6831. if ($dir->is_directory()) {
  6832. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6833. foreach ($files_delete as $value)
  6834. $value->delete();
  6835. $dir->delete();
  6836. }
  6837. }
  6838. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6839. die();
  6840. }
  6841. /// Function for rename an dir
  6842. function rename_dir_ilm () {
  6843. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6844. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6845. $context = context_course::instance($this->id);
  6846. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6847. $dir_parent = $this->get_dir_ilm('dir_parent');
  6848. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6849. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6850. if ($dir->is_directory()) {
  6851. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6852. foreach ($files_rename_path as $value)
  6853. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6854. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6855. }
  6856. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6857. die();
  6858. }
  6859. /// Function for move an dir and your content for other dir
  6860. function selected_move_ilm () {
  6861. global $PAGE, $OUTPUT, $CFG;
  6862. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6863. $context = context_course::instance($this->id);
  6864. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6865. $dirid = $this->get_dir_ilm('dirid');
  6866. $dir_base = $this->get_dir_ilm('dir_base');
  6867. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6868. $code_javascript_ilm = "
  6869. <script type='text/javascript'>
  6870. //<![CDATA[
  6871. function getRadiobutton () {
  6872. var radioButtons = document.getElementsByTagName('input');
  6873. var param = '';
  6874. for (var counter=0; counter < radioButtons.length; counter++) {
  6875. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6876. param = radioButtons[counter].value;
  6877. }
  6878. return param;
  6879. }
  6880. function move_selected_ilm () {
  6881. var msgAnswer;
  6882. if (getRadiobutton() != '') {
  6883. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6884. if (msgAnswer)
  6885. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6886. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6887. }
  6888. else
  6889. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6890. }
  6891. function cancel_selected_ilm () {
  6892. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6893. }
  6894. //]]>
  6895. </script>\n";
  6896. $title = get_string('move_files', 'iassign');
  6897. $PAGE->set_title($title);
  6898. $PAGE->set_pagelayout('base');
  6899. print $OUTPUT->header();
  6900. print $OUTPUT->heading($title);
  6901. $dir_paths = array();
  6902. print $OUTPUT->box_start();
  6903. print "<center>";
  6904. foreach ($files_id as $file_id) {
  6905. $file = $fs->get_file_by_id($file_id);
  6906. if ($file) {
  6907. if (!$file->is_directory())
  6908. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6909. else {
  6910. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6911. array_push($dir_paths, $file->get_filepath());
  6912. }
  6913. }
  6914. }
  6915. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6916. if ($dir_base != '/') {
  6917. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6918. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6919. }
  6920. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6921. foreach ($files_tree as $file) {
  6922. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6923. $is_parent = false;
  6924. foreach ($dir_paths as $dir) {
  6925. $path = explode("/", $dir);
  6926. array_pop($path);
  6927. $path[count($path) - 1] = '';
  6928. $path = implode("/", $path);
  6929. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6930. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6931. }
  6932. if ($is_parent == false) {
  6933. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6934. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6935. }
  6936. }
  6937. }
  6938. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6939. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6940. print "</center>";
  6941. print $OUTPUT->box_end();
  6942. print $OUTPUT->footer();
  6943. print $code_javascript_ilm;
  6944. die;
  6945. }
  6946. /// Function for move files for an dir
  6947. function move_files_ilm () {
  6948. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6949. $context = context_course::instance($this->id);
  6950. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6951. $dirid = $this->get_dir_ilm('dirid');
  6952. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6953. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6954. foreach ($files_id as $file_id) {
  6955. $file = $fs->get_file_by_id($file_id);
  6956. if ($file) {
  6957. if ($file->is_directory()) {
  6958. $pathname = explode("/", $file->get_filepath());
  6959. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6960. foreach ($files_move_path as $value) {
  6961. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6962. $value->rename($path_move, $value->get_filename());
  6963. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6964. }
  6965. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6966. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6967. $file->rename($path_move, $file->get_filename());
  6968. } else {
  6969. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6970. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6971. }
  6972. }
  6973. }
  6974. //die;
  6975. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6976. die();
  6977. } // function move_files_ilm()
  6978. /// Function for recover files in use on all activities of a course
  6979. function recover_files_ilm () {
  6980. global $DB, $USER;
  6981. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6982. $courseid = optional_param('id', NULL, PARAM_INT);
  6983. $dirid = $this->get_dir_ilm('dirid');
  6984. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6985. $contextfile = context_course::instance($this->id);
  6986. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6987. foreach ($iassigns as $iassign) {
  6988. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6989. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6990. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6991. $context = context_module::instance($cm->id);
  6992. // Before associtaion 'files.id' with 'iassign_statement.iassign_ilmid': $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6993. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
  6994. if ($files) {
  6995. foreach ($files as $value) {
  6996. $extension = explode(".", $value->get_filename());
  6997. if (!$value->is_directory()) {
  6998. $fileinfo = array('contextid' => $contextfile->id,
  6999. 'component' => 'mod_iassign',
  7000. 'filearea' => 'activity',
  7001. 'itemid' => 0,
  7002. 'filepath' => $this->get_dir_ilm('dir_base'),
  7003. 'userid' => $USER->id,
  7004. 'author' => $USER->firstname . ' ' . $USER->lastname,
  7005. 'license' => 'allrightsreserved',
  7006. 'timecreated' => time(),
  7007. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  7008. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  7009. }
  7010. }
  7011. } // if ($files)
  7012. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  7013. } // foreach ($iassigns as $iassign)
  7014. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  7015. die();
  7016. } // function recover_files_ilm()
  7017. /// Auxiliary function the get all files in a given context
  7018. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  7019. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  7020. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  7021. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  7022. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  7023. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  7024. // (NAO s_iassign_statement.file = s_files.id)
  7025. $fs = get_file_storage(); // Get reference to all files in Moodle data
  7026. $dir_base = $this->get_dir_ilm('dir_base');
  7027. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  7028. $countf = 0;
  7029. $array_files_id = array(); // all files from this context
  7030. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  7031. //$filename = $item_fc->get_filename();
  7032. //$filepath = $item_fc->get_filepath();
  7033. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  7034. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  7035. // $array_files_aux[] = $item_fc;
  7036. $itemid = $item_fc->get_id();
  7037. if (!in_array($itemid, $array_files_id)) {
  7038. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  7039. if ($fileuserid == $userid)
  7040. $filesfrommine[] = $item_fc;
  7041. else
  7042. $filesfromothers[] = $item_fc;
  7043. $array_files_id[] = $itemid;
  7044. $countf++;
  7045. }
  7046. }
  7047. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  7048. return $countf;
  7049. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  7050. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  7051. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  7052. function get_all_ilm_files_by_fileid ($fileid) {
  7053. global $DB, $USER;
  7054. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  7055. //TODO Criar coluna 'authorid'
  7056. $str_query = "SELECT * FROM {iassign_statement} WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  7057. $array_iassign_ilm = $DB->get_records_sql($str_query);
  7058. return $array_iassign_ilm;
  7059. }
  7060. //NN
  7061. //NN
  7062. // Build string with JavaScript code with function to edit/remove/double iLM files
  7063. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  7064. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  7065. global $CFG;
  7066. $error_files_exists = get_string('error_file_exists', 'iassign');
  7067. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  7068. $code_javascript_ilm = "
  7069. <script type='text/javascript'>
  7070. //<![CDATA[
  7071. function preview_ilm (fileid, ilmid) { //JavaScript function
  7072. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  7073. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  7074. }
  7075. function update_ilm (ilmid, fileid) { //JavaScript function
  7076. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7077. }
  7078. function delete_ilm (ilmid, fileid) { //JavaScript function
  7079. var msgAnswer;
  7080. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  7081. if (msgAnswer) {
  7082. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7083. }
  7084. }
  7085. function delete_selected_ilm () { //JavaScript function
  7086. var msgAnswer;
  7087. var param = getCheckbox();
  7088. if (param.join() != '') {
  7089. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  7090. if (msgAnswer)
  7091. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  7092. }
  7093. else
  7094. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  7095. }
  7096. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  7097. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  7098. }
  7099. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  7100. var filenamecopy;
  7101. var i;
  7102. var files = new Array(" . $files_array . ");
  7103. do {
  7104. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  7105. } while (filenamecopy == '');
  7106. if (filenamecopy == null)
  7107. return false;\n
  7108. else {
  7109. for (i=0;i<files.length;i++) {
  7110. if (files[i]==filenamecopy) {
  7111. alert('" . $error_files_exists . "');
  7112. return false;\n
  7113. }
  7114. }\n" .
  7115. // @see: function 'duplicate_file_ilm()' above
  7116. "
  7117. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  7118. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  7119. } // else
  7120. }
  7121. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  7122. var filenamecopy;
  7123. var i;
  7124. var files = new Array($files_array);
  7125. do {
  7126. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  7127. } while (filenamecopy == '');
  7128. if (filenamecopy == null)
  7129. return false;
  7130. else {
  7131. for (i=0;i<files.length;i++) {
  7132. if (files[i]==filenamecopy) {
  7133. alert('" . $error_files_exists . "');
  7134. return false;
  7135. }
  7136. }
  7137. 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;
  7138. }
  7139. }
  7140. function export_files_ilm () { //JavaScript function
  7141. var param = getCheckbox();
  7142. if (param.join() != '')
  7143. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  7144. else
  7145. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  7146. }
  7147. function select_all_ilm () { //JavaScript function
  7148. var checkBoxes = document.getElementsByTagName('input');
  7149. var selectAll = document.getElementById('select_all');
  7150. for (var counter=0; counter < checkBoxes.length; counter++) {
  7151. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  7152. checkBoxes[counter].checked = selectAll.checked;
  7153. }
  7154. }
  7155. function getCheckbox () { //JavaScript function
  7156. var checkBoxes = document.getElementsByTagName('input');
  7157. var param = new Array();
  7158. for (var counter=0; counter < checkBoxes.length; counter++) {
  7159. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  7160. param.push(checkBoxes[counter].value);
  7161. }
  7162. return param;
  7163. }
  7164. function new_dir_ilm () { //JavaScript function
  7165. var dirname = '';
  7166. var i;
  7167. var dirs = new Array(" . $dirs_array . ");
  7168. do {
  7169. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  7170. } while (dirname == '');
  7171. if (dirname == null)
  7172. return false;\n
  7173. else {
  7174. for (i=0;i<dirs.length;i++) {
  7175. if (dirs[i]==dirname) {
  7176. alert('" . $error_dir_exists . "');
  7177. return false;\n
  7178. }
  7179. }
  7180. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  7181. }
  7182. }
  7183. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  7184. var msgAnswer;
  7185. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7186. if (msgAnswer) {
  7187. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7188. }
  7189. }
  7190. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  7191. var dirnamecopy;
  7192. var i;
  7193. var dirs = new Array($dirs_array);
  7194. do {
  7195. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7196. } while (dirnamecopy == '');
  7197. if (dirnamecopy == null)
  7198. return false;\n
  7199. else {
  7200. for (i=0;i<dirs.length;i++) {
  7201. if (dirs[i]==dirnamecopy) {
  7202. alert('" . $error_dir_exists . "');
  7203. return false;\n
  7204. }
  7205. }
  7206. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7207. }
  7208. }
  7209. function move_selected_ilm (ilmid) { //JavaScript function
  7210. var param = getCheckbox();
  7211. if (param.join() != '')
  7212. 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();
  7213. else
  7214. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7215. }
  7216. function recover_files_ilm () { //JavaScript function
  7217. var msgAnswer;
  7218. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7219. if (msgAnswer) {
  7220. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7221. }
  7222. }
  7223. window.onload = function() { //JavaScript function
  7224. var xPosition = 0;
  7225. var yPosition = 0;
  7226. element=document.getElementById('new_file');
  7227. while(element) {
  7228. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7229. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7230. element = element.offsetParent;
  7231. }
  7232. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7233. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7234. location.hash = '#new_file';
  7235. };
  7236. //]]>
  7237. </script>\n"; // end of $code_javascript_ilm
  7238. return $code_javascript_ilm;
  7239. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  7240. /// List iassign files from course directory
  7241. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  7242. function view_files_ilm ($iassign_ilm_class, $extension) {
  7243. global $CFG, $DB, $USER, $OUTPUT;
  7244. $fs = get_file_storage();
  7245. $context = context_course::instance($this->id);
  7246. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  7247. $dirid = $this->get_dir_ilm('dirid');
  7248. $dir_base = $this->get_dir_ilm('dir_base');
  7249. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  7250. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  7251. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  7252. $files_array = '';
  7253. foreach ($files_course as $value) {
  7254. if (!$value->is_directory())
  7255. $files_array .= "'" . $value->get_filename() . "',";
  7256. }
  7257. $files_array .= "''";
  7258. $error_files_exists = get_string('error_file_exists', 'iassign');
  7259. $dirs_array = '';
  7260. foreach ($files_course as $value) {
  7261. if ($value->is_directory()) {
  7262. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  7263. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  7264. }
  7265. }
  7266. $dirs_array .= "''";
  7267. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  7268. //TODO: Rever o 'preview', pois so' apresenta uma vez!
  7269. $code_javascript_ilm = "
  7270. <script type='text/javascript'>
  7271. //<![CDATA[
  7272. function preview_ilm (fileid, ilmid) {
  7273. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  7274. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  7275. }
  7276. function update_ilm (ilmid, fileid) {
  7277. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7278. }
  7279. function delete_ilm (ilmid, fileid) {
  7280. var msgAnswer;
  7281. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  7282. if (msgAnswer) {
  7283. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7284. }
  7285. }
  7286. function delete_selected_ilm () {
  7287. var msgAnswer;
  7288. var param = getCheckbox();
  7289. if (param.join() != '') {
  7290. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  7291. if (msgAnswer)
  7292. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  7293. }
  7294. else
  7295. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  7296. }
  7297. function add_ilm_iassign (ilmid, filename, fileid) {
  7298. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  7299. }
  7300. function duplicate_ilm (ilmid, filename, fileid) {
  7301. var filenamecopy;
  7302. var i;
  7303. var files = new Array($files_array);
  7304. do {
  7305. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  7306. } while (filenamecopy == '');
  7307. if (filenamecopy == null)
  7308. return false;\n
  7309. else {
  7310. for (i=0;i<files.length;i++) {
  7311. if (files[i]==filenamecopy) {
  7312. alert('$error_files_exists');
  7313. return false;\n
  7314. }
  7315. }\n" .
  7316. // @see: function 'duplicate_file_ilm()' above
  7317. "
  7318. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  7319. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  7320. } // else
  7321. }
  7322. function rename_ilm (ilmid, filename, fileid) {
  7323. var filenamecopy;
  7324. var i;
  7325. var files = new Array($files_array);
  7326. do {
  7327. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  7328. } while (filenamecopy == '');
  7329. if (filenamecopy == null)
  7330. return false;
  7331. else {
  7332. for (i=0;i<files.length;i++) {
  7333. if (files[i]==filenamecopy) {
  7334. alert('$error_files_exists');
  7335. return false;
  7336. }
  7337. }
  7338. 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;
  7339. }
  7340. }
  7341. function export_files_ilm () {
  7342. var param = getCheckbox();
  7343. if (param.join() != '')
  7344. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  7345. else
  7346. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  7347. }
  7348. function select_all_ilm () {
  7349. var checkBoxes = document.getElementsByTagName('input');
  7350. var selectAll = document.getElementById('select_all');
  7351. for (var counter=0; counter < checkBoxes.length; counter++) {
  7352. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  7353. checkBoxes[counter].checked = selectAll.checked;
  7354. }
  7355. }
  7356. function getCheckbox () {
  7357. var checkBoxes = document.getElementsByTagName('input');
  7358. var param = new Array();
  7359. for (var counter=0; counter < checkBoxes.length; counter++) {
  7360. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  7361. param.push(checkBoxes[counter].value);
  7362. }
  7363. return param;
  7364. }
  7365. function new_dir_ilm () {
  7366. var dirname = '';
  7367. var i;
  7368. var dirs = new Array($dirs_array);
  7369. do {
  7370. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  7371. } while (dirname == '');
  7372. if (dirname == null)
  7373. return false;\n
  7374. else {
  7375. for (i=0;i<dirs.length;i++) {
  7376. if (dirs[i]==dirname) {
  7377. alert('$error_dir_exists');
  7378. return false;\n
  7379. }
  7380. }
  7381. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  7382. }
  7383. }
  7384. function delete_dir_ilm (ilmid, dirid) {
  7385. var msgAnswer;
  7386. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7387. if (msgAnswer) {
  7388. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7389. }
  7390. }
  7391. function rename_dir_ilm (ilmid, dirname, dirid) {
  7392. var dirnamecopy;
  7393. var i;
  7394. var dirs = new Array($dirs_array);
  7395. do {
  7396. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7397. } while (dirnamecopy == '');
  7398. if (dirnamecopy == null)
  7399. return false;\n
  7400. else {
  7401. for (i=0;i<dirs.length;i++) {
  7402. if (dirs[i]==dirnamecopy) {
  7403. alert('$error_dir_exists');
  7404. return false;\n
  7405. }
  7406. }
  7407. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7408. }
  7409. }
  7410. function move_selected_ilm (ilmid) {
  7411. var param = getCheckbox();
  7412. if (param.join() != '')
  7413. 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();
  7414. else
  7415. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7416. }
  7417. function recover_files_ilm () {
  7418. var msgAnswer;
  7419. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7420. if (msgAnswer) {
  7421. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7422. }
  7423. }
  7424. window.onload = function() {
  7425. var xPosition = 0;
  7426. var yPosition = 0;
  7427. element=document.getElementById('new_file');
  7428. while(element) {
  7429. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7430. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7431. element = element.offsetParent;
  7432. }
  7433. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7434. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7435. location.hash = '#new_file';
  7436. };
  7437. //]]>
  7438. </script>\n";
  7439. $output = "";
  7440. $select_all = "";
  7441. $count_files = 0;
  7442. $extensions_allow = array();
  7443. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  7444. foreach ($iassign_ilm as $item_iassign_ilm)
  7445. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  7446. foreach ($files_course as $value) {
  7447. $filename = $value->get_filename();
  7448. $filepath = $value->get_filepath();
  7449. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  7450. $pathname = $pathname[count($pathname) - 1];
  7451. $fileid = $value->get_id();
  7452. $tmp = explode(".", $filename);
  7453. if (count($tmp)>1) // avoid error if the file has no extension
  7454. $filetype = $tmp[1];
  7455. else // probably error...
  7456. $filetype = '';
  7457. $author = $value->get_author();
  7458. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  7459. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  7460. $extensions = explode(",", $extension);
  7461. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  7462. $count_files++;
  7463. // buscar fileid nas tabelas do iassign
  7464. $list_filein_use = "";
  7465. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  7466. if ($iassign_statement_activity_list) {
  7467. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  7468. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  7469. }
  7470. }
  7471. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  7472. if (!$iassign_ilm) {
  7473. $iassign_ilm = new stdClass();
  7474. $iassign_ilm->id = $ilmid;
  7475. }
  7476. // Do not use $var inside "..." - problem with some "unusual" operational system
  7477. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  7478. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  7479. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  7480. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  7481. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7482. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7483. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7484. $check_select = "";
  7485. $link_rename = "";
  7486. $link_delete = "";
  7487. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7488. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7489. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7490. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  7491. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7492. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7493. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7494. if ($value->get_userid() == $USER->id) {
  7495. if ($iassign_statement_activity_list) {
  7496. $check_select = "";
  7497. $link_edit = iassign_icons::insert('edit_iassign_disable');
  7498. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  7499. $link_rename = "";
  7500. } else {
  7501. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  7502. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  7503. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  7504. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  7505. }
  7506. }
  7507. if (!in_array($filetype, $extensions_allow)) {
  7508. $link_edit = "";
  7509. $link_add_ilm_iassign = "";
  7510. $link_add_ilm_tinymce = "";
  7511. $link_add_ilm_atto = "";
  7512. $link_filter = "";
  7513. }
  7514. if ($value->is_directory()) {
  7515. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  7516. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  7517. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  7518. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  7519. <td><center>$author</center></td>
  7520. <td><center>$timecreated</center></td>
  7521. <td><center>$timemodified</center></td></tr>\n";
  7522. }
  7523. else if ($this->from == 'iassign') {
  7524. $new_id = "";
  7525. $new_class = "";
  7526. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  7527. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  7528. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  7529. }
  7530. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  7531. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7532. <td><center>$author</center></td>
  7533. <td><center>$timecreated</center></td>
  7534. <td><center>$timemodified</center></td></tr>\n";
  7535. }
  7536. else if ($this->from == 'block') {
  7537. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  7538. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7539. <td><center>$author</center></td>
  7540. <td><center>$timecreated</center></td>
  7541. <td><center>$timemodified</center></td></tr>\n";
  7542. }
  7543. else if ($this->from == 'tinymce') {
  7544. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  7545. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7546. <td><center>$author</center></td>
  7547. <td><center>$timecreated</center></td>
  7548. <td><center>$timemodified</center></td></tr>\n";
  7549. }
  7550. else if ($this->from == 'atto') {
  7551. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  7552. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7553. <td><center>$author</center></td>
  7554. <td><center>$timecreated</center></td>
  7555. <td><center>$timemodified</center></td></tr>\n";
  7556. }
  7557. }
  7558. }
  7559. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  7560. $dir_base = "";
  7561. $header = "";
  7562. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  7563. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  7564. foreach ($basename as $value) {
  7565. $dir_base .= $value . "/";
  7566. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  7567. if ($dir_id) {
  7568. if ($value == "") {
  7569. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7570. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  7571. } else {
  7572. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7573. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  7574. }
  7575. }
  7576. } // foreach ($basename as $value)
  7577. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  7578. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  7579. $html .= "
  7580. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  7581. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  7582. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  7583. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  7584. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  7585. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  7586. </table>\n";
  7587. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  7588. $html .= "<table width='100%'><tr>\n";
  7589. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  7590. if ($count_files != 0) {
  7591. $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";
  7592. $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";
  7593. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  7594. }
  7595. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  7596. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  7597. $html .= "</form>\n";
  7598. print $code_javascript_ilm;
  7599. print $html;
  7600. } // function view_files_ilm($extension)
  7601. } // class ilm_manager
  7602. /// Class to insert of icons
  7603. class iassign_icons {
  7604. static function insert ($icon) {
  7605. global $CFG;
  7606. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  7607. return $string;
  7608. }
  7609. static function insertIT ($icon, $title, $text_alt) {
  7610. global $CFG;
  7611. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($title, 'iassign') . '" alt="' . get_string($text_alt, 'iassign') . '"/>'; // "\n"
  7612. return $string;
  7613. }
  7614. }
  7615. /// Class with util functions for plugin manage
  7616. class iassign_utils {
  7617. /// Function to return the filename extension
  7618. // @param string The $filename as an string
  7619. // @return string Return an string (last group after '.')
  7620. static function filename_extension ($filename) {
  7621. if ($filename == null || $filename == '') {
  7622. return null;
  7623. }
  7624. $itens = explode('.', $filename);
  7625. $num = count($itens);
  7626. if ($num < 2) {
  7627. return null;
  7628. }
  7629. return $itens[$num - 1];
  7630. }
  7631. /// Use the PHP class/package ZipArchive to create a Zip file
  7632. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  7633. // 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
  7634. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  7635. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  7636. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7637. $zip = new zip_archive(); //2
  7638. $res = $zip->open($full_path_zip_filename);
  7639. $total_vet = count($vet_student_filename);
  7640. for ($ii=0; $ii<$total_vet; $ii++) {
  7641. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7642. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7643. }
  7644. $ret = $zip->close();
  7645. iassign_utils::download_file($full_path_zip_filename);
  7646. $filenameZip = $zip->filename;
  7647. return array($ret, $zip);
  7648. }
  7649. static function download_file ($zip_filename) {
  7650. header("Pragma: public");
  7651. header("Expires: 0");
  7652. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7653. header("Cache-Control: private", false);
  7654. header("Content-Type: application/zip");
  7655. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7656. header("Content-Transfer-Encoding: binary");
  7657. header("Content-Length: " . @filesize($zip_filename));
  7658. set_time_limit(0);
  7659. @readfile("$zip_filename") || die("File not found.");
  7660. unlink($zip_filename);
  7661. }
  7662. /// Function for format filename remove special caracters
  7663. // @param string $text String for clean
  7664. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7665. // @return string Return an string in clean format
  7666. static function format_filename ($text) {
  7667. if ($text != '.') {
  7668. //D $text = htmlspecialchars(urldecode($text));
  7669. //D echo "locallib.php: format_filename: $text<br/>";
  7670. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7671. $text = json_decode($text)->{current_language()};
  7672. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7673. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7674. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7675. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7676. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7677. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7678. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7679. // E.g. text = "exerc_midpoint.course.geo"
  7680. // 0123456789012345678901234
  7681. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7682. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7683. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7684. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7685. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7686. //$ext = strrpos($text, ".");
  7687. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7688. //$text = str_replace($array1, $array2, $text);
  7689. }
  7690. return $text;
  7691. }
  7692. /// Function to filter characters to the file name to iLM content
  7693. // @param string $text String for clean
  7694. // @param string $ext String ot the extension of the iLM
  7695. // @return string Return an string in clean format
  7696. static function filter_filename_extension ($filename, $ext) {
  7697. if ($filename != '.') {
  7698. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7699. $arrTo = array("_","","","","","","","","","","","","");
  7700. $filename = str_replace($arrFrom, $arrTo, $filename);
  7701. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7702. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7703. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7704. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7705. $index_lastposition = strlen($filenameF);
  7706. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7707. $text = str_replace(".", "_", $text); // erase all other "."
  7708. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7709. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7710. }
  7711. else
  7712. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7713. return $filenameF;
  7714. }
  7715. /// Function for format pathname remove special caracters
  7716. // @param string $text String for clean
  7717. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7718. // @return string Return an string in clean format
  7719. static function format_pathname ($text, $is_lowercase = true) {
  7720. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7721. $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", "-", "_", "", "", "");
  7722. $text = str_replace($array1, $array2, $text);
  7723. if ($is_lowercase)
  7724. $text = strtolower($text);
  7725. return $text;
  7726. }
  7727. /// Function for format file name from iLM original name
  7728. // @param string $text String to build the file neam
  7729. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7730. // @return string Return an string in clean format
  7731. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7732. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7733. $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", "-", "_", "", "", "");
  7734. $index_firstposition_blank = strpos($ilm_name, " ");
  7735. if ($index_firstposition_blank) { // truncate the name!
  7736. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7737. }
  7738. $index_firstposition_dots = strpos($ilm_name, ":");
  7739. if ($index_firstposition_dots) { // truncate the name!
  7740. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7741. }
  7742. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7743. if ($is_lowercase)
  7744. $namefiltered = strtolower($namefiltered);
  7745. return $namefiltered;
  7746. }
  7747. /// Function for insert version in the filename
  7748. // @param string $filename Name of file
  7749. // @return string Return the filename with version
  7750. static function version_filename ($filename) {
  7751. $array_filename = explode('.', $filename);
  7752. if (count($array_filename) > 1)
  7753. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7754. else
  7755. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7756. return $filename;
  7757. }
  7758. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7759. static function remove_code_message ($string) {
  7760. $array = explode("&lt;ia_uc&gt;", $string);
  7761. return $array[0];
  7762. }
  7763. }
  7764. // class iassign_utils
  7765. /// Class with language functions for plugin manage
  7766. class iassign_language {
  7767. /// Function for return text in language or get default language (en)
  7768. // @param string $lang Code of language
  7769. // @param string $description JSON text content all languages
  7770. // @return string Return an string in the language selected
  7771. static function get_description_lang ($lang, $descriptions) {
  7772. $description_lang = "";
  7773. $description = json_decode($descriptions);
  7774. if ($description == null) {
  7775. $description_lang = $descriptions;
  7776. }
  7777. else {
  7778. if (isset($description->{$lang}))
  7779. $description_lang = $description->{$lang};
  7780. else
  7781. if (isset($description->en)) //MOOC2014
  7782. $description_lang = $description->en;
  7783. else //MOOC2014
  7784. $description_lang = "en"; //MOOC2014
  7785. }
  7786. return $description_lang;
  7787. }
  7788. /// Function for return all language supported by iLM
  7789. // @param string $descriptions JSON text content all languages
  7790. // @return string Return as string with all languages
  7791. static function get_all_lang ($descriptions) {
  7792. $langs = "";
  7793. $description = json_decode($descriptions);
  7794. if ($description) {
  7795. foreach ($description as $key => $value) {
  7796. $langs .= $key . " ; ";
  7797. }
  7798. $langs = substr($langs, 0, strlen($langs) - 3);
  7799. }
  7800. return $langs;
  7801. }
  7802. /// Function for convert json in xml //MOOC2014
  7803. // @param string $json JSON text
  7804. // @return string Return as string with xml tags
  7805. static function json_to_xml ($json) {
  7806. $xml = "";
  7807. $json = json_decode($json);
  7808. foreach ($json as $key => $value) {
  7809. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7810. }
  7811. return $xml;
  7812. }
  7813. }
  7814. // class iassign_language
  7815. /// Class with log functions for plugin manage.
  7816. class iassign_log {
  7817. /// Function for insert log event
  7818. // @param string $action Code action of event
  7819. // @param string $information Text for describe action of event
  7820. // @param int $cmid Id of context module
  7821. // @param int $ilmid Id of iLM
  7822. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7823. global $COURSE, $CFG, $USER, $DB;
  7824. $newentry = new stdClass();
  7825. $newentry->time = time();
  7826. $newentry->userid = $USER->id;
  7827. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7828. $newentry->course = $COURSE->id;
  7829. $newentry->cmid = $cmid;
  7830. $newentry->ilmid = $ilmid;
  7831. $newentry->action = $action;
  7832. $newentry->info = $information;
  7833. $newentry->language = current_language();
  7834. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7835. if (ini_get("browscap") && function_exists('get_browse')) {
  7836. $browser = get_browse(null, true);
  7837. $newentry->javascript = $browser['javascript'];
  7838. $newentry->java = $browser['javaapplets'];
  7839. }
  7840. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7841. print_error('error_add_log', 'iassign');
  7842. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7843. } // class iassign_log