locallib.php 427 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.7 2022/02/11
  7. * + Try to fix teacher edit of activity changing 'statement.id' to 'statement.file' in 'add_edit_iassign()'
  8. *
  9. * - v 4.9.6 2022/01/21
  10. * + Try to fix view activity not sent through report ("view_iassign_current()": else if (!$student_answer) $loadTeacherActivity=true;)
  11. *
  12. * - v 4.9.5 2021/12/28
  13. * + Detail to fix order o activities inside a block ('iassign_statement.position' - old instalation could generate order error)
  14. *
  15. * - v 4.9.4 2020/05/28
  16. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  17. *
  18. * - v 4.9.3 2020/01/16
  19. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  20. *
  21. * - v 4.9.2 2019/03/13
  22. * + Several fixes to allow iLM under HTML stack
  23. *
  24. * - v 4.9.1 2017/11/02
  25. * + 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")
  26. * + 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)'
  27. *
  28. * - v 4.9 2017/03/13
  29. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  30. *
  31. * - v 4.8 2016/05/12
  32. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  33. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  34. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  35. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  36. * replaced by
  37. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  38. * - v 4.7 2016/02/17
  39. * + 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(...)')
  40. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  41. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  42. * + 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)
  43. * + 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'
  44. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  45. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  46. *
  47. * --------------- (code bellow was used at our MOOC 2014)
  48. * - v 4.6 2014/02/25
  49. * + Fix bugs in filter function for open applets.
  50. * - v 4.5 2014/02/24
  51. * + Fix bugs in params.
  52. * + Insert new param type.
  53. * - v 4.4 2014/01/24
  54. * + Allow select type of params.
  55. * + Insert the use of applet params specific for activities.
  56. * - v 4.3 2014/01/23
  57. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  58. * - v 4.2 2016/02/13
  59. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  60. * --------------- (above code used at our MOOC 2014)
  61. *
  62. * - v 4.1 2013/12/13
  63. * + Insert log in iAssign actions.
  64. * + 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).
  65. * + Insert class for Log actions in system.
  66. * - v 4.0 2013/10/31
  67. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  68. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  69. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  70. * - v 3.9 2013/10/25
  71. * + Insert support of upgrade iLM.
  72. * + Insert support for more than one extension in iLM.
  73. * + Fix bugs in verion control.
  74. * - v 3.8 2013/09/19
  75. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  76. * - v 3.7 2013/09/12
  77. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  78. * + 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).
  79. * - v 3.6 2013/09/05
  80. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  81. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  82. * + Change tag APPLET in function ilm_settings::view_ilm.
  83. * - v 3.5 2013/08/26
  84. * + Fix bug in download package iassign without answers (iassign::report).
  85. * - v 3.4 2013/08/23
  86. * + Fix bug in export package iassign.
  87. * - v 3.3 2013/08/22
  88. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  89. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  90. * - v 3.2 2013/08/21
  91. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  92. * + Change functions for import files for ilm_manager.php.
  93. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  94. * - v 3.1 2013/08/15
  95. * + Change return file selected (ilm_manager::add_ilm).
  96. * + 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).
  97. * - v 3.0 2013/08/02
  98. * + 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).
  99. * - v 2.9 2013/08/01
  100. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  101. * - v 2.8 2013/07/25
  102. * + Insert the activity name in header of view (activity::view_dates).
  103. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  104. * - v 2.7 2013/07/24
  105. * + Create link previous and next for student view in one activity (activity::view_dates).
  106. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  107. * - v 2.6 2013/07/23
  108. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  109. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  110. * - v 2.5 2013/07/12
  111. * + 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).
  112. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  113. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  114. *
  115. * @author Patricia Alves Rodrigues
  116. * @author Leônidas O. Brandão
  117. * @contributor Igor Moreira Félix (2018-)
  118. * @contributor Márcio de Lima Passos (2014)
  119. * @version v 4.9.2 2019/03/13
  120. * @version v 4.8 2016/05/12
  121. * @package mod_iassign_lib
  122. * @since 2010/09/27
  123. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  124. *
  125. * <b>License</b>
  126. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  127. */
  128. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  129. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  130. //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"'
  131. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  132. /**
  133. * Standard base class for all iAssign
  134. */
  135. class iassign {
  136. var $cm;
  137. var $course;
  138. var $iassign;
  139. var $striassign;
  140. var $striassigns;
  141. var $context;
  142. var $activity;
  143. var $iassign_up;
  144. var $iassign_down;
  145. var $action;
  146. var $iassign_submission_current;
  147. var $userid_iassign;
  148. var $bottonPost;
  149. var $write_solution;
  150. var $view_iassign;
  151. // 3.1 update PHP 7.0 compatibility for all moodle versions
  152. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  153. /// Constructor for the base iassign class
  154. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  155. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  156. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  157. function __construct ($iassign, $cm, $course) {
  158. global $COURSE, $CFG, $USER, $DB;
  159. $botton = optional_param('botton', NULL, PARAM_TEXT);
  160. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  161. if (!is_null($botton))
  162. $USER->iassignEdit = $botton;
  163. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  164. // 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'
  165. $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"
  166. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  167. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  168. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  169. $this->action = optional_param('action', NULL, PARAM_TEXT);
  170. $this->cm = $cm;
  171. $this->context = context_module::instance($this->cm->id);
  172. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  173. $this->userid_iassign = $USER->id;
  174. if ($course) {
  175. $this->course = $course;
  176. }
  177. else if ($this->cm->course == $COURSE->id) {
  178. $this->course = $COURSE;
  179. }
  180. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  181. print_error('invalidid', 'iassign');
  182. }
  183. $this->coursecontext = context_course::instance($this->course->id);
  184. if ($iassign) {
  185. $this->iassign = $iassign;
  186. }
  187. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  188. print_error('invalidid', 'iassign');
  189. }
  190. $USER->context = context_module::instance($this->cm->id);
  191. $USER->cm = $this->cm->id;
  192. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  193. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  194. $this->context = context_module::instance($this->cm->id);
  195. $this->striassign = get_string('modulename', 'iassign');
  196. $this->striassigns = get_string('modulenameplural', 'iassign');
  197. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  198. $this->bottonPost = 0;
  199. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  200. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT)); // this is the activity inside iAssign block
  201. } // function __construct($iassign, $cm, $course)
  202. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  203. // This method provides the page to view each iLM with any interactive activity
  204. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  205. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  206. global $USER, $DB, $OUTPUT;
  207. // $iassign_statementid = $this->iassign->iassign_statementid;
  208. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  209. $iassign_statementid = $this->activity->get_activity()->id;
  210. else
  211. $iassign_statementid = "";
  212. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  213. // If this user has no capability to View 'iassign': stop here
  214. require_capability('mod/iassign:view', $this->context);
  215. // Trigger module view event
  216. $event = \mod_iassign\event\course_module_viewed::create(array(
  217. 'objectid' => $this->iassign->id,
  218. 'context' => $this->context
  219. ));
  220. $event->add_record_snapshot('course', $this->course);
  221. $event->trigger();
  222. if ($this->action) { // when student do/redo activity or teacher see student solution
  223. $this->action(); // calls '$this->view_iLM();'
  224. } else {
  225. print $OUTPUT->header();
  226. $this->view_iassigns(); // show the iLM with the content
  227. print $OUTPUT->footer();
  228. }
  229. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  230. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  231. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  232. //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" }
  233. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  234. // D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  235. // 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" }
  236. // D else echo "Apagou!<br/>";
  237. } // End function view()
  238. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  239. function action () {
  240. global $USER;
  241. // action:
  242. // up - move up activity (mover atividade para cima)
  243. // down - move down activity (mover atividade para baixo)
  244. // visible - view/hide activity (exibir/ocultar atividade)
  245. // delete - delete activity (excluir atividade)
  246. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  247. // deleteno - does not erase activity (não apaga atividade)
  248. // add - add activity (adicionar atividade)
  249. // edit - edit activity (modificar atividade)
  250. $action_iassign = array(
  251. 'newcomment' => '$this->add_comment();',
  252. 'view' => '$this->view_iassign_current();',
  253. 'get_answer' => '$this->get_answer();',
  254. 'repeat' => '$this->view_iassign_current();',
  255. 'overwrite' => '$this->get_answer();',
  256. 'stats_student' => '$this->stats_students();',
  257. 'download_answer' => '$this->export_file_answer();',
  258. 'download_all_answer' => '$this->export_package_answer();',
  259. 'notifications' => '$this->view_notifications();');
  260. $action_iassign_limit = array(
  261. 'view' => '$this->view_iassign_current();',
  262. //'newcomment' => '$this->get_answer();',
  263. 'viewsubmission' => '$this->view_iassign_current();',
  264. 'edit_status' => '$this->edit_status();',
  265. 'edit_grade' => '$this->edit_grade();',
  266. 'export_csv' => '$this->export_csv();',
  267. 'report' => '$this->report();',
  268. 'print' => '$this->report();',
  269. 'stats' => '$this->stats();',
  270. 'printstats' => '$this->stats();');
  271. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  272. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  273. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  274. 'visible' => '$this->activity->visible_iassign($this->return);',
  275. 'delete' => '$this->activity->delete($this->return);',
  276. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  277. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  278. 'add' => '$this->add_edit_iassign();',
  279. 'edit' => '$this->add_edit_iassign();',
  280. 'get_answer' => '$this->get_answer();',
  281. 'duplicate_activity' => '$this->duplicate_activity();',
  282. 'move_activity' => '$this->move_activity();',
  283. 'auto_evaluate' => '$this->auto_evaluate();',
  284. 'all_submissions' => '$this->all_submissions();',
  285. 'delete_submissions' => '$this->delete_submissions();',
  286. 'download_submissions' => '$this->download_submissions();',
  287. 'open_individual_submission' => '$this->open_individual_submission();',
  288. 'get_individual_submission' => '$this->get_individual_submission();',
  289. 'get_student_submission' => '$this->get_student_submission();',
  290. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  291. 'post_auto_eval_result' => '$this->post_auto_eval_result();',
  292. 'import_activity' => '$this->import_activity();',
  293. 'import_activity_confirm' => '$this->import_activity_confirm();'
  294. );
  295. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  296. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  297. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  298. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  299. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  300. }
  301. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  302. eval($action_iassign_limit[$this->action]);
  303. }
  304. else { // Student reaches this point
  305. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  306. // Arrive here with: "get_answer"; "view"
  307. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  308. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  309. }
  310. } // function action()
  311. /// This method prints the student submission to a specific exercise
  312. function get_student_submission () {
  313. global $DB;
  314. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  315. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  316. if (!$student || !$exercise) exit;
  317. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  318. if ($iassign_submission)
  319. print($iassign_submission->answer);
  320. die();
  321. }
  322. /// This method prints the teacher exercise
  323. function get_teacher_exercise () {
  324. global $DB, $COURSE;
  325. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  326. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  327. $fs = get_file_storage(); // Get reference to all files in Moodle data
  328. //2021/12: $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  329. //TODO 2022: trocar "$iassign_statement->id" por "$iassign_statement->file"???
  330. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  331. foreach ($files as $file) {
  332. if ($file->get_filename() != ".") {
  333. print($file->get_content());
  334. }
  335. }
  336. die();
  337. }
  338. /// This method receives the data from auto_eval event
  339. /// @see auto_evaluate()
  340. function post_auto_eval_result () {
  341. global $COURSE, $CFG, $USER, $DB;
  342. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  343. exit;
  344. //$exercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  345. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  346. $student = optional_param('student', -1, PARAM_INT);
  347. $grade = optional_param('grade', 0, PARAM_FLOAT);
  348. // 1: Recuperar a nota atual:
  349. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  350. // 2: Atualizar a tabela:
  351. $update_entry = new stdClass();
  352. $update_entry->id = $actual->id;
  353. $update_entry->previous_grade = $actual->grade;
  354. $update_entry->grade = $grade;
  355. // Update the iassign_submission
  356. $DB->update_record("iassign_submission", $update_entry);
  357. }
  358. /// Function to help download all_submissions files
  359. function download_submissions_help ($list) {
  360. global $DB, $CFG, $OUTPUT;
  361. // Get list of iLMs
  362. $ilm_list = $DB->get_records("iassign_ilm");
  363. // Get list of enrolled students:
  364. $params_temp = array('shortname' => 'student');
  365. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  366. $context = context_course::instance($this->course->id);
  367. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  368. $students_list = $DB->get_records_sql(
  369. "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);
  370. $json_obj = new stdclass();
  371. $json_obj->submissions = [];
  372. $csvfields = [];
  373. $csvfields[] = 'submissionid';
  374. $csvfields[] = 'file';
  375. $csvfields[] = 'filesize';
  376. $csvfields[] = 'timestamp';
  377. $csvfields[] = 'humandate';
  378. $csvfields[] = 'grade';
  379. $csvfields[] = 'userid';
  380. $csvfields[] = 'exerciseid';
  381. $json_obj->submissions[] = $csvfields;
  382. $exercise_dir = [];
  383. $exercises_list = [];
  384. foreach ($list as $item) {
  385. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  386. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  387. $exercises_list[] = $temp;
  388. $exercise_dir[] = $temp->id;
  389. }
  390. }
  391. $student_dir = [];
  392. $students_list = [];
  393. foreach ($list as $item) {
  394. if (!in_array($item->userid, $student_dir)) {
  395. $temp = $DB->get_record("user", array("id" => $item->userid));
  396. $students_list[] = $temp;
  397. $student_dir[] = $temp->id;
  398. }
  399. }
  400. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  401. //TODO: tem que criar moodledata/temp/iassign_files
  402. // Create $CFG->dataroot/temp/iassign_files
  403. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  404. if (!file_exists($tempfilespath)) {
  405. mkdir($tempfilespath, 0777, true);
  406. }
  407. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  408. if (!file_exists($iassignfilespath)) {
  409. mkdir($iassignfilespath, 0777, true);
  410. }
  411. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  412. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  413. if (!file_exists($diretorio)) {
  414. 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.';
  415. exit;
  416. }
  417. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  418. $zip = new zip_archive(); // create ZIP
  419. if (!$zip->open($zip_filename)) {
  420. 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;
  421. exit;
  422. }
  423. ;
  424. foreach ($exercises_list as $exercise) {
  425. $dir_ex = iassign_utils::format_filename($exercise->name);
  426. $zip->add_directory($dir_ex);
  427. $extension_ilm = '';
  428. foreach ($ilm_list as $ilm) {
  429. if ($exercise->iassign_ilmid == $ilm->id) {
  430. $extension_ilm = $ilm->extension;
  431. break;
  432. }
  433. }
  434. foreach ($students_list as $student) {
  435. $individual_dir =
  436. $dir_ex . DIRECTORY_SEPARATOR .
  437. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  438. $zip->add_directory($individual_dir);
  439. $i = 1;
  440. foreach($list as $item) {
  441. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  442. $date = new DateTime();
  443. $date->setTimestamp($item->timecreated);
  444. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  445. $zip->add_file_from_string($new_file, $item->answer);
  446. $temp_json = [];
  447. $temp_json[] = intval($item->id);
  448. $temp_json[] = $new_file;
  449. $temp_json[] = strlen($new_file);
  450. $temp_json[] = intval($item->timecreated);
  451. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  452. $temp_json[] = doubleval($item->grade);
  453. $temp_json[] = intval($item->userid);
  454. $temp_json[] = intval($exercise->id);
  455. $json_obj->submissions[] = $temp_json;
  456. }
  457. }
  458. }
  459. }
  460. $csv_str = "";
  461. foreach($json_obj->submissions as $sub) {
  462. $csv_str .= $this->csvstr($sub) . "\n";
  463. }
  464. $zip->add_file_from_string('index.csv', $csv_str);
  465. $zip->close();
  466. iassign_utils::download_file($zip_filename);
  467. exit;
  468. }
  469. function csvstr(array $fields) : string {
  470. $f = fopen('php://memory', 'r+');
  471. if (fputcsv($f, $fields) === false) {
  472. return false;
  473. }
  474. rewind($f);
  475. $csv_line = stream_get_contents($f);
  476. return rtrim($csv_line);
  477. }
  478. /// Download submissions from table iassign_allsubmissions
  479. function download_submissions () {
  480. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  481. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  482. exit;
  483. $type = optional_param('type', NULL, PARAM_TEXT);
  484. $item = optional_param('item', NULL, PARAM_TEXT);
  485. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  486. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  487. $sub_list = [];
  488. if ($type == 'individual') {
  489. $sub_list[] = $DB->get_record(
  490. 'iassign_allsubmissions', array('id' => $item));
  491. } elseif ($type == 'student') {
  492. $sub_list = $DB->get_records(
  493. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  494. } elseif ($type == 'exercise') {
  495. $sub_list = $DB->get_records(
  496. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  497. } elseif ($type == 'block') {
  498. $exercises_in_block = $DB->get_records(
  499. 'iassign_statement', array('iassignid' => $iassign_id));
  500. foreach ($exercises_in_block as $exercise) {
  501. $temp = $DB->get_records(
  502. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  503. $sub_list = array_merge($sub_list, $temp);
  504. }
  505. }
  506. $this->download_submissions_help($sub_list);
  507. }
  508. /// Delete submissions in table iassign_allsubmissions
  509. function delete_submissions () {
  510. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  511. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  512. exit;
  513. $type = optional_param('type', NULL, PARAM_TEXT);
  514. $item = optional_param('item', NULL, PARAM_TEXT);
  515. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  516. if ($type == 'individual') {
  517. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  518. } elseif ($type == 'student') {
  519. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  520. } elseif ($type == 'exercise') {
  521. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  522. }
  523. }
  524. function get_individual_submission () {
  525. global $DB, $USER;
  526. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  527. exit;
  528. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  529. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  530. print $submission->answer;
  531. }
  532. /// Open individual submission
  533. function open_individual_submission () {
  534. global $DB, $USER, $CFG;
  535. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  536. exit;
  537. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  538. $id = $this->cm->id;
  539. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  540. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  541. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  542. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  543. $all_submissions = $DB->get_records('iassign_allsubmissions',
  544. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  545. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  546. $previous = null;
  547. $next = null;
  548. $i = 0;
  549. $found = false;
  550. foreach($all_submissions as $individual) {
  551. if (!$found && $individual->id != $submissionid) {
  552. $previous = $individual;
  553. }
  554. if ($found) {
  555. $next = $individual;
  556. break;
  557. }
  558. if ($individual->id === $submissionid) {
  559. $found = true;
  560. }
  561. $i++;
  562. }
  563. print '<center>' . "\n";
  564. 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";
  565. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>' . "\n";
  566. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>' . "\n";
  567. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>' . "\n";
  568. print '</table>' . "\n";
  569. if ($previous) {
  570. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  571. print '<a href="' . $url_prev . '" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
  572. } else {
  573. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
  574. }
  575. print ' (' . $i . '/' . count($all_submissions) . ')';
  576. if ($next) {
  577. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  578. 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";
  579. } else {
  580. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">' . get_string('all_submissions_manager_next', 'iassign') . ' <span>&#9654;</span></a>' . "\n";
  581. }
  582. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  583. //array("type" => "editor_new", "notSEND" => "true")
  584. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  585. print '</center>' . "\n";
  586. } // function open_individual_submission()
  587. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - inicio 1
  588. function import_activity_confirm () {
  589. global $USER, $DB;
  590. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  591. exit;
  592. if (!isset($_REQUEST['statements'])) exit;
  593. $iassign_destiny = $this->iassign->id;
  594. $activities_list = $_REQUEST['statements'];
  595. foreach ($activities_list as $activity) {
  596. $activity_source = $DB->get_record('iassign_statement', array('id' => $activity));
  597. $activity_source->id = 0;
  598. $iassign_id_from = $activity_source->iassignid;
  599. $filesid_from = $activity_source->filesid;
  600. $activity_source->iassignid = $iassign_destiny;
  601. $author = $DB->get_record("user", array('id' => $USER->id));
  602. $activity_source->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  603. $activity_source->author_modified = $activity_source->author_modified_name;
  604. if ($id_ = $DB->insert_record("iassign_statement", $activity_source)) {
  605. $fs = get_file_storage();
  606. // Duplicate activity file
  607. $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
  608. print 'Arquivos a serem copiados: ';
  609. print_r($files_ids);
  610. foreach ($files_ids as $fileid) {
  611. $source_file = $fs->get_file_by_id($fileid->id);
  612. $newfile = $fs->create_file_from_storedfile(array('contextid' => $this->context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $source_file);
  613. $updateentry = new stdClass();
  614. $updateentry->id = $id_;
  615. $updateentry->filesid = $id_;
  616. // Update the duplicated iLM iAssign with new file id
  617. $DB->update_record("iassign_statement", $updateentry);
  618. }
  619. }
  620. } // foreach ($activities_list as $activity)
  621. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->context->id));
  622. $str_index = count($activities_list) > 1 ? 'import_activities_success' : 'import_activity_success';
  623. redirect($this->return, get_string($str_index, 'iassign'), null, \core\output\notification::NOTIFY_SUCCESS);
  624. exit;
  625. }
  626. function import_activity () {
  627. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  628. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  629. exit;
  630. print '<script>
  631. function verify_selection () {
  632. document.getElementById("msg-error").classList.add("d-none");
  633. var checkboxes = document.getElementsByName("statements[]");
  634. for (var i = 0; i < checkboxes.length; i++)
  635. if (checkboxes[i].checked) return true;
  636. document.getElementById("msg-error").classList.remove("d-none");
  637. return false;
  638. }
  639. </script>'; // "
  640. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id, 'action' => 'import_activity_confirm'));
  641. print $OUTPUT->header();
  642. $this->print_main_menu();
  643. print '<h2 class="m-b-2 mt-4">' . get_string('import_activity', 'iassign') . '</h2>' . "\n";
  644. print '<form action="' . $destiny_url . '" method="post" onsubmit="return verify_selection()">' . "\n";
  645. $courses_as_teacher = $this->get_courses_enroled_as_teacher($USER->id);
  646. foreach ($courses_as_teacher as $course) {
  647. 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";
  648. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '">' . "\n";
  649. $iassigns = $this->get_iassign_items_by_course($course->id);
  650. if ($iassigns) {
  651. foreach ($iassigns as $iassign) {
  652. 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";
  653. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '-' . $iassign->id . '">' . "\n";
  654. $statements = $this->get_iassign_statement_by_iassign($iassign->id);
  655. print '<table class="table table-hover">' . "\n";
  656. if ($statements) {
  657. foreach ($statements as $statement) {
  658. print '<tr><td> <div class="form-check"> <input class="form-check-input" name="statements[]" type="checkbox" value="' . $statement->id . '" id="statement-' . $statement->id . '">' . "\n";
  659. print '<label class="form-check-label w-100" for="statement-' . $statement->id . '">' . $statement->name;
  660. print '</label></div></td></tr>' . "\n";
  661. }
  662. }
  663. else {
  664. print '<tr><td>' . get_string('no_activity', 'iassign') . '</td></tr>' . "\n";
  665. }
  666. print '</table></div>' . "\n";
  667. }
  668. }
  669. else {
  670. print '<div class="p-2">' . get_string('import_statement_empty', 'iassign') . '</div>' . "\n";
  671. }
  672. print '</div>' . "\n";
  673. }
  674. print '<div class="text-center"><button type="submit" class="btn btn-primary mt-2">Confirmar</button></div>' . "\n";
  675. print '<div class="text-center text-danger d-none" id="msg-error">' . get_string('import_statement_no_exercise', 'iassign') . '</div>' . "\n";
  676. print "</form>\n";
  677. print $OUTPUT->footer();
  678. } // function post_auto_eval_result()
  679. function get_iassign_items_by_course ($courseid) {
  680. global $DB;
  681. return $DB->get_records("iassign", array("course" => $courseid));
  682. }
  683. function get_iassign_statement_by_iassign ($iassignid) {
  684. global $DB;
  685. return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  686. }
  687. function get_courses_enroled_as_teacher($userid) {
  688. $all_enroled = enrol_get_users_courses($userid);
  689. $return = array();
  690. foreach ($all_enroled as $enroled) {
  691. $context_course = context_course::instance($enroled->id);
  692. if (has_capability('mod/iassign:runautoevaluate', $context_course, $userid, false) ) {
  693. array_push($return, $enroled);
  694. }
  695. }
  696. return $return;
  697. }
  698. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - final 1
  699. /// Manage all submissions in exercises to table iassign_allsubmissions
  700. function all_submissions () {
  701. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  702. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  703. exit;
  704. print $OUTPUT->header();
  705. $this->print_main_menu();
  706. $id = $this->cm->id;
  707. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  708. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  709. print '
  710. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  711. <div class="modal-dialog modal-dialog-centered" role="document">
  712. <div class="modal-content">
  713. <div class="modal-header">
  714. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('delete', 'iassign') . '</h5>
  715. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  716. <span aria-hidden="true">&times;</span>
  717. </button>
  718. </div>
  719. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  720. <div class="modal-footer">
  721. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  722. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  723. </div>
  724. </div>
  725. </div>
  726. </div>'; // "
  727. print '
  728. <script>
  729. var sub_type;
  730. var sub_item;
  731. var sub_el;
  732. var sub_exercise;
  733. function delete_submission (type, item, el, exercise = 0) {
  734. sub_type = type;
  735. sub_item = item;
  736. sub_exercise = exercise;
  737. sub_el = el.closest("tr");
  738. if (!sub_el) sub_el = el.closest("a");
  739. $("#modalConfirm").modal();
  740. }
  741. function confirm_delete () {
  742. var url = "'.$enderecoPOST.'&action=delete_submissions";
  743. var xhttp = new XMLHttpRequest();
  744. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  745. xhttp.send();
  746. $("#modalConfirm").modal("hide");
  747. if ($(sub_el).attr("href"))
  748. $($(sub_el).attr("href")).remove();
  749. if (sub_el) sub_el.remove();
  750. }
  751. function download_submission(type, item, exercise = 0, iassign = 0) {
  752. var url = "'.$enderecoPOST.'&action=download_submissions";
  753. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  754. document.location = url;
  755. }
  756. function open_submission(item) {
  757. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  758. var poupup = window.open(url, "popup", "width=900,height=900");
  759. }
  760. </script>' . chr(13); // '
  761. // Get list of exercises in the instance:
  762. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  763. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  764. print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
  765. 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>';
  766. // Get list of enrolled students:
  767. $params_temp = array('shortname' => 'student');
  768. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  769. $context = context_course::instance($this->course->id);
  770. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  771. $students_list = $DB->get_records_sql(
  772. "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);
  773. print '<div>';
  774. foreach ($exercises_list as $exercise) {
  775. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  776. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  777. print '
  778. <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> '
  779. . $exercise->name
  780. . ' - ' . $iassign_ilm->name
  781. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  782. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  783. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  784. . $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> '
  785. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  786. . '</a>';
  787. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  788. foreach ($students_list as $student) {
  789. $total = 0;
  790. $student_submissions = [];
  791. foreach ($submissions_list as $submission) {
  792. if ($submission->userid == $student->userid) {
  793. $student_submissions[] = $submission;
  794. $total++;
  795. }
  796. }
  797. 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");\'>
  798. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  799. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  800. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  801. . '<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> '
  802. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  803. . ' </a>';
  804. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  805. print '<table class="table table-striped table-hover"><thead>
  806. <tr>
  807. <th scope="col">#</th>
  808. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  809. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  810. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  811. </tr>
  812. </thead><tbody>'; // "
  813. $i = 1;
  814. foreach ($student_submissions as $individual) {
  815. $date = new DateTime();
  816. $date->setTimestamp($individual->timecreated);
  817. print '<tr>';
  818. print '<td>' . ($i++) . '</td>';
  819. print '<td>' . date_format($date, 'd/m/Y H:i:s') . '</td>';
  820. print '<td>' . $individual->grade . '</td>';
  821. print '<td>
  822. <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>
  823. <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>
  824. <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>';
  825. print " </tr>\n";
  826. }
  827. print '</tbody></table>';
  828. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  829. print '</div>';
  830. }
  831. print '</div>';
  832. }
  833. print '</div>';
  834. print $OUTPUT->footer();
  835. } // function all_submissions()
  836. /// This method runs activities auto evaluation in teacher area
  837. function auto_evaluate () {
  838. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  839. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  840. exit;
  841. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  842. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  843. // Get list of exercises in the instance:
  844. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  845. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  846. // Get list of enrolled students:
  847. $params_temp = array('shortname' => 'student');
  848. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  849. $context = context_course::instance($this->course->id);
  850. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  851. $students_list = $DB->get_records_sql(
  852. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  853. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  854. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  855. print $OUTPUT->header();
  856. $this->print_main_menu();
  857. print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  858. print '<ul style="list-style-type: none; margin: 1em;">';
  859. foreach ($exercises_list as $exercise) {
  860. $matches = [];
  861. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  862. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  863. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  864. if ($matches[0][0]) {
  865. 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>';
  866. } else {
  867. 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>';
  868. }
  869. } else {
  870. if ($matches[0][0]) {
  871. 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>';
  872. } else {
  873. 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>';
  874. }
  875. }
  876. }
  877. print '</ul>
  878. <center>
  879. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  880. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  881. <div id="evaluate_message" style="color: red"></div>
  882. <div id="evaluate_alerts"></div>
  883. <div>
  884. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  885. <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>
  886. </div>
  887. </center>'; // close "
  888. print ' </div>' . "\n";
  889. print ' <script>' . "\n";
  890. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  891. print ' var submissions = [';
  892. // Get list of student id have submit for each exercise:
  893. foreach ($exercises_list as $exercise) {
  894. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  895. print '
  896. {
  897. "exerciseid": "' . $exercise->id . '",
  898. "grade": ' . $exercise->grade . ',
  899. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  900. "submited": ['; // "
  901. $params_temp = array('iassign_statementid' => $exercise->id);
  902. $submited = $DB->get_records_sql( // Get userid and his grade
  903. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  904. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  905. foreach ($submited as $ss) {
  906. print($ss->userid . ',');
  907. }
  908. print '],';
  909. print '"allgrades": [';
  910. foreach ($submited as $ss) {
  911. print( $ss->grade . ',');
  912. }
  913. print ']
  914. },'; // close "
  915. } // foreach ($exercises_list as $exercise)
  916. print " ];\n";
  917. print '
  918. var total_submissions = 0;
  919. var selected_exercises;
  920. var count_steps;
  921. var value_by_step;
  922. var stoped = false;
  923. var time_interval = 5000;
  924. var var_interval;
  925. function add_hover_th (id_th, id_li) { //AJAX
  926. $("#" + id_th).hover(function() {
  927. $("#" + id_li).css("background-color", "#d9d8d8");
  928. $(this).css("background-color", "#d9d8d8");
  929. }, function() {
  930. $("#" + id_li).css("background-color", "");
  931. $(this).css("background-color", "");
  932. });
  933. }
  934. function start_evaluation () {
  935. stoped = false;
  936. //AJAX
  937. $("#progress_bar").css("display", "none");
  938. $("#evaluate_message").text("");
  939. $("#evaluate_alerts").text("");
  940. $(".added-col").remove();
  941. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  942. selected_exercises = [];
  943. var c = 0;
  944. for (var i = 0; i < exercises.length; i++) {
  945. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  946. selected_exercises[c++] = exercises[i];
  947. }
  948. }
  949. if (selected_exercises.length == 0) {
  950. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  951. return;
  952. } else {
  953. $("input:checkbox").attr("disabled", true); //AJAX
  954. for (var i = 0; i < selected_exercises.length; i++) {
  955. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  956. //AJAX
  957. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  958. $("#table-results tbody tr").each(function(e) {
  959. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  960. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  961. });
  962. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  963. }
  964. //AJAX
  965. $("#button_start").prop("disabled", true);
  966. $("#button_stop").prop("disabled", false);
  967. $("#progress_bar").css("display", "block");
  968. }
  969. total_submissions = selected_exercises.length * students.length;
  970. count_steps = 0;
  971. value_by_step = 100/total_submissions;
  972. actual_exercise = 0;
  973. actual_student = 0;
  974. actual_submission = 0;
  975. get_original_propositions();
  976. var_interval = setInterval(verifyBreak, time_interval);
  977. } // function start_evaluation()
  978. var actual_exercise;
  979. var actual_student;
  980. var actual_submission;
  981. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  982. function run_individual_evaluation () {
  983. if (stoped) return;
  984. // Verify if student really sent his answer
  985. var found = false;
  986. for (var j = 0; j < submissions.length; j++) {
  987. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  988. for (var k = 0; k < submissions[j].submited.length; k++) {
  989. if (students[actual_student] == submissions[j].submited[k]) {
  990. found = true;
  991. break;
  992. }
  993. }
  994. break;
  995. }
  996. }
  997. if (found == false) {
  998. postResultAutoEval();
  999. } else {
  1000. // If it was sent, search it...
  1001. var final_url = "";
  1002. 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];
  1003. for (var j = 0; j < submissions.length; j++) {
  1004. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  1005. final_url = submissions[j].ilm;
  1006. break;
  1007. }
  1008. }
  1009. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  1010. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1011. window.frames["ifrm"].location=final_url;
  1012. }
  1013. } // function run_individual_evaluation()
  1014. var break_student = -1;
  1015. var break_exercise = -1;
  1016. function verifyBreak () {
  1017. if (actual_student == break_student && actual_exercise == break_exercise) {
  1018. postResultAutoEval(-6);
  1019. break_student = -1;
  1020. break_exercise = -1;
  1021. return;
  1022. } else {
  1023. break_student = actual_student;
  1024. break_exercise = actual_exercise;
  1025. }
  1026. }
  1027. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  1028. function getStudentAnswerURL () {
  1029. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1030. }
  1031. // This function is called by the iLM!!!
  1032. function getAutoEvalOriginalData () {
  1033. return original_propositions[actual_exercise];
  1034. }
  1035. function updateProgressBar () {
  1036. if (stoped) return;
  1037. var temp = (count_steps * value_by_step)|0;
  1038. count_steps++;
  1039. temp = temp > 100 ? 100 : temp;
  1040. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  1041. if (temp >= 100) {
  1042. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1043. $("#button_start").prop("disabled", false);
  1044. $("#button_stop").prop("disabled", true);
  1045. $("input:checkbox").attr("disabled", false);
  1046. clearInterval(var_interval);
  1047. }
  1048. }
  1049. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  1050. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  1051. function postResultAutoEval (grade = null) {
  1052. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  1053. if (grade == null) {
  1054. $("#"+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>\');
  1055. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1056. } else {
  1057. // Verify if the re-evaluation grade is the of that one registered:
  1058. var actual_value = 0;
  1059. var actual_student_grade = 0;
  1060. for (var k = 0; k < submissions.length; k++) {
  1061. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  1062. actual_value = submissions[k].grade;
  1063. for (var h = 0; h < submissions[k].submited.length; h++) {
  1064. if (submissions[k].submited[h] == students[actual_student]) {
  1065. actual_student_grade = submissions[k].allgrades[h];
  1066. break;
  1067. }
  1068. }
  1069. break;
  1070. }
  1071. }
  1072. // @FeedbackConvention
  1073. if (grade < 0) {
  1074. switch (grade) {
  1075. case -1:
  1076. // Test-cases are empty:
  1077. $("#"+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>\');
  1078. var mm = actual_exercise;
  1079. $("#"+id_t).find(".details-button").click(function(e) {
  1080. $(".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>\');
  1081. });
  1082. break;
  1083. case -2:
  1084. // Test-cases were manually altered by the student (fraud!):
  1085. $("#"+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>\');
  1086. var mm = actual_exercise;
  1087. $("#"+id_t).find(".details-button").click(function(e) {
  1088. $(".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>");
  1089. });
  1090. //AJAX
  1091. $.ajax({
  1092. dataType: "html",
  1093. 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",
  1094. success: function(d) {} });
  1095. break;
  1096. case -5:
  1097. // Execution failed:
  1098. $("#"+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>\');
  1099. var mm = actual_exercise;
  1100. //AJAX
  1101. $("#"+id_t).find(".details-button").click(function(e) {
  1102. $(".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>\');
  1103. });
  1104. break;
  1105. case -6: // iLM not answering was detected in "verifyBreak()"
  1106. // The iLM are not answering:
  1107. //AJAX
  1108. $("#"+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>\');
  1109. $("#"+id_t).find(".details-button").click(function(e) {
  1110. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  1111. });
  1112. break;
  1113. }
  1114. //AJAX
  1115. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1116. } else {
  1117. console.log((grade), (actual_student_grade));
  1118. if ((grade) == (actual_student_grade)) {
  1119. $("#"+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>\');
  1120. } else { // Notas diferem:
  1121. $("#"+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>\');
  1122. var mm = actual_exercise;
  1123. //AJAX
  1124. $("#"+id_t).find(".details-button").click(function(e) {
  1125. $(".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>\');
  1126. });
  1127. //AJAX
  1128. // Send to the endpoint the post_auto_eval_result to verify:
  1129. $.ajax({
  1130. dataType: "html",
  1131. 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),
  1132. success: function(d) {}
  1133. });
  1134. }
  1135. //AJAX
  1136. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1137. }
  1138. }
  1139. updateProgressBar();
  1140. // Does it must continue in the same exercise or stop?
  1141. if (actual_student < students.length) {
  1142. actual_student++;
  1143. run_individual_evaluation();
  1144. } else {
  1145. actual_student = 0;
  1146. // Does it go to next exercise or is it finished?
  1147. if (actual_exercise < selected_exercises.length) {
  1148. actual_exercise++;
  1149. run_individual_evaluation();
  1150. } else {
  1151. //AJAX
  1152. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1153. }
  1154. }
  1155. }
  1156. var original_propositions;
  1157. function get_original_propositions () {
  1158. original_propositions = [];
  1159. var count = 0;
  1160. for (var i = 0; i < exercises.length; i++) {
  1161. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1162. //AJAX
  1163. $.ajax({
  1164. dataType: "html",
  1165. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1166. success: function(d) { // variable "d" has the iLM content
  1167. original_propositions[count] = d; // exercise original content
  1168. count++;
  1169. if (count == selected_exercises.length) {
  1170. run_individual_evaluation();
  1171. }
  1172. }
  1173. });
  1174. }
  1175. }
  1176. }
  1177. function stop_evaluation () {
  1178. stoped = true;
  1179. //AJAX
  1180. $("#button_start").prop("disabled", false);
  1181. $("#button_stop").prop("disabled", true);
  1182. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1183. $("input:checkbox").attr("disabled", false);
  1184. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1185. clearInterval(var_interval);
  1186. }
  1187. var exercises = [ '; // '
  1188. foreach ($exercises_list as $exercise) {
  1189. print $exercise->id . ',';
  1190. }
  1191. print ' ];';
  1192. print ' var students = [ ';
  1193. foreach ($students_list as $student) {
  1194. print $student->userid . ',';
  1195. }
  1196. print '];';
  1197. print ' var ilms = [';
  1198. foreach ($exercises_list as $exercise) {
  1199. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1200. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1201. }
  1202. print ']';
  1203. print '</script>';
  1204. print '
  1205. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1206. <div class="modal-dialog modal-dialog-centered" role="document">
  1207. <div class="modal-content">
  1208. <div class="modal-header">
  1209. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1210. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1211. <span aria-hidden="true">&times;</span>
  1212. </button>
  1213. </div>
  1214. <div class="modal-body">
  1215. ...
  1216. </div>
  1217. <div class="modal-footer">
  1218. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1219. </div>
  1220. </div>
  1221. </div>
  1222. </div>'; //
  1223. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1224. print '<table id="table-results" class="table table-hover m-t-1">
  1225. <thead>
  1226. <tr id="cols-exercises">
  1227. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1228. </tr>
  1229. </thead>
  1230. <tbody>'; // "
  1231. foreach ($students_list as $student) {
  1232. $user = $DB->get_record('user', array('id' => $student->userid));
  1233. $avatar = new user_picture($user);
  1234. $avatar->courseid = $COURSE->id;
  1235. $avatar->link = true;
  1236. print ' <tr data-student="' . $student->userid . '">
  1237. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1238. </tr>' . "\n"; // "
  1239. }
  1240. print " </tbody>
  1241. </table>\n";
  1242. print $OUTPUT->footer();
  1243. } // function auto_evaluate()
  1244. /// This method moves an iAssign activity
  1245. function move_activity () {
  1246. global $USER, $CFG, $DB, $COURSE;
  1247. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1248. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1249. $update_entry_new_iassign = new stdClass();
  1250. $update_entry_new_iassign->id = $iassign_id;
  1251. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1252. // Update the iassign_statement
  1253. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1254. // Update file context
  1255. $c_i = context_module::instance($this->cm->id);
  1256. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1257. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1258. $path_module = context_course::instance($COURSE->id);
  1259. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1260. $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny); //2021/12
  1261. if ($context_file) {
  1262. $id_context = $context_file->id;
  1263. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1264. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1265. $context = context_module::instance($USER->cm); //2021/12
  1266. //2021/12 $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1267. //TODO 2022: trocar "$iassign_statement->id" por "$iassign_statement->file"???
  1268. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  1269. foreach ($files as $value) {
  1270. if ($value->get_filename() != ".") {
  1271. //2021/12 $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1272. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1273. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1274. $destiny_context = context_module::instance($course_module->id);
  1275. $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());
  1276. $updateentry = new stdClass();
  1277. $updateentry->id = $iassign_id;
  1278. $updateentry->filesid = $iassign_id; //2021/12 $newfile->get_itemid(); //TODO: esta' correto? $newfile definido 3 linhas acima NAO mais usado?
  1279. $DB->update_record("iassign_statement", $updateentry);
  1280. //2021/12 $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1281. break;
  1282. }
  1283. }
  1284. }
  1285. //2021/12 $this->return_home_course('moved_activity');
  1286. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
  1287. 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);
  1288. exit;
  1289. } // function move_activity()
  1290. /// This method duplicates an iAssign activity
  1291. function duplicate_activity () {
  1292. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1293. $id = $this->cm->id;
  1294. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1295. $context = context_module::instance($this->cm->id);
  1296. $contextuser = context_user::instance($USER->id);
  1297. // Get the the iAssign acitivity to be duplicated
  1298. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1299. // Remove the current id of activity
  1300. $id_source_copy = $iassign_statement->id;
  1301. $iassign_statement->id=0;
  1302. // Include prefix (Copy of ...)
  1303. $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
  1304. // Get the information about current author, and add this information in author_modified field
  1305. $author = $DB->get_record("user", array('id' => $USER->id));
  1306. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1307. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1308. // Store the activity in the table
  1309. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1310. // Duplicate activity file
  1311. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1312. //2021/12 $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1313. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
  1314. foreach ($files as $value) {
  1315. if ($value->get_filename() != ".") {
  1316. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1317. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1318. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
  1319. $updateentry = new stdClass();
  1320. $updateentry->id = $id_;
  1321. //2021/12 $updateentry->filesid = $newfile->get_itemid();
  1322. $updateentry->filesid = $id_;
  1323. // Update the duplicated iLM iAssign with new file id
  1324. $DB->update_record("iassign_statement", $updateentry);
  1325. }
  1326. }
  1327. }
  1328. // log event --------------------------------------------------------------------------------------
  1329. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1330. $this->return_home_course('duplicated_activity');
  1331. exit;
  1332. }
  1333. // / This method gets the content from comment and register it
  1334. function add_comment () {
  1335. global $USER, $DB;
  1336. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1337. $comment = false;
  1338. if ($submission_comment)
  1339. $comment = $this->write_comment_submission();
  1340. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1341. if (!$id_submission) {
  1342. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  1343. if ($iassign_submission) {
  1344. $id_submission = $iassign_submission->id;
  1345. }
  1346. }
  1347. $content = $this->search_comment_submission($id_submission);
  1348. ob_end_clean();
  1349. header("Connection: close\r\n");
  1350. header("Content-Encoding: none\r\n");
  1351. header('Content-Type: text/html');
  1352. ob_start();
  1353. print $this->search_comment_submission($id_submission);
  1354. $size = ob_get_length();
  1355. header("Content-Length: $size");
  1356. ob_end_flush();
  1357. flush();
  1358. ob_end_clean();
  1359. // Send email to users:
  1360. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $id_submission));
  1361. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1362. }
  1363. /// This method alerts envolved to new comment sent
  1364. function send_alert_new_comment ($comment, $student_id = -1) {
  1365. global $USER, $DB, $COURSE, $SITE;
  1366. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign') . " ";
  1367. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); //leo 2021/12
  1368. $subject .= $iassign_ilm->name . ' ' . get_string('new_comment_mail_at', 'iassign') . ' ' . get_string("iassign", "iassign") . '/Moodle'; //leo 2021/12
  1369. // $url_curso; $url_submissao;
  1370. $text = "<p style='margin-top: 1rem;'>\n";
  1371. $text .= "<a href=\"" . new moodle_url('/course/view.php', array('id' => $COURSE->id)) . "\">" . $COURSE->shortname . "</a> " . " &#8811; \n";
  1372. $modinfo = get_fast_modinfo($COURSE);
  1373. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1374. if ($modinfo->get_section_info($i) && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1375. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1376. $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";
  1377. break;
  1378. }
  1379. }
  1380. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1381. $text .= "<a href=\"" . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id)) . "\">" . $iassign->name . "</a> &#8811; \n";
  1382. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1383. array(
  1384. 'id' => $this->cm->id,
  1385. 'action' => 'viewsubmission',
  1386. 'iassign_current' => $this->activity->get_activity()->id,
  1387. 'userid_iassign' => $USER->id));
  1388. $text .= "<a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a></p>\n";
  1389. $text .= "<div style='margin-left: .5rem;'>\n";
  1390. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>\n";
  1391. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1392. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>\n";
  1393. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1394. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': ' . "<a href=\"" .
  1395. new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">" . $USER->firstname . " " . $USER->lastname . "</a>\n";
  1396. $text .= " - " . userdate(time());
  1397. $text .= "</div><div style='margin: 2rem;'>\n";
  1398. $text .= $comment;
  1399. $text .= "</div><div>\n";
  1400. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | \n";
  1401. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>\n";
  1402. $text .= "</div>\n";
  1403. // Who has to receive?
  1404. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1405. $userfrom = \core_user::get_noreply_user();
  1406. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1407. // other teachers receive also: (excepts the sender)
  1408. foreach ($teachers as $teacher) {
  1409. if ($teacher->id != $USER->id) {
  1410. email_to_user(
  1411. $teacher,
  1412. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1413. $subject,
  1414. "",
  1415. $text,
  1416. '',
  1417. '',
  1418. false,
  1419. $userfrom->email,
  1420. 'Não responda a esta mensagem' //TODO: internacionalizar
  1421. );
  1422. $message = new \core\message\message();
  1423. $message->component = 'mod_iassign';
  1424. $message->name = 'message';
  1425. $message->userfrom = core_user::get_noreply_user();
  1426. $message->userto = $teacher;
  1427. $message->subject = $subject;
  1428. $message->fullmessage = $text;
  1429. $message->fullmessageformat = FORMAT_MARKDOWN;
  1430. $message->fullmessagehtml = $text;
  1431. $message->smallmessage = $subject;
  1432. $message->notification = 1;
  1433. $message->contexturl = $url_submissao . '#comments';
  1434. $message->contexturlname = $this->activity->get_activity()->name;
  1435. $messageid = message_send($message);
  1436. }
  1437. } // foreach ($teachers as $teacher)
  1438. // and student:
  1439. $student = $DB->get_record('user', array('id' => $student_id));
  1440. $formated_text = str_replace("viewsubmission", "view", $text);
  1441. email_to_user(
  1442. $student,
  1443. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1444. $subject,
  1445. "",
  1446. $formated_text,
  1447. '',
  1448. '',
  1449. false,
  1450. $userfrom->email,
  1451. 'Não responda a esta mensagem' //TODO: internacionalizar
  1452. );
  1453. $url_student = new moodle_url('/mod/iassign/view.php',
  1454. array(
  1455. 'id' => $this->cm->id,
  1456. 'action' => 'view',
  1457. 'iassign_current' => $this->activity->get_activity()->id));
  1458. $message = new \core\message\message();
  1459. $message->component = 'mod_iassign';
  1460. $message->name = 'message';
  1461. $message->userfrom = core_user::get_noreply_user();
  1462. $message->userto = $student;
  1463. $message->subject = $subject;
  1464. $message->fullmessage = $formated_text;
  1465. $message->fullmessageformat = FORMAT_MARKDOWN;
  1466. $message->fullmessagehtml = $formated_text;
  1467. $message->smallmessage = $subject;
  1468. $message->notification = 1;
  1469. $message->contexturl = $url_student . '#comments';
  1470. $message->contexturlname = $this->activity->get_activity()->name;
  1471. $messageid = message_send($message);
  1472. } // if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  1473. else { // a student has sent the comment:
  1474. foreach ($teachers as $teacher) {
  1475. email_to_user(
  1476. $teacher,
  1477. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1478. $subject,
  1479. "",
  1480. $text,
  1481. '',
  1482. '',
  1483. false,
  1484. $userfrom->email,
  1485. 'Não responda a esta mensagem' //TODO: internacionalizar
  1486. );
  1487. $message = new \core\message\message();
  1488. $message->component = 'mod_iassign';
  1489. $message->name = 'message';
  1490. $message->userfrom = core_user::get_noreply_user();
  1491. $message->userto = $teacher;
  1492. $message->subject = $subject;
  1493. $message->fullmessage = $text;
  1494. $message->fullmessageformat = FORMAT_MARKDOWN;
  1495. $message->fullmessagehtml = $text;
  1496. $message->smallmessage = $subject;
  1497. $message->notification = 1;
  1498. $message->contexturl = $url_submissao . '#comments';
  1499. $message->contexturlname = $this->activity->get_activity()->name;
  1500. $messageid = message_send($message);
  1501. } // foreach ($teachers as $teacher)
  1502. }
  1503. } // function send_alert_new_comment($comment, $student_id = -1)
  1504. /// This method gets the content from the iLM and register it
  1505. // It could be the "exercise template" (teacher) or an answer (student)
  1506. function get_answer () {
  1507. global $USER, $CFG, $DB, $OUTPUT;
  1508. $id = $this->cm->id;
  1509. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1510. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1511. if ($submission_ajax == 1) ob_start();
  1512. $comment = false;
  1513. if ($submission_comment)
  1514. $comment = $this->write_comment_submission();
  1515. // receives data of iLM using the current activity
  1516. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1517. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1518. // receives data of submission of current activity
  1519. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1520. // receives post and get
  1521. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1522. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1523. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1524. $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)
  1525. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1526. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1527. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1528. $msg = '';
  1529. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1530. $newentry = new stdClass();
  1531. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1532. $newentry->userid = $this->userid_iassign;
  1533. $newentry->timecreated = time();
  1534. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1535. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1536. $DB->insert_record("iassign_allsubmissions", $newentry);
  1537. }
  1538. // Feedback
  1539. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1540. $str_action = "view"; // repeat
  1541. if (strtolower($iassign_ilm->name) == "igeom") {
  1542. }
  1543. $title = get_string('evaluate_iassign', 'iassign');
  1544. print $OUTPUT->header();
  1545. print $OUTPUT->box_start();
  1546. // Action = { view ; repeat ; viewsubmission }
  1547. // * '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")
  1548. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1549. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1550. $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;
  1551. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1552. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1553. print '<table width=100% >';
  1554. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1555. //TODO alterar aqui???
  1556. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1557. // empty_answer_post = No solution was posted.
  1558. if ($comment)
  1559. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1560. else
  1561. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1562. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1563. } else {
  1564. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1565. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1566. // Correct answer!!
  1567. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1568. $this->write_solution = 1; //
  1569. $status = 3;
  1570. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1571. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1572. // log record
  1573. $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;
  1574. // Trigger module viewed event.
  1575. $event = \mod_iassign\event\submission_created::create(array(
  1576. 'objectid' => $this->iassign->id,
  1577. 'context' => $this->context,
  1578. 'other' => $info
  1579. ));
  1580. $event->add_record_snapshot('course', $this->course);
  1581. $event->trigger();
  1582. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1583. // Wrong answer...: get_answer_incorrect
  1584. $status = 2;
  1585. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1586. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1587. // log record
  1588. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1589. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1590. // Trigger module viewed event.
  1591. $event = \mod_iassign\event\submission_created::create(array(
  1592. 'objectid' => $this->iassign->id,
  1593. 'context' => $this->context,
  1594. 'other' => $info
  1595. ));
  1596. $event->add_record_snapshot('course', $this->course);
  1597. $event->trigger();
  1598. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1599. // Presents to the learner the result of the automatic evaluate?
  1600. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1601. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1602. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1603. print '<tr>';
  1604. // log record
  1605. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1606. // Trigger module viewed event.
  1607. $event = \mod_iassign\event\submission_created::create(array(
  1608. 'objectid' => $this->iassign->id,
  1609. 'context' => $this->context,
  1610. 'other' => $info
  1611. ));
  1612. $event->add_record_snapshot('course', $this->course);
  1613. $event->trigger();
  1614. } else { // yes!!!
  1615. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1616. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1617. print '<tr>';
  1618. print $msg;
  1619. }
  1620. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1621. $status = 1;
  1622. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1623. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1624. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1625. print '<tr>';
  1626. // log record
  1627. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1628. $event = \mod_iassign\event\submission_created::create(array(
  1629. 'objectid' => $this->iassign->id,
  1630. 'context' => $this->context,
  1631. 'other' => $info
  1632. ));
  1633. $event->add_record_snapshot('course', $this->course);
  1634. $event->trigger();
  1635. } // if ($iassign_ilm->evaluate == 1)
  1636. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1637. print '</tr></table>';
  1638. print $OUTPUT->box_end();
  1639. // add or update evaluate
  1640. if ($this->write_solution == 1) {
  1641. $timenow = time();
  1642. // new record
  1643. if (!$iassign_submission) {
  1644. $newentry = new stdClass();
  1645. $newentry->userid = $this->userid_iassign;
  1646. // $newentry->userid = $USER->id;
  1647. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1648. $newentry->timecreated = $timenow;
  1649. $newentry->timemodified = $timenow;
  1650. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1651. $newentry->grade = round($grade_student, 2);
  1652. $newentry->status = $status;
  1653. $newentry->experiment = 1;
  1654. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1655. print_error('error_insert', 'iassign');
  1656. } else {
  1657. // Trigger module viewed event.
  1658. $event = \mod_iassign\event\submission_created::create(array(
  1659. 'objectid' => $this->iassign->id,
  1660. 'context' => $this->context
  1661. ));
  1662. $event->add_record_snapshot('course', $this->course);
  1663. $event->trigger();
  1664. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1665. }
  1666. } elseif ($iassign_submission->status != 3) {
  1667. $newentry = new stdClass();
  1668. $newentry->id = $iassign_submission->id;
  1669. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1670. $newentry->userid = $iassign_submission->userid;
  1671. $newentry->timecreated = $iassign_submission->timecreated;
  1672. $newentry->timemodified = $timenow;
  1673. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1674. $newentry->grade = round($grade_student, 2);
  1675. $newentry->status = $status;
  1676. $newentry->experiment = $iassign_submission->experiment + 1;
  1677. if (!$DB->update_record("iassign_submission", $newentry)) {
  1678. print_error('error_update', 'iassign');
  1679. //D depurar...
  1680. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1681. //D $fp = fopen("teste1.txt","w");
  1682. //D fwrite($fp,$stringAux);
  1683. } else {
  1684. // Trigger module viewed event.
  1685. $event = \mod_iassign\event\submission_updated::create(array(
  1686. 'objectid' => $this->iassign->id,
  1687. 'context' => $this->context
  1688. ));
  1689. $event->add_record_snapshot('course', $this->course);
  1690. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1691. }
  1692. } else {
  1693. if ($return_get_answer == 1) {
  1694. $newentry = new stdClass();
  1695. $newentry->id = $iassign_submission->id;
  1696. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1697. $newentry->userid = $iassign_submission->userid;
  1698. $newentry->timecreated = $iassign_submission->timecreated;
  1699. $newentry->timemodified = $timenow;
  1700. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1701. $newentry->grade = round($grade_student, 2);
  1702. $newentry->status = $status;
  1703. $newentry->experiment = $iassign_submission->experiment + 1;
  1704. if (!$DB->update_record("iassign_submission", $newentry))
  1705. print_error('error_update', 'iassign');
  1706. else {
  1707. $event = \mod_iassign\event\submission_updated::create(array(
  1708. 'objectid' => $this->iassign->id,
  1709. 'context' => $this->context
  1710. ));
  1711. $event->add_record_snapshot('course', $this->course);
  1712. $event->trigger();
  1713. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1714. print $OUTPUT->box_start();
  1715. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1716. print $OUTPUT->box_end();
  1717. }
  1718. } elseif ($return_get_answer == 2) {
  1719. print $OUTPUT->box_start();
  1720. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1721. print $OUTPUT->box_end();
  1722. } else {
  1723. print $OUTPUT->box_start();
  1724. print "
  1725. <script type='text/javascript'>
  1726. //<![CDATA[
  1727. function overwrite () {
  1728. document.formEnvio.return_get_answer.value = 1;
  1729. document.formEnvio.submit();
  1730. }
  1731. function nooverwrite () {
  1732. document.formEnvio.return_get_answer.value = 2;
  1733. document.formEnvio.submit();
  1734. }
  1735. //]]>
  1736. </script>";
  1737. $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;
  1738. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1739. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1740. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1741. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1742. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1743. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1744. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1745. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1746. <input type='hidden' name='return_get_answer'/> ";
  1747. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1748. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1749. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1750. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1751. print " </form>";
  1752. print $OUTPUT->box_end();
  1753. }
  1754. }
  1755. } // if ($this->write_solution == 1)
  1756. print $OUTPUT->footer();
  1757. if ($submission_ajax == 1) {
  1758. ob_end_clean();
  1759. print 'OK';
  1760. }
  1761. die();
  1762. } // function get_answer()
  1763. /// Export in file the answer of student.
  1764. function export_file_answer () {
  1765. global $DB;
  1766. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1767. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1768. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1769. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1770. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1771. $extensions = explode(",", $iassign_ilm->extension);
  1772. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1773. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1774. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1775. header("Pragma: public");
  1776. header("Expires: 0");
  1777. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1778. header("Cache-Control: private", false);
  1779. header("Content-Type: document/unknown");
  1780. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1781. set_time_limit(0);
  1782. print($iassign_submission->answer);
  1783. exit;
  1784. } // function export_file_answer()
  1785. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1786. // @calledby $this->export_package_answer()
  1787. //TODO Precisa terminar! //TODO_HTML
  1788. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1789. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1790. <head>
  1791. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1792. $str_html .= " </head>
  1793. <body>\n";
  1794. $tam = sizeof($array_iassign_name);
  1795. for ($ii=0; $ii<$tam; $ii++) {
  1796. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1797. }
  1798. $str_html .= "
  1799. </body>\n</html>";
  1800. return $str_html;
  1801. }
  1802. /// Export an package (zip) with all answer of students
  1803. // @calledby $this->action()
  1804. function export_package_answer () {
  1805. global $DB, $CFG, $OUTPUT;
  1806. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1807. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1808. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1809. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1810. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1811. $userid = optional_param('userid', NULL, PARAM_INT);
  1812. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1813. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1814. //TODO_HTML echo "username=$username<br/>"; exit;
  1815. $current_date = date('Y_m_d_H');
  1816. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1817. // If temporary directory under Moodle data does not exists => create it
  1818. if (!is_dir($diretorio)) {
  1819. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1820. // created directory with permissions to be seen by everyone
  1821. }
  1822. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1823. if (!is_writable($diretorio)) { // send a highlighted message!
  1824. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1825. exit; // just in case
  1826. }
  1827. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1828. $zip = new zip_archive(); // create ZIP
  1829. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1830. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1831. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1832. $vet_student_filename = array();
  1833. $vet_student_content = array();
  1834. foreach ($iassign_statements as $iassign_statement) {
  1835. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1836. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1837. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1838. $extensions = explode(",", $iassign_ilm->extension);
  1839. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1840. if ($iassign_submission) {
  1841. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1842. $student_content = $iassign_submission->answer;
  1843. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1844. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1845. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1846. if ($resp) {
  1847. $vet_student_filename[] = $student_filename;
  1848. $vet_student_content[] = $student_content;
  1849. }
  1850. else { // send a highlighted message!
  1851. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1852. exit; // just in case
  1853. }
  1854. }
  1855. } // foreach ($iassign_statements as $iassign_statement)
  1856. $zip->close(); // close the ZIP file
  1857. if (count($vet_student_filename)>0) {
  1858. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1859. $result_tf = $vet_result[0];
  1860. $filenameZip = $vet_result[1]->filename;
  1861. }
  1862. iassign_utils::download_file($zip_filename); // download the ZIP file
  1863. exit;
  1864. } // function export_package_answer()
  1865. /// Editing status of interactive activities
  1866. function edit_status () {
  1867. global $USER, $DB, $OUTPUT;
  1868. $newentry = new stdClass();
  1869. $newentry->id = $this->iassign_submission_current;
  1870. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1871. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1872. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1873. $newentry->status = $iassign_submission->status;
  1874. $newentry->teacher = $USER->id;
  1875. if (!$DB->update_record('iassign_submission', $newentry))
  1876. print_error('error_update', 'iassign');
  1877. else {
  1878. // Trigger module viewed event.
  1879. $event = \mod_iassign\event\submission_updated::create(array(
  1880. 'objectid' => $this->iassign->id,
  1881. 'context' => $this->context
  1882. ));
  1883. $event->add_record_snapshot('course', $this->course);
  1884. $event->trigger();
  1885. $this->action = 'viewsubmission';
  1886. $this->view_iassign_current();
  1887. } // if (!$DB->update_record('iassign_submission', $newentry))
  1888. } // function edit_status()
  1889. /// Editing grade of interactive activities
  1890. function edit_grade () {
  1891. global $USER, $DB, $OUTPUT;
  1892. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1893. if ($newgrade && $newgrade >= 0) {
  1894. $newentry = new stdClass();
  1895. $newentry->id = $this->iassign_submission_current;
  1896. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1897. $newentry->teacher = $USER->id;
  1898. if (!$DB->update_record('iassign_submission', $newentry))
  1899. print_error('error_update', 'iassign');
  1900. else {
  1901. // Trigger module viewed event.
  1902. $event = \mod_iassign\event\submission_updated::create(array(
  1903. 'objectid' => $this->iassign->id,
  1904. 'context' => $this->context
  1905. ));
  1906. $event->add_record_snapshot('course', $this->course);
  1907. $event->trigger();
  1908. }
  1909. } // if ($newgrade >= 0)
  1910. $this->action = 'viewsubmission';
  1911. $this->view_iassign_current();
  1912. }
  1913. /// Add or Edit interactive activities
  1914. // Get here when editing form and and submitted form data
  1915. // @calledby $this->action()
  1916. function add_edit_iassign () {
  1917. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1918. require_once('iassign_form.php');
  1919. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1920. $iassignid = $this->iassign->id;
  1921. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1922. $param->action = $this->action; // hidden
  1923. $param->id = $id; // hidden
  1924. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1925. $COURSE->cm = $id;
  1926. $COURSE->iassignid = $iassignid;
  1927. $COURSE->iassign_file_id = NULL;
  1928. $context = context_module::instance($this->cm->id);
  1929. $contextuser = context_user::instance($USER->id);
  1930. $component = 'mod_iassign';
  1931. $filearea = 'exercise';
  1932. if (!empty($this->iassign_current))
  1933. $COURSE->iassign_id = $this->iassign_current;
  1934. else
  1935. $COURSE->iassign_id = 0;
  1936. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1937. if ($this->action == 'add') {
  1938. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1939. $params_temp = array('iassignid' => $iassignid);
  1940. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1941. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1942. $total_of_activities = count($iassign_statement);
  1943. $param->iassignid = $iassignid;
  1944. $param->name = "";
  1945. $param->oldname = "";
  1946. $param->type_iassign = 3;
  1947. $param->proposition = "";
  1948. $author = $DB->get_record("user", array("id" => $USER->id));
  1949. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1950. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1951. $param->author = $param->author_name;
  1952. $param->author_modified = $param->author_modified_name;
  1953. $COURSE->iassign_list = array();
  1954. $param->iassign_list = array();
  1955. if ($iassign_statement) {
  1956. foreach ($iassign_statement as $iassign) {
  1957. $iassignid = $iassign->id;
  1958. $param->iassign_list[$iassignid] = 0;
  1959. $COURSE->iassign_list[$iassignid] = new stdClass();
  1960. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1961. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1962. $COURSE->iassign_list[$iassignid]->enable = 1;
  1963. } // foreach ($iassign_statement as $iassign)
  1964. }
  1965. $param->iassign_ilmid = 0;
  1966. $param->file = 0;
  1967. $param->fileold = 0;
  1968. $param->filename = "";
  1969. $param->grade = $iassign_data->grade;
  1970. $param->timemodified = time();
  1971. $param->timecreated = time();
  1972. $param->timeavailable = $iassign_data->timeavailable;
  1973. $param->timedue = $iassign_data->timedue;
  1974. $param->preventlate = $iassign_data->preventlate;
  1975. $param->test = $iassign_data->test;
  1976. $param->special_param1 = 0;
  1977. $param->visible = 1;
  1978. $param->max_experiment = $iassign_data->max_experiment;
  1979. $param->dependency = 0;
  1980. $param->automatic_evaluate = 1;
  1981. $param->show_answer = 1;
  1982. } // if ($this->action == 'add')
  1983. elseif ($this->action == 'edit') {
  1984. $COURSE->iassign_list = array();
  1985. $this_activity = $this->activity->get_activity();
  1986. if ($this_activity != null) { // first enter here: fill form data
  1987. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1988. $param->iassign_id = $iassign_statement_current->id; // oculto
  1989. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1990. $param->name = $iassign_statement_current->name;
  1991. $param->oldname = $iassign_statement_current->name;
  1992. $param->type_iassign = $iassign_statement_current->type_iassign;
  1993. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1994. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1995. $param->author_name = $iassign_statement_current->author_name; // oculto
  1996. $param->author = $iassign_statement_current->author_name;
  1997. $author = $DB->get_record("user", array('id' => $USER->id));
  1998. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1999. $param->author_modified = $param->author_modified_name;
  2000. $dependency = explode(';', $iassign_statement_current->dependency);
  2001. $param->iassign_list = array();
  2002. // Select all other iAssign activities inside this block with dependency
  2003. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  2004. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  2005. $array_dependency = array();
  2006. $subdependency = "";
  2007. $sub_subdependency = "";
  2008. // Dependents on this exercise
  2009. if ($iassign_statement_dependency) {
  2010. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  2011. // to whom this exercise depends
  2012. foreach ($inter as $tmp)
  2013. $sub_subdependency .= $this->search_sub_dependency($tmp);
  2014. $list_dependency = $subdependency . $sub_subdependency;
  2015. $array_dependency = explode(";", $list_dependency);
  2016. }
  2017. // Get all activities in the same iAssigment block:
  2018. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  2019. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  2020. $total_of_activities = count($all_others_iassign_statement) + 1;
  2021. $inter = array();
  2022. if ($all_others_iassign_statement) {
  2023. foreach ($all_others_iassign_statement as $iassign)
  2024. if (in_array($iassign->id, $dependency))
  2025. $inter[] = $iassign->id;
  2026. }
  2027. if ($all_others_iassign_statement) {
  2028. foreach ($all_others_iassign_statement as $iassign) {
  2029. $iassignid = $iassign->id;
  2030. $COURSE->iassign_list[$iassignid] = new stdClass();
  2031. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  2032. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  2033. if (in_array($iassignid, $dependency))
  2034. $param->iassign_list[$iassignid] = 1;
  2035. else
  2036. $param->iassign_list[$iassignid] = 0;
  2037. if (in_array($iassignid, $array_dependency))
  2038. $COURSE->iassign_list[$iassignid]->enable = 0;
  2039. else
  2040. $COURSE->iassign_list[$iassignid]->enable = 1;
  2041. } // foreach ($all_others_iassign_statement as $iassign)
  2042. } // if ($all_others_iassign_statement)
  2043. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  2044. $param->fileold = 0;
  2045. $param->filesid = 0;
  2046. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  2047. $param->filename = '';
  2048. $param->grade = $iassign_statement_current->grade;
  2049. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  2050. $param->timeavailable = $iassign_statement_current->timeavailable;
  2051. $param->timedue = $iassign_statement_current->timedue;
  2052. $param->preventlate = $iassign_statement_current->preventlate;
  2053. $param->test = $iassign_statement_current->test;
  2054. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  2055. $param->position = $iassign_statement_current->position; // hidden
  2056. $param->visible = $iassign_statement_current->visible;
  2057. $param->max_experiment = $iassign_statement_current->max_experiment;
  2058. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  2059. $param->show_answer = $iassign_statement_current->show_answer;
  2060. $fs = get_file_storage(); // Get reference to all files in Moodle data
  2061. //2021/12 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  2062. //2022/02 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id); // em alguns "_files.id" tem 'file' NAO 'id'
  2063. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file); // It must have: {files}->id=$iassign_statement_current->file
  2064. if ($files) {
  2065. foreach ($files as $file) {
  2066. if ($file->get_filename() != '.') {
  2067. $param->filename = $file->get_filename();
  2068. $param->file = $file->get_id();
  2069. $param->fileold = $file->get_id();
  2070. $COURSE->iassign_file_id = $file->get_id();
  2071. }
  2072. }
  2073. }
  2074. //TODO //MOOC2014 -- inicio
  2075. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  2076. //D if ($iassign_ilm_configs) {
  2077. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  2078. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  2079. //D } //MOOC2014 -- fim
  2080. } // if ($this_activity != null)
  2081. } // elseif ($this->action == 'edit')
  2082. // Get all iActivity in the iAssign block with id = $this->iassign->id
  2083. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  2084. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  2085. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  2086. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  2087. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  2088. $param->position = $total_of_activities;
  2089. // Create form and associate its data
  2090. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  2091. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  2092. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  2093. if (isset($param->iassign_ilmid)) {
  2094. // array is additional atributes to 'form'
  2095. // '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)"
  2096. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  2097. }
  2098. else {
  2099. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  2100. }
  2101. $mform->set_data($param); // define data in the form
  2102. if ($mform->is_cancelled()) {
  2103. $this->return_home_course('iassign_cancel');
  2104. exit;
  2105. }
  2106. else { // else if ($mform->is_cancelled())
  2107. $result = $mform->get_data();
  2108. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  2109. if ($result) {
  2110. $result->context = $context;
  2111. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  2112. $result->grade = 0;
  2113. if ($result->type_iassign == 1) {
  2114. $result->automatic_evaluate = 0;
  2115. $result->show_answer = 0;
  2116. }
  2117. elseif ($result->automatic_evaluate == 0)
  2118. $result->show_answer = 0;
  2119. // $_POST['iassign_list']
  2120. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  2121. if ($result->iassign_list) {
  2122. foreach ($result->iassign_list as $key => $value)
  2123. $result->dependency .= $key . ';';
  2124. }
  2125. else
  2126. $result->dependency = 0;
  2127. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  2128. //TODO Then get it directly from the form data $_POST!
  2129. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  2130. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  2131. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  2132. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  2133. if ($this->action == 'add') {
  2134. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  2135. if ($iassign_statement_name) {
  2136. $this->return_home_course('error_iassign_name');
  2137. die();
  2138. }
  2139. // Really insert the new iActivity in table '*_iassign_statement'
  2140. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  2141. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  2142. // Trigger module viewed event.
  2143. $event = \mod_iassign\event\iassign_created::create(array(
  2144. 'objectid' => $iassignid,
  2145. 'context' => $context
  2146. ));
  2147. $event->add_record_snapshot('course', $this->course);
  2148. $event->trigger();
  2149. $this->return_home_course('iassign_add');
  2150. } // if ($this->action == 'add')
  2151. elseif ($this->action == 'edit') {
  2152. $iassignid = $this->activity->update_iassign($result);
  2153. $this->activity->update_calendar($iassignid, $result->oldname);
  2154. // Trigger module viewed event.
  2155. $event = \mod_iassign\event\iassign_updated::create(array(
  2156. 'objectid' => $iassignid,
  2157. 'context' => $context
  2158. ));
  2159. $event->add_record_snapshot('course', $this->course);
  2160. $event->trigger();
  2161. $this->return_home_course('iassign_update');
  2162. } // elseif ($this->action == 'edit')
  2163. die();
  2164. } // if ($result)
  2165. } // else if ($mform->is_cancelled())
  2166. print $OUTPUT->header();
  2167. $mform->display();
  2168. print $OUTPUT->footer();
  2169. die();
  2170. } // function add_edit_iassign()
  2171. /// Search for dependencies
  2172. function search_dependency ($search_iassing_id, $iassign_statement) {
  2173. global $DB, $OUTPUT;
  2174. $dependency = "";
  2175. if ($iassign_statement)
  2176. foreach ($iassign_statement as $iassign) {
  2177. $inter_dependency = explode(';', $iassign->dependency);
  2178. if (in_array($search_iassing_id, $inter_dependency)) {
  2179. $dependency .= $iassign->id . ";";
  2180. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2181. } // if (in_array($search_iassing_id, $inter_dependency))
  2182. } // foreach ($iassign_statement as $iassign)
  2183. return $dependency;
  2184. }
  2185. /// Search for "sub"dependency
  2186. function search_sub_dependency ($search_iassing_id) {
  2187. global $DB, $OUTPUT;
  2188. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2189. $dependency = "";
  2190. if ($iassign_statement) {
  2191. $inter_dependency = explode(';', $iassign_statement->dependency);
  2192. foreach ($inter_dependency as $tmp) {
  2193. if ($tmp != 0)
  2194. $dependency .= $tmp . ";";
  2195. $dependency .= $this->search_sub_dependency($tmp);
  2196. } // foreach ($inter_dependency as $tmp)
  2197. } // if ($iassign_statement)
  2198. return $dependency;
  2199. }
  2200. // Warning message
  2201. static function warning_message_iassign ($strcode) {
  2202. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2203. }
  2204. /// Update grade of iAssign
  2205. // Called always any iAssign activity is created
  2206. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2207. static function update_grade_iassign ($iassignid) {
  2208. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2209. require_once($CFG->libdir . '/gradelib.php');
  2210. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2211. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2212. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2213. // Each iAssign item is associated with one item on the "gradebook"
  2214. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2215. //$sum_grade = 0;
  2216. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2217. //foreach($grade as $tmp) {
  2218. // $sum_grade += $tmp->grade;
  2219. // }
  2220. //1 Solution 1
  2221. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2222. //1 $sum_grade = 0; //1
  2223. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2224. //2 Solution 2
  2225. $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
  2226. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2227. if (key($array_sum_grade))
  2228. $sum_grade = key($array_sum_grade); //2
  2229. else
  2230. $sum_grade = 0; //2
  2231. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2232. $grades = NULL;
  2233. $params_temp = array('itemname' => $grade_iassign->name);
  2234. $params_temp['iteminstance'] = $iassignid;
  2235. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2236. //2016 if ($sum_grade != 0) {
  2237. $params_temp['grademax'] = $sum_grade;
  2238. $params_temp['rawgrademax'] = $sum_grade;
  2239. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2240. $params_temp['grademin'] = 0;
  2241. // @calls /lib/gradelib.php: call to grade_item->insert()
  2242. //TODO: is there any error here in Moodle version 3.0?
  2243. //TODO: Incorrect property 'grademax' found when inserting grade object
  2244. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2245. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2246. }
  2247. /// Update grade of student
  2248. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2249. global $CFG, $DB, $OUTPUT;
  2250. require_once($CFG->libdir . '/gradelib.php');
  2251. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2252. // Review all the student submission for this iAssign activity
  2253. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2254. $total_grade = 0;
  2255. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2256. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2257. if ($iassign_submission)
  2258. $total_grade += $iassign_submission->grade;
  2259. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2260. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2261. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2262. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2263. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2264. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2265. $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
  2266. if (key($array_sum_grade))
  2267. $sum_grade = key($array_sum_grade); //2
  2268. else
  2269. $sum_grade = 0; //2
  2270. $grades['userid'] = $userid;
  2271. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2272. $params_temp = array('itemname' => $grade_iassign->name);
  2273. $params_temp['iteminstance'] = $iassignid;
  2274. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2275. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2276. $params_temp['grademax'] = $sum_grade;
  2277. $params_temp['rawgrademax'] = $sum_grade;
  2278. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2279. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2280. }
  2281. /// Display caption of icons - to the bottom page of teacher's report
  2282. function view_legend_icons () {
  2283. global $USER, $CFG, $DB, $OUTPUT;
  2284. $id = $this->cm->id;
  2285. if ($this->action == 'print')
  2286. print '<table border=1 width=100%><tr>';
  2287. else
  2288. print '<table width=100%><tr>';
  2289. print '<td >';
  2290. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2291. if ($this->action != 'print') {
  2292. $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";
  2293. $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";
  2294. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2295. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2296. } // if ($this->action != 'print')
  2297. print '</tr></table>' . "\n";
  2298. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2299. print '</td></tr></table>' . "\n";
  2300. } // function view_legend_icons()
  2301. /// Display activity current
  2302. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2303. function view_iassign_current () {
  2304. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2305. $id = $this->cm->id;
  2306. $iassignid = $this->iassign->id;
  2307. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2308. $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
  2309. // 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 ...
  2310. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2311. if (!$iassign_statement_activity_item) {
  2312. print $OUTPUT->header();
  2313. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2314. print $OUTPUT->footer();
  2315. exit;
  2316. }
  2317. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2318. $ilm_name = '';
  2319. if ($ilm->ilm)
  2320. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2321. // 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
  2322. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2323. // log record
  2324. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2325. //Trigger module viewed event.
  2326. $event = \mod_iassign\event\submission_viewed::create(array(
  2327. 'objectid' => $iassign->id,
  2328. 'context' => $this->context,
  2329. 'other' => $info
  2330. ));
  2331. $event->add_record_snapshot('course', $this->course);
  2332. $event->trigger();
  2333. // Search of iLM data used in the current activity
  2334. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2335. // Add actual activity to navbar:
  2336. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2337. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2338. print $OUTPUT->header();
  2339. if ($this->action == 'viewsubmission') {
  2340. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2341. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2342. else
  2343. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2344. } else {
  2345. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2346. }
  2347. if ($iassign_submission)
  2348. $this->update_comment($iassign_submission->id);
  2349. //2021/12 $file = $iassign_statement_activity_item->filesid;
  2350. $file = $iassign_statement_activity_item->id;
  2351. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2352. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2353. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2354. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2355. $this->bottonPost = 0; // hide submit button
  2356. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2357. $this->view_iassign = false; // disable visualization of activity
  2358. $repeat = "";
  2359. $last_iassign = "";
  2360. $student_answer = "";
  2361. $comment = "";
  2362. // *** Teacher access (view learner's submission)
  2363. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2364. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2365. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2366. // ---> access teacher for test
  2367. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2368. $this->bottonPost = 1;
  2369. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2370. $this->activity->view_dates();
  2371. $USER->iassignEdit = $this->bottonPost;
  2372. $this->activity->show_info_iassign();
  2373. if ($iassign_submission) {
  2374. //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;
  2375. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2376. } else {
  2377. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2378. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2379. }
  2380. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2381. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2382. // Prepare tags to present the iLM
  2383. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2384. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2385. // *** (end) Teacher access (view the activity)
  2386. // *** Teacher access (view learner's submission to the activity)
  2387. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2388. // It is teacher or 'nonediting teacher' that can evaluate
  2389. // ----> area teacher evaluate
  2390. $row = optional_param('row', 0, PARAM_INT);
  2391. $column = optional_param('column', 0, PARAM_INT);
  2392. $link_next = iassign_icons::insert('right_disable');
  2393. $link_previous = iassign_icons::insert('left_disable');
  2394. $link_up = iassign_icons::insert('up_disable');
  2395. $link_down = iassign_icons::insert('down_disable');
  2396. if (isset($USER->matrix_iassign[$row][$column])) {
  2397. $has_row_column = True;
  2398. $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
  2399. }
  2400. else {
  2401. $has_row_column = False;
  2402. $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
  2403. }
  2404. $msgViewAction = "view.php?action=viewsubmission&id=$id&iassign_submission_current=";
  2405. $msgUserId_current = "&userid_iassign=" . $this->userid_iassign . "&iassign_current=";
  2406. // next_activity
  2407. if ($has_row_column && $element_matrix_iassign->iassign_next != - 1) {
  2408. $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);
  2409. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2410. }
  2411. // previous_activity
  2412. if ($has_row_column && $element_matrix_iassign->iassign_previous != - 1) {
  2413. $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);
  2414. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2415. }
  2416. // previous_student
  2417. if ($has_row_column && $element_matrix_iassign->user_next != - 1) {
  2418. $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);
  2419. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2420. }
  2421. // next_student
  2422. if ($has_row_column && $element_matrix_iassign->user_previous != - 1) {
  2423. $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);
  2424. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2425. }
  2426. if ($iassign_submission) {
  2427. $student_answer = $iassign_submission->answer;
  2428. }
  2429. $last_iassign = get_string('last_iassign', 'iassign');
  2430. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2431. // Messages related to due date (and user role)
  2432. $this->activity->view_dates();
  2433. print $OUTPUT->box_start();
  2434. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2435. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2436. if ($user_data) // additional security (if occurs programming errors in $$url_next, $url_previous...)
  2437. print $OUTPUT->user_picture($user_data);
  2438. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2439. print '</td>' . "\n";
  2440. print '<td width=20% align=right>' . "\n";
  2441. print '<table width=50 cellpadding="0">';
  2442. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2443. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2444. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2445. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2446. print '</table>' . "\n";
  2447. print '</td></tr></table>' . "\n";
  2448. print $OUTPUT->box_end();
  2449. print $OUTPUT->box_start();
  2450. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2451. print '<td width=60% valign="top">' . "\n";
  2452. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2453. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2454. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2455. $resp = get_string('yes');
  2456. else
  2457. $resp = get_string('no');
  2458. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2459. if ($iassign_statement_activity_item->show_answer == 1)
  2460. $resp = get_string('yes');
  2461. else
  2462. $resp = get_string('no');
  2463. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2464. print '</td>';
  2465. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2466. print '<td width=40% valign="top" align="left">';
  2467. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2468. // check status of solution sent by the student
  2469. if ($iassign_submission) {
  2470. switch ($iassign_submission->status) {
  2471. case 3 :
  2472. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2473. break;
  2474. case 2 :
  2475. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2476. break;
  2477. case 1 :
  2478. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2479. break;
  2480. default :
  2481. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2482. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2483. } // switch ($iassign_submission->status)
  2484. }
  2485. else { // if ($iassign_submission)
  2486. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2487. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2488. }
  2489. // update_status
  2490. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2491. $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);
  2492. print " <script type='text/javascript'>
  2493. //<![CDATA[
  2494. function overwriteStatus (newstatus) {
  2495. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2496. document.formEditStatus.return_status.value=newstatus;
  2497. document.formEditStatus.submit();
  2498. }
  2499. else
  2500. document.formEditStatus.return_status.value=-1;
  2501. }
  2502. //]]>
  2503. </script>";
  2504. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2505. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2506. 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";
  2507. print " <input type='hidden' name='return_status'>\n";
  2508. print "</form>\n";
  2509. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2510. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2511. $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);
  2512. print "
  2513. <script type='text/javascript'>
  2514. //<![CDATA[
  2515. function overwriteGrade (newgrade,maxgrade) {
  2516. if (newgrade<0 || newgrade>maxgrade) {
  2517. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2518. document.formEditGrade.return_grade.value=-1;
  2519. document.formEditGrade.submit();
  2520. }
  2521. else {
  2522. document.formEditGrade.return_grade.value=newgrade;
  2523. document.formEditGrade.submit();
  2524. }
  2525. }
  2526. //]]>
  2527. </script>";
  2528. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2529. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2530. print " <input type='text' name='grade' size='6'>";
  2531. print " <input type='hidden' name='return_grade'> ";
  2532. 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";
  2533. print "</form>";
  2534. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2535. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2536. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2537. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2538. if ($teacher)
  2539. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2540. } // if ($iassign_submission->experiment > 0)
  2541. print '</td>';
  2542. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2543. print '</tr></table>';
  2544. print $OUTPUT->box_end();
  2545. $USER->iassignEdit = $this->bottonPost;
  2546. print activity::toggle_columns_script();
  2547. if ($iassign_submission && $allow_resubmission) {
  2548. // Put the iLM to
  2549. print $OUTPUT->box_start();
  2550. print '<p><strong>' . $last_iassign . '</strong></p>';
  2551. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2552. $enderecoPOST = "";
  2553. // Prepare tags to present the iLM
  2554. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2555. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2556. print $OUTPUT->box_end();
  2557. } // if ($iassign_submission && $allow_resubmission)
  2558. else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2559. // If '$student_answer' is empty, then the student does not submit any solution to the exercice
  2560. // ATTENTION: exception used by iGeom (exercise with "script")
  2561. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2562. if (substr($ilm_name, 0, 5)=="igeom") {
  2563. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2564. $loadTeacherActivity = true;
  2565. }
  2566. else
  2567. if (!$student_answer) { //2022/01 this student does not submit any soluction => load the teacher content
  2568. $loadTeacherActivity = true;
  2569. }
  2570. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2571. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2572. print activity::toggle_columns_script();
  2573. // Prepare tags to present the iLM
  2574. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2575. }
  2576. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2577. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2578. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2579. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2580. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2581. // *** (end) Teacher access (view learner's submission to the activity)
  2582. // *** Student access (view the activity)
  2583. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2584. // It could be the learner (he could send or resend the activity)
  2585. // ---> access student
  2586. $time_now = time();
  2587. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2588. // activity of type example - not submit button for submission
  2589. $this->view_iassign = true;
  2590. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2591. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2592. // activity of type test - iLM automatic evaluator - submit button for submission
  2593. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2594. $this->bottonPost = 1;
  2595. $this->view_iassign = true;
  2596. } else
  2597. $this->view_iassign = false;
  2598. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2599. // activity of type exercise (learner can send his answer, if yet open...)
  2600. $this->view_iassign = true;
  2601. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2602. $this->view_iassign = false;
  2603. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2604. $this->bottonPost = 1; // allow the submit button
  2605. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2606. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2607. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2608. if (!$iassign_submission) {
  2609. $str_iassign_submission_id = '';
  2610. $str_iassign_submission_answer = '';
  2611. }
  2612. else {
  2613. $str_iassign_submission_id = $iassign_submission->id;
  2614. $str_iassign_submission_answer = $iassign_submission->answer;
  2615. }
  2616. if ($this->action != 'repeat') {
  2617. $repeat = "<a href='view.php?action=repeat&id="
  2618. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2619. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2620. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2621. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2622. }
  2623. $this->bottonPost = 1;
  2624. $this->write_solution = 1; // can register his submission
  2625. $student_answer = $str_iassign_submission_answer;
  2626. }
  2627. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2628. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2629. $last_iassign = get_string('last_iassign', 'iassign');
  2630. if ($iassign_submission) {
  2631. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2632. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2633. $student_answer = $iassign_submission->answer;
  2634. } else {
  2635. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2636. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2637. }
  2638. }
  2639. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2640. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2641. $this->bottonPost = 1;
  2642. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2643. } else {
  2644. $last_iassign = get_string('last_iassign', 'iassign');
  2645. if ($iassign_submission) {
  2646. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2647. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2648. $student_answer = $iassign_submission->answer;
  2649. } else {
  2650. // Symbol of "redo activity"
  2651. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2652. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2653. }
  2654. }
  2655. } // elseif ($iassign_statement_activity_item->test == 1)
  2656. elseif ($iassign_statement_activity_item->test == 0)
  2657. $this->view_iassign = false;
  2658. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2659. if ($iassign_submission)
  2660. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2661. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2662. else
  2663. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2664. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2665. $this->activity->view_dates();
  2666. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2667. print $OUTPUT->box_start();
  2668. print '<table width=100% border=0 valign="top">' . "\n";
  2669. print '<tr><td width=60% valign="top">' . "\n";
  2670. $flag_dependency = true;
  2671. if ($iassign_statement_activity_item->type_iassign == 3) {
  2672. if ($iassign_statement_activity_item->dependency == 0) {
  2673. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2674. } else {
  2675. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2676. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2677. foreach ($dependencys as $dependency) {
  2678. if ($dependency) {
  2679. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2680. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2681. if ($dependencysubmissions) {
  2682. if ($dependencysubmissions->status == 3)
  2683. $icon = iassign_icons::insert('correct');
  2684. elseif ($dependencysubmissions->status == 2) {
  2685. $icon = iassign_icons::insert('incorrect');
  2686. $flag_dependency = false;
  2687. } elseif ($dependencysubmissions->status == 1) {
  2688. $icon = iassign_icons::insert('post');
  2689. $flag_dependency = false;
  2690. } elseif ($dependencysubmissions->status == 0) {
  2691. $icon = iassign_icons::insert('not_post');
  2692. $flag_dependency = false;
  2693. }
  2694. } else {
  2695. $icon = iassign_icons::insert('not_post');
  2696. $flag_dependency = false;
  2697. } // if ($dependencysubmissions)
  2698. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2699. } // if ($dependency)
  2700. } // foreach ($dependencys as $dependency)
  2701. } // if ($iassign_statement_activity_item->dependency == 0)
  2702. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2703. if ($flag_dependency == false) {
  2704. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2705. $this->view_iassign = false;
  2706. print '</tr></table>' . "\n";
  2707. }
  2708. else {
  2709. $this->view_iassign = true;
  2710. print '</td>' . "\n";
  2711. } // if ($flag_dependency == false)
  2712. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2713. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2714. // receiver=1 - message to teacher
  2715. // receiver=2 - message to student
  2716. if ($iassign_submission) {
  2717. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2718. if ($verify_message)
  2719. $comment = iassign_icons::insert('comment_unread');
  2720. }
  2721. print '<td width=40% valign="top" align="left">';
  2722. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2723. if ($iassign_statement_activity_item->show_answer == 1) {
  2724. // check status of solution sent by the student
  2725. if ($iassign_submission) {
  2726. switch ($iassign_submission->status) {
  2727. case 3 :
  2728. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2729. break;
  2730. case 2 :
  2731. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2732. break;
  2733. case 1 :
  2734. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2735. break;
  2736. default :
  2737. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2738. $repeat = "";
  2739. $last_iassign = "";
  2740. } // switch ($iassign_submission->status)
  2741. } else {
  2742. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2743. $repeat = "";
  2744. $last_iassign = "";
  2745. }
  2746. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2747. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2748. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2749. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2750. if ($iassign_statement_activity_item->max_experiment == 0)
  2751. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2752. else {
  2753. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2754. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2755. $repeat = "";
  2756. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2757. $this->bottonPost = 0;
  2758. $this->write_solution = 0;
  2759. }
  2760. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2761. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2762. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2763. if ($teacher)
  2764. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2765. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2766. } // if ($iassign_statement_activity_item->show_answer==1)
  2767. else {
  2768. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2769. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2770. $repeat = "";
  2771. $last_iassign = "";
  2772. } elseif ($iassign_submission->status == 1) {
  2773. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2774. }
  2775. }
  2776. print '</td>';
  2777. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2778. print '</tr></table>' . "\n";
  2779. // Presents the iLM
  2780. print '<table width=100% border=0 valign="top">' . "\n";
  2781. print '<td width=80% align="left">';
  2782. 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\".
  2783. print '<td width=20% align="rigth">';
  2784. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2785. print $repeat; // symbol of "redo activity"
  2786. print '</td></tr></table>' . "\n";
  2787. //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)'
  2788. print activity::toggle_columns_script();
  2789. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2790. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2791. $output = '';
  2792. if (!$iassign_ilm) {
  2793. $iassign_ilm = new stdClass();
  2794. $iassign_ilm->file_jar = "";
  2795. }
  2796. $output .= $OUTPUT->box_start();
  2797. $USER->iassignEdit = $this->bottonPost;
  2798. // ---
  2799. // Presents the iLM
  2800. // Prepare tags to present the iLM
  2801. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2802. $student_answer = ""; //?
  2803. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2804. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2805. $student_answer = "";
  2806. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2807. } else {
  2808. // When student is redoing his activity
  2809. // ATTENTION: exception used by iGeom (exercise with "script")
  2810. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2811. if (substr($ilm_name, 0, 5)=="igeom") {
  2812. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2813. $loadTeacherActivity = true;
  2814. }
  2815. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2816. }
  2817. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2818. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2819. //1 $history_comment = '';
  2820. //1 if ($iassign_submission) {
  2821. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2822. //1 }
  2823. //1 if (!empty($history_comment)) {
  2824. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2825. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2826. //1 $output .= $history_comment;
  2827. //1 $output .= "</table>\n";
  2828. //1 }
  2829. //1 $output .= "</form></center>\n";
  2830. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2831. //1 }
  2832. $output .= $OUTPUT->box_end();
  2833. print $output;
  2834. } // if ($this->view_iassign)
  2835. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2836. } // if ($this->view_iassign)
  2837. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2838. else
  2839. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2840. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2841. print '<table width=100% border=0 valign="top">' . "\n";
  2842. print '<tr><td width=60% valign="top">' . "\n";
  2843. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2844. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2845. print '</tr></table>' . "\n";
  2846. $student_answer = "";
  2847. $enderecoPOST = "";
  2848. // Prepare tags to present the iLM
  2849. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2850. print $output;
  2851. }
  2852. //2020 Frame with area to send and read comments (in this point to allow everyone read)
  2853. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2854. 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
  2855. // Put a block with area to sent/answer comments
  2856. $output = '';
  2857. $history_comment = '';
  2858. $row = optional_param('row', 0, PARAM_INT);
  2859. $column = optional_param('column', 0, PARAM_INT);
  2860. if ($iassign_submission) {
  2861. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2862. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2863. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2864. }
  2865. else {
  2866. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2867. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2868. }
  2869. $output .= $OUTPUT->box_start();
  2870. //if (!empty($history_comment)) {
  2871. $output .= "<a id='comments'></a>";
  2872. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2873. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2874. $output .= "</table>";
  2875. print " <script type='text/javascript'>
  2876. //<![CDATA[
  2877. function submit_comment(url) {
  2878. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2879. var formData = new FormData();
  2880. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2881. var request = new XMLHttpRequest();
  2882. request.open('POST', url);
  2883. document.getElementById('comments_history').innerHTML = '';
  2884. request.onload = function (e) {
  2885. if (request.readyState === 4) {
  2886. if (request.status === 200) {
  2887. document.getElementById('comments_history').innerHTML = request.responseText;
  2888. document.getElementById('check-message-success').style.visibility = 'visible';
  2889. setTimeout(function(){
  2890. document.getElementById('check-message-success').style.visibility = 'hidden';
  2891. }, 3000);
  2892. }
  2893. }
  2894. };
  2895. document.formEnvioComment.submission_comment.value = '';
  2896. request.send(formData);
  2897. }
  2898. function event_text_area (event) {
  2899. if (event.ctrlKey && event.keyCode == 13)
  2900. submit_comment('" . $enderecoPOSTcomment . "');
  2901. }
  2902. //]]>
  2903. </script>";
  2904. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2905. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
  2906. $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";
  2907. $output .= "</form> </center>\n";
  2908. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2909. // }
  2910. $output .= $OUTPUT->box_end();
  2911. print $output;
  2912. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2913. // final block 'studant'
  2914. print $OUTPUT->footer();
  2915. die();
  2916. } // function view_iassign_current()
  2917. /// Export the data from performance report into CSV file format
  2918. function export_csv () {
  2919. global $USER, $CFG, $DB, $OUTPUT;
  2920. $str = "";
  2921. $fields = "student_id, student_name";
  2922. // Finding all iassign activities for the iassign:
  2923. $id = $this->cm->id;
  2924. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2925. $c = 1;
  2926. foreach ($iassign_list as $iassign) {
  2927. $fields .= ", activity_id_" . $c . ", activity_name_" . $c . ", total_submissions_activity_" . $c . ", grade_activity_" . $c . ""
  2928. . ", status_activity_" . $c . ", ilm_id_activity_" . $c . ", ilm_name_activity_" . $c;
  2929. $c++;
  2930. }
  2931. // Finding enrolled students:
  2932. $params_temp = array('shortname' => 'student');
  2933. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2934. $context = context_course::instance($this->course->id);
  2935. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2936. $students = $DB->get_records_sql(
  2937. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2938. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2939. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2940. foreach ($students as $student) {
  2941. $str .= $student->userid . ',';
  2942. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2943. foreach ($iassign_list as $iassign) {
  2944. $str .= ',' . $iassign->id . ',';
  2945. $str .= '"' . $iassign->name . '",';
  2946. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2947. if ($student_submissions) {
  2948. $str .= $student_submissions->experiment . ',';
  2949. $str .= $student_submissions->grade . ',';
  2950. switch ($student_submissions->status) {
  2951. case 3:
  2952. $str .= '"correct",';
  2953. break;
  2954. case 2:
  2955. $str .= '"incorrect",';
  2956. break;
  2957. case 1:
  2958. $str .= '"post",';
  2959. break;
  2960. case 0:
  2961. $str .= '"not_post",';
  2962. break;
  2963. }
  2964. }
  2965. else {
  2966. $str .= ',,"not_post",';
  2967. }
  2968. $str .= $iassign->iassign_ilmid . ',';
  2969. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2970. $str .= '"' . $ilm_activity->name . '"';
  2971. }
  2972. $str .= "\n";
  2973. }
  2974. $str = $fields . "\n" . $str;
  2975. header("Content-type: text/csv");
  2976. header("Content-disposition: attachment; filename=report.csv");
  2977. header("Pragma: no-cache");
  2978. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2979. header('Content-Length: ' . strlen($str));
  2980. header('Connection: close');
  2981. print $str;
  2982. flush();
  2983. } // function export_csv()
  2984. /// Display report of performance
  2985. function report () {
  2986. global $USER, $CFG, $DB, $OUTPUT;
  2987. $id = $this->cm->id;
  2988. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2989. if ($this->action != 'print') {
  2990. $title = get_string('report', 'iassign');
  2991. print $OUTPUT->header();
  2992. } // if ($this->action != 'print')
  2993. $this->print_main_menu();
  2994. print $OUTPUT->box_start();
  2995. $this->view_legend_icons();
  2996. print $OUTPUT->box_end();
  2997. if ($this->action == 'print')
  2998. print '<table border=1 width="100%">' . "\n";
  2999. else
  3000. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
  3001. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3002. // $num = array();
  3003. $i = 1;
  3004. $num = array();
  3005. $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;";
  3006. foreach ($iassign_list as $iassign) { // for all exercise in this block
  3007. $test_exercise = "";
  3008. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3009. if (($iassign_submission) && $iassign->type_iassign < 3) {
  3010. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  3011. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  3012. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  3013. $num[$i] = new stdClass();
  3014. $num[$i]->name = $iassign->name;
  3015. $num[$i]->id = $i;
  3016. $num[$i]->iassignid = $iassign->id;
  3017. print ' <tr >' . "\n";
  3018. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  3019. print "<td class=\"cell c0 actvity\">";
  3020. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  3021. print ' </tr>' . "\n";
  3022. $i++;
  3023. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  3024. } // foreach ($iassign_list as $iassign)
  3025. $num_exerc = $i; // total of exercises
  3026. print "</table>";
  3027. print "<p></p>";
  3028. if ($this->action == 'print')
  3029. print '<table border=1 width="100%">' . "\n";
  3030. else // ./theme/boost/style/moodle.css: .generaltable
  3031. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  3032. $context = context_course::instance($this->course->id);
  3033. if ($num_exerc > 1) {
  3034. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3035. $params_temp = array('shortname' => 'student');
  3036. $role = $DB->get_record_sql(
  3037. "SELECT s.id, s.shortname FROM {role} s " .
  3038. " WHERE s.shortname = :shortname", $params_temp);
  3039. // $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");
  3040. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3041. $students = $DB->get_records_sql(
  3042. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3043. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3044. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3045. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  3046. $width = 90/$num_exerc;
  3047. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  3048. $sum_iassign_correct[$j] = 0;
  3049. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  3050. }
  3051. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  3052. $sum_iassign = $j - 1;
  3053. print '</tr>' . "\n";
  3054. $total = 0;
  3055. $sum_student = 0;
  3056. $comment = iassign_icons::insert('comment_read');
  3057. $sum_comment = 0;
  3058. $sum_correct_iassign = array();
  3059. $sum_correct_student = array();
  3060. $USER->matrix_iassign = array();
  3061. if ($students) {
  3062. $w = 0;
  3063. foreach ($students as $tmp) { // count students
  3064. $users_array[$w] = $tmp;
  3065. $w++;
  3066. }
  3067. for ($x=0; $x<$w; $x++) { // for all students
  3068. print '<tr>' . "\n";
  3069. $sum_student++;
  3070. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  3071. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  3072. $total_student = 0;
  3073. $tentativas = 0;
  3074. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  3075. $sum_comment = $sum_verify_message = 0;
  3076. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  3077. if ($student_submissions) {
  3078. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  3079. $tentativas = $student_submissions->experiment;
  3080. // Get student comments
  3081. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  3082. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  3083. $student_submissions_comment = $DB->get_record_sql(
  3084. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3085. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  3086. if ($student_submissions_comment) // student has comment
  3087. foreach ($student_submissions_comment as $tmp)
  3088. $sum_comment = $tmp;
  3089. // informations to previous activities
  3090. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  3091. else $iassign_previous = $num[$j - 1]->iassignid;
  3092. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3093. else $user_previous = $users_array[$x - 1]->userid;
  3094. // next
  3095. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3096. else $iassign_next = "-1";
  3097. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3098. else $user_next = "-1";
  3099. $position = "&row= $x&column=$j";
  3100. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  3101. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3102. $url .= $position;
  3103. // receiver=1 - message to teacher
  3104. // receiver=2 - message to student
  3105. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  3106. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  3107. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  3108. $verify_message = $DB->get_record_sql(
  3109. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3110. "WHERE iassign_submissionid = :iassign_submissionid " .
  3111. " AND return_status= :return_status " .
  3112. " AND receiver= :receiver", $params_temp);
  3113. if ($verify_message)
  3114. foreach ($verify_message as $tmp)
  3115. $sum_verify_message = $tmp;
  3116. if ($sum_verify_message > 0)
  3117. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  3118. else
  3119. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  3120. if ($student_submissions->status == 3) {
  3121. $sum_iassign_correct[$j]++;
  3122. $total_student++;
  3123. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  3124. }
  3125. elseif ($student_submissions->status == 2) {
  3126. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  3127. }
  3128. elseif ($student_submissions->status == 1) {
  3129. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3130. }
  3131. elseif ($student_submissions->status == 0) {
  3132. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3133. }
  3134. if ($this->action != 'print') {
  3135. if ($tentativas > 0)
  3136. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3137. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3138. . $feedback
  3139. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3140. . $tentativas
  3141. . '</span> </button>'
  3142. . '</a>' . "\n";
  3143. else
  3144. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3145. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3146. . $feedback
  3147. .'</button>'
  3148. . '</a>' . "\n";
  3149. if ($sum_comment > 0 && $sum_verify_message > 0)
  3150. print '<a href="' . $url . '"> '
  3151. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3152. . $comment
  3153. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3154. . $sum_verify_message . '/' . $sum_comment
  3155. . '</span> </button>'
  3156. . '</a>';
  3157. else if ($sum_comment > 0)
  3158. print '<a href="' . $url . '"> '
  3159. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  3160. . $comment
  3161. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3162. . $sum_comment
  3163. . '</span> </button>'
  3164. . '</a>';
  3165. print '</td>' . "\n";
  3166. }
  3167. if ($this->action == 'print')
  3168. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3169. } // if ($student_submissions)
  3170. else { // if ($student_submissions)
  3171. // Student does not have any submission
  3172. // informations to browse previous activities
  3173. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3174. else $iassign_previous = $num[$j - 1]->iassignid;
  3175. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3176. else $user_previous = $users_array[$x - 1]->userid;
  3177. // next
  3178. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3179. else $iassign_next = "-1";
  3180. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3181. else $user_next = "-1";
  3182. $position = "&row= $x&column=$j";
  3183. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3184. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3185. $url .= $position;
  3186. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3187. if ($this->action == 'print')
  3188. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3189. else {
  3190. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3191. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3192. . $feedback
  3193. .'</button>'
  3194. . '</a>' . "\n";
  3195. // print '<td> &nbsp;</td>';
  3196. if ($sum_comment > 0)
  3197. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3198. // else print '<td> &nbsp;</td>';
  3199. print '</td>';
  3200. }
  3201. } // else if ($student_submissions)
  3202. $USER->matrix_iassign[$x][$j] = new stdClass();
  3203. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3204. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3205. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3206. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3207. if ($student_submissions)
  3208. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3209. else
  3210. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3211. //print '</td>' . "\n";
  3212. } // for ($j=1; $j<$num_exerc; $j++)
  3213. $total = $total + $total_student;
  3214. $porcentagem = ($total_student / ($j - 1)) * 100;
  3215. if ($tentativas != 0 && $tentativas != null) {
  3216. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3217. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3218. }
  3219. else {
  3220. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3221. }
  3222. print '</tr>' . "\n";
  3223. $sum_correct_student[$sum_student] = new stdClass();
  3224. $sum_correct_student[$sum_student]->name = $name;
  3225. $sum_correct_student[$sum_student]->sum = $total_student;
  3226. } // for ($x = 0; $x < $w; $x++)
  3227. for ($i = 1; $i < $j; $i++) {
  3228. if (is_null($sum_iassign_correct[$i]))
  3229. $sum_iassign_correct[$i] = 0;
  3230. $sum_correct_iassign[$i] = new stdClass();
  3231. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3232. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3233. }
  3234. // print '</tr></table>' . "\n";
  3235. }
  3236. } // if ($i>1)
  3237. else {
  3238. print_string('no_activity', 'iassign');
  3239. }
  3240. print "</table>\n";
  3241. print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . "</p>\n"; // the number of atemps is...
  3242. print '<p>' . get_string('ps_comment', 'iassign') . "</p>\n"; // the total number of messages is...
  3243. if ($this->action != 'print')
  3244. print $OUTPUT->footer();
  3245. die();
  3246. } // function report()
  3247. /// Display graphics of performance
  3248. function stats () {
  3249. global $USER, $CFG, $DB, $OUTPUT;
  3250. $id = $this->cm->id;
  3251. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3252. if ($this->action != 'printstats')
  3253. $title = get_string('graphic', 'iassign');
  3254. $num = array();
  3255. $sum_correct_iassign = array();
  3256. $sum_correct_student = array();
  3257. $sum_student = 0;
  3258. $i = 1;
  3259. foreach ($iassign_list as $iassign) {
  3260. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3261. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3262. $sum_iassign_correct[$i] = 0;
  3263. $num[$i] = new stdClass();
  3264. $num[$i]->name = $iassign->name;
  3265. $num[$i]->id = $i;
  3266. $num[$i]->iassignid = $iassign->id;
  3267. $i++;
  3268. } // if ($iassign->type_iassign == 3)
  3269. } // foreach ($iassign_list as $iassign)
  3270. $sum_iassign = $i - 1;
  3271. $context = context_course::instance($this->course->id);
  3272. if ($i > 1) {
  3273. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3274. $params_temp = array('shortname' => 'student');
  3275. $role = $DB->get_record_sql(
  3276. "SELECT s.id, s.shortname FROM {role} s " .
  3277. " WHERE s.shortname = :shortname", $params_temp);
  3278. // $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");
  3279. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3280. $students = $DB->get_records_sql(
  3281. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3282. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3283. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3284. $total = 0;
  3285. $sum_student = 0;
  3286. $j = 0;
  3287. $sum_correct_iassign = array();
  3288. $sum_correct_student = array();
  3289. $sum_experiment = array();
  3290. if ($students) {
  3291. foreach ($students as $users) {
  3292. $sum_student++;
  3293. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3294. // rows
  3295. $total_student = 0;
  3296. for ($j = 1; $j < $i; $j++) {
  3297. $total_experiment = 0;
  3298. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3299. if ($student_submissions) {
  3300. if ($student_submissions->status == 3) {
  3301. $sum_iassign_correct[$j]++;
  3302. $total_student++;
  3303. } // if ($student_submissions->status == 3)
  3304. $total_experiment += $student_submissions->experiment;
  3305. }
  3306. $sum_experiment[$j] = $total_experiment;
  3307. } // for ($j=1; $j<$i; $j++)
  3308. $total = $total + $total_student;
  3309. $sum_correct_student[$sum_student] = new stdClass();
  3310. $sum_correct_student[$sum_student]->name = $name;
  3311. $sum_correct_student[$sum_student]->sum = $total_student;
  3312. } // foreach ($students as $users)
  3313. }
  3314. for ($i = 1; $i < $j; $i++) {
  3315. if (is_null($sum_iassign_correct[$i]))
  3316. $sum_iassign_correct[$i] = 0;
  3317. $sum_correct_iassign[$i] = new stdClass();
  3318. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3319. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3320. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3321. } // for ($i = 1; $i < $j; $i++)
  3322. } // if ($i > 1)
  3323. print $OUTPUT->header();
  3324. $this->print_main_menu();
  3325. if ($this->action != 'printstats') {
  3326. $title = get_string('graphic', 'iassign');
  3327. $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>";
  3328. $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>";
  3329. print '<table width=100%><tr>';
  3330. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3331. print '<td width=15% align="right">' . $link_report . '</td>';
  3332. print '</td></tr></table>' . "\n";
  3333. print "<br><br>";
  3334. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3335. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3336. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3337. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3338. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3339. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3340. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3341. print '</tr>' . "\n";
  3342. $sum_correct = 0;
  3343. if ($sum_correct_iassign) {
  3344. foreach ($sum_correct_iassign as $iassign) {
  3345. if (is_null($iassign->experiment))
  3346. $iassign->experiment = 0;
  3347. $bar = "";
  3348. $sum = $iassign->sum;
  3349. $percent = ($sum / $sum_student) * 100;
  3350. $text = number_format($percent, 1) . '%';
  3351. $sum_correct += $sum;
  3352. if ($sum > 0) {
  3353. for ($i = 1; $i < $percent * 2; $i++)
  3354. $bar .= iassign_icons::insert('hbar_blue');
  3355. $bar .= iassign_icons::insert('hbar_blue_r');
  3356. } // if ($sum > 0)
  3357. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3358. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3359. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3360. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3361. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3362. print '</tr>' . "\n";
  3363. } // foreach ($sum_correct_iassign as $iassign)
  3364. }
  3365. print "</table>";
  3366. print "<br><br>";
  3367. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3368. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3369. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3370. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3371. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3372. print '</tr>' . "\n";
  3373. $sum_correct = 0;
  3374. foreach ($sum_correct_student as $student) {
  3375. $bar = "";
  3376. $sum = $student->sum;
  3377. $percent = ($sum / $sum_iassign) * 100;
  3378. $text = number_format($percent, 1) . '%';
  3379. $sum_correct += $sum;
  3380. if ($sum > 0) {
  3381. for ($i = 1; $i < $percent * 2; $i++)
  3382. $bar .= iassign_icons::insert('hbar_blue');
  3383. $bar .= iassign_icons::insert('hbar_blue_r');
  3384. } // if ($sum > 0)
  3385. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3386. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3387. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3388. print '</tr>' . "\n";
  3389. } // foreach ($sum_correct_student as $student)
  3390. print "</table>\n";
  3391. print "<br><br>\n";
  3392. $var = 0;
  3393. $cv = 0;
  3394. $dv = 0;
  3395. $avg = 0;
  3396. if ($sum_correct_student) {
  3397. $avg = $sum_correct / $sum_student;
  3398. if ($avg > 0) {
  3399. foreach ($sum_correct_student as $student)
  3400. $var += pow($student->sum - $avg, 2);
  3401. $var = $var / $sum_student;
  3402. $dv = sqrt($var);
  3403. $cv = ($dv / $avg) * 100;
  3404. }
  3405. }
  3406. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3407. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3408. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3409. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3410. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3411. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3412. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3413. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3414. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3415. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3416. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3417. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3418. print "</table>\n";
  3419. print $OUTPUT->footer();
  3420. } else {
  3421. print "<STYLE TYPE='text/css'>
  3422. <!--
  3423. .boldtable {
  3424. font-family:sans-serif;
  3425. font-size:10pt;
  3426. }
  3427. -->
  3428. </STYLE>\n";
  3429. print '<table border=1 width=100%>' . "\n";
  3430. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3431. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3432. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3433. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3434. print '</tr>' . "\n";
  3435. $sum_correct = 0;
  3436. foreach ($sum_correct_iassign as $iassign) {
  3437. $bar = "";
  3438. $sum = $iassign->sum;
  3439. $percent = ($sum / $sum_student) * 100;
  3440. $text = number_format($percent, 1) . '%';
  3441. $sum_correct += $sum;
  3442. if ($sum > 0) {
  3443. for ($i = 1; $i < $percent * 2; $i++)
  3444. $bar .= iassign_icons::insert('hbar_blue');
  3445. $bar .= iassign_icons::insert('hbar_blue_r');
  3446. } // if ($sum > 0)
  3447. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3448. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3449. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3450. print '</tr>' . "\n";
  3451. } // foreach ($sum_correct_iassign as $iassign)
  3452. print "</table>";
  3453. print "<br><br>";
  3454. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3455. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3456. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3457. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3458. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3459. print '</tr>' . "\n";
  3460. $sum_correct = 0;
  3461. foreach ($sum_correct_student as $student) {
  3462. $bar = "";
  3463. $sum = $student->sum;
  3464. $percent = ($sum / $sum_iassign) * 100;
  3465. $text = number_format($percent, 1) . '%';
  3466. $sum_correct += $sum;
  3467. if ($sum > 0) {
  3468. for ($i = 1; $i < $percent * 2; $i++)
  3469. $bar .= iassign_icons::insert('hbar_blue');
  3470. $bar .= iassign_icons::insert('hbar_blue_r');
  3471. } // if ($sum > 0)
  3472. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3473. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3474. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3475. print '</tr>' . "\n";
  3476. } // foreach ($sum_correct_student as $student)
  3477. print "</table>\n";
  3478. print "<br/><br/>\n";
  3479. $var = 0;
  3480. $cv = 0;
  3481. $dv = 0;
  3482. $avg = 0;
  3483. if ($sum_correct_student) {
  3484. $avg = $sum_correct / $sum_student;
  3485. if ($avg > 0) {
  3486. foreach ($sum_correct_student as $student)
  3487. $var += pow($student->sum - $avg, 2);
  3488. $var = $var / $sum_student;
  3489. $dv = sqrt($var);
  3490. $cv = ($dv / $avg) * 100;
  3491. }
  3492. }
  3493. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3494. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3495. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3496. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3497. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3498. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3499. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3500. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3501. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3502. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3503. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3504. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3505. print "</table>\n";
  3506. } // if ($this->action != 'printstats')
  3507. die();
  3508. }
  3509. /// Display graphics of performance for students
  3510. function stats_students () {
  3511. global $USER, $CFG, $DB, $OUTPUT;
  3512. $id = $this->cm->id;
  3513. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3514. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3515. $title = get_string('results', 'iassign');
  3516. $sum_correct = 0;
  3517. $sum_incorrect = 0;
  3518. $sum_post = 0;
  3519. $sum_nopost = 0;
  3520. $sum_iassign = count($iassign_statement_list);
  3521. $bar_nopost = "";
  3522. $bar_correct = "";
  3523. $bar_incorrect = "";
  3524. $bar_post = "";
  3525. $text_nopost = "";
  3526. $text_correct = "";
  3527. $text_incorrect = "";
  3528. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3529. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3530. if ($iassign_submission) {
  3531. if ($iassign_submission->status == 3)
  3532. $sum_correct++;
  3533. elseif ($iassign_submission->status == 2)
  3534. $sum_incorrect++;
  3535. elseif ($iassign_submission->status == 1)
  3536. $sum_post++;
  3537. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3538. $sum_nopost++;
  3539. } // if ($iassign_submission)
  3540. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3541. if ($sum_iassign > 0) {
  3542. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3543. $text_correct = number_format($percent_correct, 1) . '%';
  3544. }
  3545. if ($sum_correct > 0) {
  3546. for ($i = 1; $i < $percent_correct * 2; $i++)
  3547. $bar_correct .= iassign_icons::insert('hbar_green');
  3548. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3549. } // if ($sum_correct > 0)
  3550. if ($sum_iassign > 0) {
  3551. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3552. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3553. }
  3554. if ($sum_incorrect > 0) {
  3555. for ($i = 1; $i < $percent_incorrect * 2; $i++)
  3556. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3557. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3558. } // if ($sum_incorrect > 0)
  3559. if ($sum_iassign > 0) {
  3560. $percent_post = ($sum_post / $sum_iassign) * 100;
  3561. $text_post = number_format($percent_post, 1) . '%';
  3562. }
  3563. if ($sum_post > 0) {
  3564. for ($i = 1; $i < $percent_post * 2; $i++)
  3565. $bar_post .= iassign_icons::insert('hbar_blue');
  3566. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3567. } // if ($sum_post > 0)
  3568. if ($sum_iassign > 0) {
  3569. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3570. $text_nopost = number_format($percent_nopost, 1) . '%';
  3571. }
  3572. if ($sum_nopost > 0) {
  3573. for ($i = 1; $i < $percent_nopost * 2; $i++)
  3574. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3575. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3576. } // if ($sum_nopost > 0)
  3577. print $OUTPUT->header();
  3578. $this->print_main_menu();
  3579. //2021/12 $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3580. //2021/12 print '<table width=100%><tr>';
  3581. //2021/12 print '<td align="right">' . $link_return . '</td>' . "\n";
  3582. //2021/12 print '</td></tr></table>' . "\n";
  3583. print "<br/><br/>\n";
  3584. print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
  3585. print '<tr><th colspan=3 class="header c1">' . "\n";
  3586. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3587. // $imagetext = '');
  3588. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3589. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3590. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3591. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3592. print '</tr>' . "\n";
  3593. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3594. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3595. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3596. print '</tr>' . "\n";
  3597. if ($sum_post) {
  3598. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3599. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3600. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3601. print '</tr>' . "\n";
  3602. } // if ($sum_post)
  3603. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3604. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3605. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3606. print '</tr>' . "\n";
  3607. print "</table>";
  3608. print "<br><br>";
  3609. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3610. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3611. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3612. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3613. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3614. $sum_grade = 0;
  3615. $sum_grade_student = 0;
  3616. $avg = 0;
  3617. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3618. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3619. if (!$iassign_submission) {
  3620. $iassign_submission = new stdClass();
  3621. $iassign_submission->grade = 0;
  3622. }
  3623. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3624. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3625. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3626. print '</tr>' . "\n";
  3627. $sum_grade += $iassign_statement_activity_item->grade;
  3628. $sum_grade_student += $iassign_submission->grade;
  3629. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3630. if ($sum_grade > 0)
  3631. $avg = $sum_grade_student / $sum_grade * 100;
  3632. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3633. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3634. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3635. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3636. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3637. print "</table>";
  3638. print $OUTPUT->footer();
  3639. die();
  3640. } // function stats_students()
  3641. function get_total_notifications () {
  3642. global $DB, $USER, $COURSE;
  3643. $total_messages = 0;
  3644. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3645. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3646. $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 "
  3647. . " 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);
  3648. }
  3649. else {
  3650. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3651. $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 "
  3652. . " 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);
  3653. }
  3654. return $total_messages->total;
  3655. }
  3656. function get_iassign_statement_messages () {
  3657. global $DB, $USER, $COURSE;
  3658. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3659. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3660. $totais = array();
  3661. $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 "
  3662. . " 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);
  3663. foreach($messages as $item) {
  3664. if (isset($totais[$item->subid])) {
  3665. $totais[$item->subid]->total++;
  3666. }
  3667. else {
  3668. $totais[$item->subid] = new stdclass();
  3669. $item->total = 1;
  3670. $totais[$item->subid] = $item;
  3671. }
  3672. }
  3673. return $totais;
  3674. }
  3675. else {
  3676. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3677. $totais = array();
  3678. $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 "
  3679. . " 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);
  3680. foreach($messages as $item) {
  3681. if (isset($totais[$item->subid])) {
  3682. $totais[$item->subid]->total++;
  3683. }
  3684. else {
  3685. $totais[$item->subid] = new stdclass();
  3686. $item->total = 1;
  3687. $totais[$item->subid] = $item;
  3688. }
  3689. }
  3690. return $totais;
  3691. }
  3692. }
  3693. function view_notifications_teachers () {
  3694. global $OUTPUT, $USER, $DB;
  3695. $messages = $this->get_iassign_statement_messages();
  3696. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3697. // 1º. listar as mensagens recebidas no bloco atual:
  3698. $actual_block = $this->iassign->id;
  3699. $id = $this->cm->id;
  3700. $total_include = 0;
  3701. $activities_actual_block = array();
  3702. if ($messages)
  3703. foreach ($messages as $item)
  3704. if ($item->iasid == $actual_block)
  3705. if (!in_array($item->stid, $activities_actual_block))
  3706. array_push($activities_actual_block, $item->stid);
  3707. if ($activities_actual_block)
  3708. foreach ($activities_actual_block as $activity_id) {
  3709. $printed = false;
  3710. foreach ($messages as $item) {
  3711. if ($item->stid == $activity_id) {
  3712. if (!$printed) {
  3713. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
  3714. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3715. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3716. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3717. $printed = true;
  3718. }
  3719. $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
  3720. $user = $DB->get_record('user', array('id' => $item->user));
  3721. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3722. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3723. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3724. '<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>'
  3725. .'</tr>';
  3726. $total_include++;
  3727. }
  3728. }
  3729. print '</td></tr></table>';
  3730. }
  3731. print '</table>';
  3732. if (count($activities_actual_block) == 0) {
  3733. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3734. print '<hr class="my-4">';
  3735. }
  3736. if ($messages && $total_include == count($messages)) {
  3737. print $OUTPUT->footer();
  3738. return;
  3739. }
  3740. 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>';
  3741. $iassign_ids = array();
  3742. if ($messages)
  3743. foreach ($messages as $item)
  3744. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3745. array_push($iassign_ids, $item->iasid);
  3746. foreach ($iassign_ids as $id_iassign) {
  3747. $printed = false;
  3748. $activities_in_block = array();
  3749. foreach ($messages as $subitem)
  3750. if ($subitem->iasid == $id_iassign)
  3751. if (!in_array($item->stid, $activities_in_block))
  3752. array_push($activities_in_block, $item->stid);
  3753. foreach ($messages as $item) {
  3754. if ($item->iasid == $id_iassign) {
  3755. if (!$printed) {
  3756. $printed = true;
  3757. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3758. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3759. }
  3760. foreach ($activities_in_block as $id_activity) {
  3761. $print = false;
  3762. foreach ($messages as $subitem) {
  3763. if ($subitem->stid == $id_activity) {
  3764. if (!$print) {
  3765. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
  3766. $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
  3767. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3768. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3769. $print = true;
  3770. }
  3771. foreach ($messages as $comment_student) {
  3772. if ($comment_student->stid == $id_activity) {
  3773. $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
  3774. $user = $DB->get_record('user', array('id' => $comment_student->user));
  3775. $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3776. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3777. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3778. '<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>'
  3779. .'</tr>';
  3780. }
  3781. }
  3782. break;
  3783. }
  3784. }
  3785. }
  3786. print '</table></td></tr></table>';
  3787. break;
  3788. }
  3789. }
  3790. }
  3791. print $OUTPUT->footer();
  3792. }
  3793. function view_notifications () {
  3794. global $OUTPUT, $USER;
  3795. print $OUTPUT->header();
  3796. $this->print_main_menu();
  3797. print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
  3798. if ($this->get_total_notifications() == 0) {
  3799. print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
  3800. print '<hr class="my-4">';
  3801. print $OUTPUT->footer();
  3802. return;
  3803. }
  3804. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3805. $this->view_notifications_teachers();
  3806. return;
  3807. }
  3808. $messages = $this->get_iassign_statement_messages();
  3809. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3810. // 1º. listar as mensagens recebidas no bloco atual:
  3811. $actual_block = $this->iassign->id;
  3812. $id = $this->cm->id;
  3813. $total_include = 0;
  3814. if ($messages)
  3815. foreach ($messages as $item) {
  3816. if ($item->iasid == $actual_block) {
  3817. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3818. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3819. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3820. 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>';
  3821. $total_include++;
  3822. }
  3823. }
  3824. print '</table>';
  3825. if ($total_include == 0) {
  3826. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3827. print '<hr class="my-4">';
  3828. }
  3829. if ($messages && $total_include == count($messages)) {
  3830. print $OUTPUT->footer();
  3831. return;
  3832. }
  3833. 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>';
  3834. // 2º. listar as mensagens recebidas nos demais blocos do curso:
  3835. $iassign_ids = array();
  3836. if ($messages)
  3837. foreach ($messages as $item)
  3838. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3839. array_push($iassign_ids, $item->iasid);
  3840. foreach ($iassign_ids as $id_iassign) {
  3841. $printed = false;
  3842. foreach ($messages as $item) {
  3843. if ($item->iasid == $id_iassign) {
  3844. if (!$printed) {
  3845. $printed = true;
  3846. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3847. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3848. }
  3849. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3850. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3851. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3852. 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>';
  3853. }
  3854. }
  3855. print '</table>';
  3856. }
  3857. print $OUTPUT->footer();
  3858. }
  3859. function print_main_menu () {
  3860. global $USER;
  3861. $id = $this->cm->id;
  3862. $actual_action = optional_param('action', '', PARAM_TEXT);
  3863. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3864. $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
  3865. $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
  3866. $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
  3867. $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
  3868. $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
  3869. $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
  3870. $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
  3871. $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
  3872. $url_import_activity = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'import_activity', 'iassignid' => $this->iassign->id));
  3873. print '<div class="btn-group" role="group" aria-label="">';
  3874. print '<a href="' . $url_home . '" class="btn btn-outline-primary ' . ($actual_action == '' ? 'active' : '') . '">' . "\n";
  3875. print ' <i class="fa fa-home" aria-hidden="true"></i> ' . get_string('activities_page', 'iassign') . "</a>\n";
  3876. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3877. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3878. // Has capability to see "report": teacher or up
  3879. 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>';
  3880. print '<div class="btn-group"><div class="btn-group">
  3881. <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">
  3882. <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
  3883. <div class="dropdown-menu">
  3884. <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>
  3885. <div class="dropdown-divider"></div>
  3886. <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>
  3887. <div class="dropdown-divider"></div>
  3888. <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>
  3889. </div>
  3890. </div>
  3891. '; // "
  3892. 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>';
  3893. 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>';
  3894. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3895. $notifications = $this->get_total_notifications();
  3896. print '<a href="' . $url_notifications . '" class="btn btn-outline-primary ' . ($actual_action == 'notifications' ? 'active' : '') . '">' . "\n"; // '
  3897. print ' <i class="fa fa-bell" aria-hidden="true"></i> ' . get_string('notifications', 'iassign');
  3898. if ($notifications > 0)
  3899. print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
  3900. print '</a></div><div class="btn-group">';
  3901. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3902. 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";
  3903. print '
  3904. <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  3905. </button>
  3906. <div class="dropdown-menu">
  3907. <a class="dropdown-item" href="' . $url_import_activity . '">' . get_string('import_activity', 'iassign') . '</a>
  3908. </div>'; // "
  3909. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3910. print '</div></div>' . "\n";
  3911. }
  3912. /// Display page of iAssign's block of activities
  3913. function view_iassigns () {
  3914. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3915. $id = $this->cm->id;
  3916. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3917. $notice = optional_param('notice', '', PARAM_TEXT);
  3918. if (strpos($notice, 'error'))
  3919. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3920. else if ($notice != '')
  3921. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3922. $this->print_main_menu(); // teachers' menu: Page of activities; About iLM; Report; Results; Reevaluation; Notifications
  3923. print $OUTPUT->box_start();
  3924. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3925. print '<div class="border float-right">' . "\n";
  3926. if ($iassign_list) {
  3927. // $USER->iassignEdit == 0 view 'Turn editing off'
  3928. // $USER->iassignEdit == 1 view 'Turn editing on'
  3929. if (!isset($USER->iassignEdit))
  3930. $USER->iassignEdit = 0;
  3931. if ($USER->iassignEdit == 0) {
  3932. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3933. $botton = 1;
  3934. }
  3935. elseif ($USER->iassignEdit == 1) {
  3936. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3937. $botton = 0;
  3938. }
  3939. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3940. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3941. print " <input class='btn btn-primary' type=submit value='" . $bottonEdit_message . "'/>\n";
  3942. print "</form>\n";
  3943. } // if ($iassign_list)
  3944. print "</div>\n";
  3945. }
  3946. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3947. // $this->view_legend_icons();
  3948. print $OUTPUT->box_end();
  3949. $iassign_array_exercise = array();
  3950. $i_exercise = 0; // count total number of activities of type 'exercise' inside the block
  3951. $iassign_array_test = array();
  3952. $i_test = 0; // count total number of activities of type 'test' inside the block
  3953. $iassign_array_example = array();
  3954. $i_example = 0; // count total number of activities of type 'example' inside the block
  3955. $iassign_array_general = array();
  3956. $i_general = 0;
  3957. if ($iassign_list) {
  3958. if ($this->iassign->activity_group == 0) {
  3959. foreach ($iassign_list as $iassign) {
  3960. $iassign_array_general[$i_general] = $iassign;
  3961. $i_general++;
  3962. }
  3963. } // if ($this->iassign->activity_group == 0)
  3964. else {
  3965. foreach ($iassign_list as $iassign) {
  3966. if ($iassign->type_iassign == 3) {
  3967. $iassign_array_exercise[$i_exercise] = $iassign;
  3968. $i_exercise++;
  3969. } // if ($iassign->type_iassign == 3)
  3970. if ($iassign->type_iassign == 2) {
  3971. $iassign_array_test[$i_test] = $iassign;
  3972. $i_test++;
  3973. } // if ($iassign->type_iassign == 2)
  3974. if ($iassign->type_iassign == 1) {
  3975. $iassign_array_example[$i_example] = $iassign;
  3976. $i_example++;
  3977. } // if ($iassign->type_iassign == 1)
  3978. }
  3979. }
  3980. if ($iassign_array_exercise) {
  3981. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3982. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3983. }
  3984. if ($iassign_array_test) {
  3985. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3986. $this->show_iassign($title, $iassign_array_test, $i_test);
  3987. }
  3988. if ($iassign_array_example) {
  3989. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3990. $this->show_iassign($title, $iassign_array_example, $i_example);
  3991. }
  3992. if ($iassign_array_general) {
  3993. $title = "";
  3994. $this->show_iassign($title, $iassign_array_general, $i_general);
  3995. }
  3996. } else { // if ($iassign_list)
  3997. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3998. }
  3999. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  4000. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4001. print $OUTPUT->box_start();
  4002. print '<table width=100% border=0><tr>' . "\n";
  4003. print '<td width=10% align="left">' . "\n";
  4004. print $link_report;
  4005. print '</td>' . "\n";
  4006. print '</tr></table>' . "\n";
  4007. print $OUTPUT->box_end();
  4008. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4009. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  4010. print $OUTPUT->box_start();
  4011. print '<table width=100% border=0><tr>' . "\n";
  4012. print '<td align="left">' . "\n";
  4013. print $link_add;
  4014. print '</td>' . "\n";
  4015. print '</tr></table>' . "\n";
  4016. print $OUTPUT->box_end();
  4017. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4018. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  4019. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4020. // $this->view_legend_icons();
  4021. } // function view_iassigns()
  4022. /// Display all iAssigns: the list of activities inside the iAssign block
  4023. // HTTP: ./mod/iassign/view.php?id= <$id>
  4024. function show_iassign ($title, $iassign_array, $total_of_activities) {
  4025. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  4026. $id = $this->cm->id; // ID of iAssign block (accessed throgh table "couse_module")
  4027. print $OUTPUT->box_start();
  4028. print " <script type='text/javascript'>
  4029. //<![CDATA[
  4030. function validate_move () {
  4031. var radios = document.getElementsByName('iassign_destiny');
  4032. var formValid = false;
  4033. //alert('aqui validate_move()');
  4034. var i = 0;
  4035. while (!formValid && i < radios.length) {
  4036. if (radios[i].checked) formValid = true;
  4037. i++;
  4038. }
  4039. if (!formValid) {
  4040. document.getElementById('move_dest').classList.add('alert-danger');
  4041. }
  4042. return formValid;
  4043. }
  4044. var modal;
  4045. function load_move(id_ias) {
  4046. document.form_move_activity.iassign_current.value = id_ias;
  4047. modal.style.display = 'block';
  4048. var radios = document.getElementsByName('iassign_destiny');
  4049. var i = 0;
  4050. while (i < radios.length) {
  4051. radios[i].checked = false;
  4052. i++;
  4053. }
  4054. document.getElementById('move_dest').classList.remove('alert-danger');
  4055. }
  4056. function closeModal () {
  4057. modal.style.display = 'none';
  4058. }
  4059. function load_modal_elements () {
  4060. modal = document.getElementById('myModal');
  4061. var span = document.getElementById('close_modal');
  4062. span.onclick = function() {
  4063. modal.style.display = 'none';
  4064. }
  4065. window.onclick = function(event) {
  4066. if (event.target == modal) {
  4067. modal.style.display = 'none';
  4068. }
  4069. }
  4070. }
  4071. window.onload = load_modal_elements;
  4072. //]]>
  4073. </script>\n";
  4074. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  4075. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  4076. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  4077. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  4078. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  4079. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  4080. <input type='hidden' name='iassign_current' value='' />";
  4081. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  4082. $section = $course_sections[0];
  4083. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  4084. for ($k = 0; $k < count($ids_sections); $k++) {
  4085. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  4086. for ($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  4087. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  4088. if ($c_cm) {
  4089. if ($ccm->instance == $c_cm->instance) {
  4090. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4091. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4092. }
  4093. else {
  4094. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4095. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4096. }
  4097. }
  4098. }
  4099. $radio_buttons .= "</ul>";
  4100. }
  4101. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  4102. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
  4103. </form>
  4104. </div></div> </div></div>\n";
  4105. print " <style>.modal {
  4106. display: none;
  4107. position: fixed;
  4108. z-index: 1;
  4109. left: 0;
  4110. top: 0;
  4111. width: 100%;
  4112. height: 100%;
  4113. overflow: scroll;
  4114. background-color: rgb(0,0,0);
  4115. background-color: rgba(0,0,0,0.4);
  4116. }
  4117. .modal-content {
  4118. background-color: #fefefe;
  4119. margin: 15% auto;
  4120. padding: 10px 10px;
  4121. border: 1px solid #888;
  4122. width: 50%;
  4123. }
  4124. #close_modal {
  4125. color: #aaa;
  4126. float: right;
  4127. font-size: 28px;
  4128. font-weight: bold;
  4129. margin-top: -15px;
  4130. margin-right: -3px;
  4131. }
  4132. #close_modal:hover,
  4133. #close_modal:focus {
  4134. color: black;
  4135. text-decoration: none;
  4136. cursor: pointer;
  4137. }
  4138. #modal_title {
  4139. min-height: 3rem;
  4140. color: initial;
  4141. background: initial;
  4142. font-size: 1.5rem;
  4143. line-height: 1.5;
  4144. padding: 15px;
  4145. border-bottom: 1px solid #e5e5e5;
  4146. }
  4147. .input_move {
  4148. width: 90%;
  4149. padding: 2px;
  4150. }
  4151. .input_move:hover {
  4152. background: #eff0ef;
  4153. }
  4154. </style>";
  4155. $action_links = "";
  4156. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4157. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4158. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4159. for ($j=0; $j<$total_of_activities; $j++) {
  4160. $iassign_current = $iassign_array[$j]->id;
  4161. // receiver=1 - message to teacher
  4162. // receiver=2 - message to student
  4163. $sum_comment = 0;
  4164. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  4165. foreach ($iassign_submissions as $iassign_submission) {
  4166. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  4167. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4168. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4169. if ($verify_message)
  4170. foreach ($verify_message as $tmp)
  4171. $sum_comment += $tmp;
  4172. } // foreach ($iassign_submissions as $iassign_submission)
  4173. if ($sum_comment == 0)
  4174. $comment_unread = "";
  4175. else {
  4176. $comment_unread_message = get_string('comment_unread', 'iassign');
  4177. if ($sum_comment == 1)
  4178. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4179. $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '">' .
  4180. ' <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 .
  4181. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . '</span> </span></a>' . "\n";
  4182. }
  4183. if ($j == $total_of_activities - 1)
  4184. $iassign_down = $iassign_array[$j]->id;
  4185. else
  4186. $iassign_down = $iassign_array[$j + 1]->id;
  4187. if ($j > 0)
  4188. $iassign_up = $iassign_array[$j - 1]->id;
  4189. else
  4190. $iassign_up = $iassign_array[$j]->id;
  4191. if ($iassign_array[$j]->visible == 0)
  4192. $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";
  4193. else
  4194. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4195. $links .= $comment_unread;
  4196. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  4197. $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>\n";
  4198. $str_aux = "&id=" . $id . "&iassign_current=" . $iassign_current . "&iassign_up=" . $iassign_up . "&iassign_down=" . $iassign_down;
  4199. $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";
  4200. if ($j==0) // first activity
  4201. $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";
  4202. else
  4203. $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";
  4204. $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";
  4205. $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";
  4206. $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";
  4207. $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";
  4208. $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";
  4209. $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";
  4210. if (count($iassign_array) > 1) {
  4211. if ($j == 0)
  4212. $action_links .= $link_down;
  4213. elseif ($j == $total_of_activities - 1)
  4214. $action_links .= $link_up;
  4215. else
  4216. $action_links .= $link_up . $link_down;
  4217. } // if (count($iassign_array) > 1)
  4218. $action_links .= $link_edit . $link_delete;
  4219. if ($iassign_array[$j]->visible == 0)
  4220. $action_links .= $link_visible_show;
  4221. else
  4222. $action_links .= $link_visible_hide;
  4223. $action_links .= $link_duplicate_activity . $link_move_activity;
  4224. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4225. $action_links .= "</ul></nav>\n";
  4226. 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";
  4227. } // for ($j=0; $j<$total_of_activities; $j++)
  4228. //D echo "locallib.php: show_iassign():<br/>";
  4229. //EXTRA: This for is to correct error in ordem inside the block, to detect (and fix it) 'iassign_statement.position' errors
  4230. $vector_final_order = array(); // get the final order to be used to correct existent one
  4231. for ($j=0; $j<$total_of_activities; $j++) { // List all iAssign activity inside this block
  4232. //D echo $j . ": id=" . $iassign_array[$j]->id . ", position=" . $iassign_array[$j]->position . "<br/>";
  4233. if ($iassign_array[$j]->position!=($j+1)) {
  4234. activity::move_change_activity_position($DB, $iassign_array[$j]->id, $iassign_array[$j]->id, $j+1, $j+1);
  4235. }
  4236. }
  4237. print "</tbody></table>\n";
  4238. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4239. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  4240. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4241. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4242. for ($j=0; $j<$total_of_activities; $j++) {
  4243. $icon_status = "";
  4244. $icon_comment = "";
  4245. if ($iassign_array[$j]->visible == 1) {
  4246. $iassign_current = $iassign_array[$j]->id;
  4247. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  4248. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4249. $icon_status = "";
  4250. $icon_comment = "";
  4251. if ($iassign_submission) {
  4252. // receiver=1 - message to teacher
  4253. // receiver=2 - message to student
  4254. // $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");
  4255. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  4256. $verify_message = $DB->get_record_sql(
  4257. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4258. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4259. if ($verify_message)
  4260. foreach ($verify_message as $tmp)
  4261. $sum_comment = $tmp;
  4262. if ($sum_comment > 0) {
  4263. $comment_unread_message = get_string('comment_unread', 'iassign');
  4264. if ($sum_comment == 1)
  4265. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4266. $icon_comment = "<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "#comments'>\n" .
  4267. ' <span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . "\n" .
  4268. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . "</span> </span></a>\n";
  4269. }
  4270. // $icon_comment = iassign_icons::insert('comment_unread');
  4271. if ($iassign_array[$j]->type_iassign == 3) {
  4272. if ($iassign_array[$j]->show_answer == 1) {
  4273. if ($iassign_submission->status == 3)
  4274. $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('correct', 'iassign') . '"></i>' . "\n";
  4275. elseif ($iassign_submission->status == 2)
  4276. $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('incorrect', 'iassign') . '"></i>' . "\n";
  4277. elseif ($iassign_submission->status == 1)
  4278. $icon_status = '<i class="fa fa-question" style="color: #77229; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4279. //2021/12 $icon_status = iassign_icons::insert('post');
  4280. elseif ($iassign_submission->status == 0)
  4281. $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";
  4282. } // if ($iassign_array[$j]->show_answer==1)
  4283. else {
  4284. if ($iassign_submission->status == 0) {
  4285. //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";
  4286. $icon_status = iassign_icons::insert('not_post');
  4287. }
  4288. else {
  4289. //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";
  4290. $icon_status = iassign_icons::insert('post');
  4291. }
  4292. }
  4293. } // if ($iassign_array[$j]->type_iassign == 3)
  4294. } // if ($iassign_submission)
  4295. elseif ($iassign_array[$j]->type_iassign == 3) {
  4296. $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";
  4297. //2021/12 $icon_status = iassign_icons::insert('not_post');
  4298. } // if ($iassign_array[$j]->type_iassign == 3)
  4299. 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;">'
  4300. . $links . '</td><td>' . $icon_comment . '</td></tr>' . "\n";
  4301. //print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  4302. } // if ($iassign_array[$j]->visible == 1)
  4303. } // for ($j=0; $j<$total_of_activities; $j++)
  4304. print "</table>\n";
  4305. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4306. else if (isguestuser()) {
  4307. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  4308. print '<table width=100% ><tr>' . "\n";
  4309. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  4310. print '</tr></table>' . "\n";
  4311. for ($j=0; $j<$total_of_activities; $j++) {
  4312. $icon_status = "";
  4313. $icon_comment = "";
  4314. if ($iassign_array[$j]->visible == 1) {
  4315. $iassign_current = $iassign_array[$j]->id;
  4316. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4317. print '<p>' . $links . '</p>' . "\n";
  4318. } // if ($iassign_array[$j]->visible == 1)
  4319. }
  4320. }
  4321. print $OUTPUT->box_end();
  4322. } // function show_iassign($title, $iassign_array, $total_of_activities)
  4323. /// Show message of return
  4324. function return_home_course ($message) {
  4325. //D global $DB, $OUTPUT;
  4326. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4327. //D echo $OUTPUT->box_start();
  4328. //D echo '<table width=100% border=0 valign="top">' . "\n";
  4329. //D echo '<tr><td align="left"><strong>' . "\n";
  4330. //D print_string($message, 'iassign');
  4331. //D echo '</strong></td>' . "\n";
  4332. //D echo '<td width=20% align="right">' . "\n";
  4333. //D echo $link_return;
  4334. //D echo '</td></tr></table>' . "\n";
  4335. //D echo $OUTPUT->box_end();
  4336. //D // echo $OUTPUT->footer();
  4337. redirect(new moodle_url($this->return . '&notice=' . $message));
  4338. exit;
  4339. }
  4340. /// Search comment of activity
  4341. function search_comment_submission ($iassign_submissionid) {
  4342. global $USER, $DB, $OUTPUT, $COURSE;
  4343. // $context = context_course::instance($COURSE->id);
  4344. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  4345. $colorEdit2 = "#d2e5fc";
  4346. $has_capability = 0;
  4347. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  4348. $text = "";
  4349. if ($comments) {
  4350. $even = 1;
  4351. foreach ($comments as $tmp) {
  4352. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  4353. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  4354. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  4355. // $text .= $tmp->comment . "</td></tr>";
  4356. //} else {
  4357. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  4358. $avatar = new user_picture($user_data);
  4359. $avatar->courseid = $COURSE->id;
  4360. $avatar->link = true;
  4361. $user_picture = $OUTPUT->render($avatar);
  4362. $user_picture = str_replace('"35"', '"45"', $user_picture);
  4363. if ($even) {
  4364. $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";
  4365. $even = 0;
  4366. } else {
  4367. $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";
  4368. $even = 1;
  4369. }
  4370. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  4371. } // foreach ($comments as $tmp)
  4372. }
  4373. return $text;
  4374. }
  4375. /// Update comment of activity
  4376. function update_comment ($iassign_submissionid) {
  4377. global $USER, $DB, $OUTPUT;
  4378. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  4379. $receiver = 1; // student message to teacher
  4380. else
  4381. $receiver = 2; // teacher message to student
  4382. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  4383. if ($verify_message) {
  4384. foreach ($verify_message as $message) {
  4385. if ($message->receiver == $receiver) {
  4386. $newentry = new stdClass();
  4387. $newentry->id = $message->id;
  4388. $newentry->return_status = 1;
  4389. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  4390. print_error('error_update', 'iassign');
  4391. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  4392. } // if ($message->receiver == $receiver)
  4393. // Trigger module viewed event.
  4394. $event = \mod_iassign\event\submission_comment_updated::create(array(
  4395. 'objectid' => $this->iassign->id,
  4396. 'context' => $this->context
  4397. ));
  4398. $event->add_record_snapshot('course', $this->course);
  4399. $event->trigger();
  4400. } // foreach ($verify_message as $message)
  4401. }
  4402. }
  4403. /// Record comment of activity
  4404. function write_comment_submission () {
  4405. global $USER, $CFG, $DB;
  4406. $id = $this->cm->id;
  4407. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  4408. $row = optional_param('row', 0, PARAM_INT);
  4409. $column = optional_param('column', 0, PARAM_INT);
  4410. $sum_comment = 0;
  4411. $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);
  4412. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  4413. $str1 = trim($submission_comment);
  4414. $str2 = trim(get_string('box_comment_message', 'iassign'));
  4415. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  4416. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  4417. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  4418. $receiver = 1; // student message to teacher
  4419. $this->action = 'view';
  4420. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  4421. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  4422. } else {
  4423. $receiver = 2; // teacher message to student
  4424. $this->action = 'viewsubmission';
  4425. //D $tousers = array(); //MOOC 2016
  4426. //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
  4427. }
  4428. //MOOC 2016: foi p/ 15 linhas acima:
  4429. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  4430. // verificar se existe uma submissão para o exercício e aluno informados
  4431. if (!$iassign_submission) {
  4432. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  4433. }
  4434. if (!$iassign_submission) {
  4435. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  4436. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  4437. $this->iassign_submission_current = $id_submission;
  4438. }
  4439. else {
  4440. $id_submission = $iassign_submission->id;
  4441. } // if (!$iassign_submission)
  4442. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4443. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4444. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4445. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4446. $comments = $DB->get_record_sql(
  4447. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4448. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4449. if ($comments)
  4450. foreach ($comments as $tmp)
  4451. $sum_comment = $tmp;
  4452. if ($sum_comment == 0) {
  4453. $newentry = new stdClass();
  4454. $newentry->iassign_submissionid = $id_submission;
  4455. $newentry->comment_authorid = $USER->id;
  4456. $newentry->timecreated = time();
  4457. $newentry->comment = $submission_comment;
  4458. $newentry->receiver = $receiver;
  4459. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4460. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  4461. // Trigger module viewed event
  4462. $event = \mod_iassign\event\submission_comment_created::create(array(
  4463. 'objectid' => $this->iassign->id,
  4464. 'context' => $this->context
  4465. ));
  4466. $event->add_record_snapshot('course', $this->course);
  4467. $event->trigger();
  4468. }
  4469. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4470. // if ($this->action=='viewsubmission') {
  4471. // echo $OUTPUT->header();
  4472. // $this->return_last('confirm_add_comment', $link_return);
  4473. // die;
  4474. // }
  4475. return true;
  4476. } // function write_comment_submission()
  4477. /// Writes a new submission
  4478. // The first student answer is under 'function get_answer()'
  4479. function new_submission ($iassignid, $id_user, $receiver) {
  4480. global $USER, $DB, $OUTPUT;
  4481. $newentry = new stdClass();
  4482. $newentry->iassign_statementid = $iassignid;
  4483. $newentry->userid = $id_user;
  4484. $newentry->timecreated = time();
  4485. $newentry->timemodified = time();
  4486. $newentry->answer = 0; // student only submit message
  4487. if ($receiver == 2) // teacher message to student (write id teacher)
  4488. $newentry->teacher = $USER->id;
  4489. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4490. return_home_course('error_insert_submissions');
  4491. else {
  4492. // Trigger module view event
  4493. $event = \mod_iassign\event\submission_created::create(array(
  4494. 'objectid' => $this->iassign->id,
  4495. 'context' => $this->context
  4496. ));
  4497. $event->add_record_snapshot('course', $this->course);
  4498. $event->trigger();
  4499. }
  4500. return $newentry->id;
  4501. }
  4502. /// Return to a specific address of page
  4503. function return_last ($message, $link_return) {
  4504. global $DB, $OUTPUT;
  4505. print $OUTPUT->box_start();
  4506. print '<table width=100% border=0 valign="top">' . "\n";
  4507. print '<tr><td align="left"><strong>' . "\n";
  4508. print_string($message, 'iassign');
  4509. print '</strong></td>' . "\n";
  4510. print '<td width=20% align="right">' . "\n";
  4511. print $link_return;
  4512. print '</td></tr></table>' . "\n";
  4513. print $OUTPUT->box_end();
  4514. print $OUTPUT->footer();
  4515. die();
  4516. } // function return_last($message, $link_return)
  4517. } // class iassign
  4518. /// Class for manage activities
  4519. class activity {
  4520. var $activity;
  4521. /// Constructor of class.
  4522. // @param int $id Id of activity
  4523. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4524. //D public function activity($id) { self::__construct($id); }
  4525. function __construct ($id) {
  4526. global $DB;
  4527. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4528. if (empty($this->activity))
  4529. $this->activity = null;
  4530. }
  4531. /// Get an activity
  4532. // @return NULL
  4533. function get_activity () {
  4534. if ($this->activity != null)
  4535. return $this->activity;
  4536. else
  4537. return null;
  4538. }
  4539. /// Delete interactive activities
  4540. function delete ($return) {
  4541. global $USER, $CFG, $DB, $OUTPUT;
  4542. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4543. print $OUTPUT->header();
  4544. $output .= $OUTPUT->box_start();
  4545. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4546. if ($iassign_submission_currents) {
  4547. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4548. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4549. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4550. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4551. $output .= $OUTPUT->box_end();
  4552. $output .= $OUTPUT->footer();
  4553. print $output;
  4554. die();
  4555. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4556. } // if ($iassign_submission_currents)
  4557. else
  4558. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>\n";
  4559. $output .= '<table width=50% border=0>';
  4560. $output .= '<tr valign="top"><td>';
  4561. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>\n";
  4562. $output .= '</td><td>';
  4563. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4564. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4565. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>\n";
  4566. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4567. $output .= "</form>\n";
  4568. $output .= '</td><td>';
  4569. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4570. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4571. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4572. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4573. $output .= "</form>\n";
  4574. $output .= '</td></tr></table>' . "\n";
  4575. $output .= $OUTPUT->box_end();
  4576. $output .= $OUTPUT->footer();
  4577. print $output;
  4578. } // function delete($return)
  4579. /// Function for confirm the delete of activity
  4580. // @param String $return Url of return
  4581. // @param Object $iassign Object content an activity
  4582. function deleteyes ($return, $iassign) {
  4583. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4584. $msg = '';
  4585. if (!empty($this->activity->id)) {
  4586. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4587. if ($iassign_submission_currents) {
  4588. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4589. foreach ($iassign_submission_currents as $iassign_submission)
  4590. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4591. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4592. } // if ($iassign_submission_currents)
  4593. }
  4594. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4595. // Remove all files associated to this activity:
  4596. $fs = get_file_storage();
  4597. //TODO 2022: nao deveria ser "$this->activity->file" no lugar de "$this->activity->id"?
  4598. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4599. $this->delete_calendar($this->activity->id);
  4600. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4601. iassign::update_grade_iassign($this->activity->iassignid);
  4602. if ($delete_iassign_current) {
  4603. $iassign->return_home_course('confirm_delete_iassign');
  4604. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4605. }
  4606. else {
  4607. $iassign->return_home_course('error_confirm_delete_iassign');
  4608. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4609. }
  4610. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4611. }
  4612. } // function deleteyes($return, $iassign)
  4613. /// Change fields 'iassign_statement.position' between 2 activities
  4614. // @calledby : class this->move_iassign($move_action, $target, $return)
  4615. // @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})
  4616. static function move_change_activity_position ($DB, $idFrom, $idTo, $posFrom, $posTo) { //1
  4617. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4618. $newentry->id = $idFrom; // ID of the "source activity" //1 $this->activity->id -> $idFrom
  4619. $newentry->position = $posFrom; // final position to source //1 $final_position_source -> $posFrom
  4620. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4621. print_error('error_update_move_iassign', 'iassign');
  4622. }
  4623. // If $idFrom == $idTo then came here from 'this->show_iassign(.)' above, to correct order!
  4624. if ($idFrom != $idTo) { // if $idFrom != $idTo then must update also the targe position
  4625. $newentry->id = $idTo; //1 $iassign_target->id -> $idTo
  4626. $newentry->position = $posTo; //1 $final_position_target -> $posTo
  4627. if (!$DB->update_record('iassign_statement', $newentry))
  4628. print_error('error_update_move_iassign', 'iassign');
  4629. }
  4630. }
  4631. /// Changes position of activities (between those inside a group of interactive activities)
  4632. // @param $move_action = must be "up" or "down"
  4633. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4634. function move_iassign ($move_action, $target, $return) {
  4635. global $DB, $OUTPUT;
  4636. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4637. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4638. if ($move_action=="firstdown") {
  4639. $final_position_source = 2;
  4640. $final_position_target = 1;
  4641. }
  4642. else
  4643. if ($move_action=="down") {
  4644. $final_position_target = $this->activity->position;
  4645. $final_position_source = $final_position_target + 1;
  4646. }
  4647. else
  4648. if ($move_action=="up") {
  4649. $final_position_target = $this->activity->position;
  4650. $final_position_source = $final_position_target - 1;
  4651. }
  4652. else { // error:
  4653. print_error('error_update_move_iassign', 'iassign');
  4654. exit;
  4655. }
  4656. activity::move_change_activity_position($DB, $this->activity->id, $iassign_target->id, $final_position_source, $final_position_target); // efectively exchange 'position'
  4657. redirect($return);
  4658. } // function move_iassign($move_action, $target, $return)
  4659. /// Enable or disable the display of interactive activities
  4660. function visible_iassign ($return) {
  4661. global $DB;
  4662. $newentry = new stdClass();
  4663. $newentry->id = $this->activity->id;
  4664. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4665. if (!$DB->update_record('iassign_statement', $newentry))
  4666. print_error('error_update_visible_iassign', 'iassign');
  4667. redirect($return);
  4668. }
  4669. /// Add news interactive activities (register in table 'iassign_statement')
  4670. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4671. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4672. function new_iassign ($param) {
  4673. global $DB;
  4674. $newentry = new stdClass();
  4675. $newentry->iassignid = $param->iassignid;
  4676. $newentry->name = $param->name;
  4677. $newentry->type_iassign = $param->type_iassign;
  4678. $newentry->store_all_submissions = $param->store_all_submissions;
  4679. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4680. $proposition = $param->proposition;
  4681. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4682. else $proposition_text = $proposition;
  4683. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4684. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4685. //TODO Then get it directly from the form data $_POST!
  4686. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4687. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4688. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4689. $newentry->author_name = $param->author_name;
  4690. $newentry->author_modified_name = $param->author_modified_name;
  4691. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4692. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4693. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4694. $newentry->grade = $param->grade;
  4695. $newentry->timemodified = time();
  4696. $newentry->timecreated = time();
  4697. if ($param->type_iassign == 1) {
  4698. $newentry->timedue = 0;
  4699. $newentry->timeavailable = 0;
  4700. } // if ($param->type_iassign == 1)
  4701. else {
  4702. $newentry->timedue = $param->timedue;
  4703. $newentry->timeavailable = $param->timeavailable;
  4704. }
  4705. $newentry->preventlate = $param->preventlate;
  4706. $newentry->test = $param->test;
  4707. $newentry->special_param1 = $param->special_param1;
  4708. $newentry->visible = $param->visible;
  4709. $newentry->position = $param->position;
  4710. $newentry->max_experiment = $param->max_experiment;
  4711. $newentry->dependency = $param->dependency;
  4712. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4713. $newentry->show_answer = $param->show_answer;
  4714. $id = $DB->insert_record("iassign_statement", $newentry);
  4715. if ($id) {
  4716. $component = 'mod_iassign';
  4717. $filearea = 'exercise';
  4718. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4719. $file = $fs->get_file_by_id($param->file);
  4720. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4721. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4722. //$itemid = $id;
  4723. // File already inserted in other context!
  4724. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4725. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4726. $updateentry = new stdClass();
  4727. $updateentry->id = $id;
  4728. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4729. $updateentry->filesid = $newfile->get_itemid();
  4730. if (!$DB->update_record("iassign_statement", $updateentry))
  4731. print_error('error_add', 'iassign');
  4732. if ($param->type_iassign == 3)
  4733. iassign::update_grade_iassign($param->iassignid);
  4734. //TODO iLM_HTML5 :: //MOOC2014
  4735. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4736. //D if ($iassign_ilm_configs) {
  4737. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4738. //D if ($iassign_ilm_config->param_type != 'static') {
  4739. //D $newentry = new stdClass();
  4740. //D $newentry->iassign_statementid = $id;
  4741. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4742. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4743. //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});
  4744. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4745. //D print_error('error_add_param', 'iassign');
  4746. //D }
  4747. //D }
  4748. //D }
  4749. // log event --------------------------------------------------------------------------------------
  4750. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4751. // log event --------------------------------------------------------------------------------------
  4752. return $id;
  4753. }
  4754. else
  4755. print_error('error_add', 'iassign');
  4756. } // function new_iassign($param)
  4757. /// Add the calendar entries for this iassign
  4758. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4759. // @return bool
  4760. static function add_calendar ($iassignid) {
  4761. global $DB, $CFG;
  4762. require_once($CFG->dirroot . '/calendar/lib.php');
  4763. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4764. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4765. $event = new stdClass();
  4766. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4767. $event->description = $iassign_statement_activity_item->name;
  4768. $event->courseid = $iassign->course;
  4769. $event->groupid = 0;
  4770. $event->userid = 0;
  4771. $event->modulename = 'iassign';
  4772. $event->instance = $iassign->id;
  4773. $event->eventtype = 'due';
  4774. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4775. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4776. calendar_event::create($event);
  4777. }
  4778. /// Update the calendar entries for this iassign
  4779. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4780. // @return bool
  4781. function update_calendar ($iassignid, $olddescription) {
  4782. global $DB, $CFG;
  4783. require_once($CFG->dirroot . '/calendar/lib.php');
  4784. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4785. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4786. $event = new stdClass();
  4787. $event->id = 0;
  4788. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4789. if ($events) {
  4790. foreach ($events as $value) {
  4791. if ($value->description == $olddescription) {
  4792. $event->id = $value->id;
  4793. }
  4794. }
  4795. }
  4796. if ($event->id != 0) {
  4797. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4798. $event->description = $iassign_statement_activity_item->name;
  4799. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4800. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4801. $calendarevent = calendar_event::load($event->id);
  4802. $calendarevent->update($event);
  4803. } else
  4804. $this->add_calendar($iassignid);
  4805. }
  4806. /// Update the calendar entries for this iassign
  4807. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4808. // @return bool
  4809. function delete_calendar ($iassignid) {
  4810. global $DB, $CFG;
  4811. require_once($CFG->dirroot . '/calendar/lib.php');
  4812. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4813. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4814. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4815. if ($events) {
  4816. foreach ($events as $value) {
  4817. if ($value->description == $iassign_statement_activity_item->name) {
  4818. $DB->delete_records('event', array('id' => $value->id));
  4819. }
  4820. }
  4821. }
  4822. }
  4823. /// Update interactive activities
  4824. function update_iassign ($param) {
  4825. global $DB;
  4826. $component = 'mod_iassign';
  4827. $filearea = 'exercise';
  4828. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4829. $file = $fs->get_file_by_id($param->file);
  4830. $fileold = $fs->get_file_by_id($param->fileold);
  4831. if ($param->file != $param->fileold) {
  4832. if ($fileold) {
  4833. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4834. foreach ($fileoldarea as $value) {
  4835. $value->delete();
  4836. }
  4837. }
  4838. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4839. $itemid = $file->get_itemid() + $param->iassign_id;
  4840. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4841. $param->file = $newfile->get_itemid();
  4842. }
  4843. else
  4844. $param->file = $file->get_itemid();
  4845. }
  4846. else {
  4847. $param->file = $file->get_itemid();
  4848. }
  4849. $newentry = new stdClass();
  4850. $newentry->id = $param->iassign_id;
  4851. $newentry->name = $param->name;
  4852. $newentry->type_iassign = $param->type_iassign;
  4853. $newentry->store_all_submissions = $param->store_all_submissions;
  4854. //2019 $newentry->proposition = $param->proposition;
  4855. $proposition = $param->proposition;
  4856. if (is_array($proposition))
  4857. $proposition_text = $proposition['text'];
  4858. else
  4859. $proposition_text = $proposition;
  4860. $newentry->proposition = $proposition_text;
  4861. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4862. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4863. $newentry->grade = $param->grade;
  4864. $newentry->author_modified_name = $param->author_modified_name;
  4865. $newentry->timemodified = time();
  4866. if ($param->type_iassign == 1) {
  4867. $newentry->timedue = 0;
  4868. $newentry->timeavailable = 0;
  4869. } // if ($param->type_iassign == 1)
  4870. else {
  4871. $newentry->timedue = $param->timedue;
  4872. $newentry->timeavailable = $param->timeavailable;
  4873. }
  4874. $newentry->preventlate = $param->preventlate;
  4875. $newentry->test = $param->test;
  4876. if (isset($param->special_param1))
  4877. $newentry->special_param1 = $param->special_param1;
  4878. else
  4879. $newentry->special_param1 = NULL;
  4880. $newentry->visible = $param->visible;
  4881. $newentry->max_experiment = $param->max_experiment;
  4882. $newentry->dependency = $param->dependency;
  4883. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4884. $newentry->show_answer = $param->show_answer;
  4885. if (!$DB->update_record("iassign_statement", $newentry))
  4886. print_error('error_update', 'iassign');
  4887. if ($param->type_iassign == 3) {
  4888. iassign::update_grade_iassign($param->iassignid);
  4889. }
  4890. //$id = $newentry->id; // MOOC 2016 --- inicio
  4891. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4892. //if ($iassign_activity_item_configs) {
  4893. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4894. // $newentry = new stdClass();
  4895. // $newentry->id = $iassign_activity_item_config->id;
  4896. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4897. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4898. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4899. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4900. // print_error('error_edit_param', 'iassign');
  4901. // }
  4902. // } // MOOC 2016 --- final
  4903. // log event --------------------------------------------------------------------------------------
  4904. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4905. // log event --------------------------------------------------------------------------------------
  4906. return $newentry->id;
  4907. // if ($param->type_iassign==3)
  4908. // $this->update_grade_iassign($param->iassignid);
  4909. } // function update_iassign($param)
  4910. /// Show information of activity
  4911. function show_info_iassign () {
  4912. global $DB, $OUTPUT;
  4913. $output = '';
  4914. if ($this->activity->type_iassign == 3) {
  4915. if ($this->activity->dependency == 0) {
  4916. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4917. } else {
  4918. $dependencys = explode(';', $this->activity->dependency);
  4919. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4920. foreach ($dependencys as $dependency) {
  4921. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4922. if ($dependencyiassign)
  4923. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4924. } // foreach ($dependencys as $dependency)
  4925. } // if ($iassign_statement_activity_item->dependency == 0)
  4926. if ($this->activity->max_experiment == 0)
  4927. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4928. else
  4929. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4930. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4931. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4932. $output .= $this->toggle_columns_script();
  4933. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4934. print $OUTPUT->box($output);
  4935. } // function show_info_iassign()
  4936. /// Provide script to toggle columns
  4937. static function toggle_columns_script () {
  4938. $output = "";
  4939. $output .= '<script>
  4940. function toLeft () {
  4941. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4942. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4943. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4944. document.getElementById("columnsbutton").style.color = "#1da075";
  4945. }
  4946. function toDefault () {
  4947. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4948. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4949. document.getElementById("fullscreen").style.marginTop = "0";
  4950. document.getElementById("columnsbutton").style.color = "#343a40";
  4951. }
  4952. var activate = false;
  4953. function toggleColumns () {
  4954. if (activate) {
  4955. activate = false;
  4956. toDefault();
  4957. } else {
  4958. activate = true;
  4959. toLeft();
  4960. }
  4961. }
  4962. </script>'; // '
  4963. $output .= '<span tabindex="0" data-toggle="tooltip" title="' . get_string('enable_disable_columns', 'iassign')
  4964. . '" 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";
  4965. return $output;
  4966. } // function write_comment_submission()
  4967. static function get_latest_array_item ($DB, $iassignid, $position) { //TODO: may be search for the greatest grade?
  4968. $iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'position' => $position));
  4969. $item = NULL;
  4970. foreach ($iassign_statement as $item) ; // get the last item!
  4971. if ($item) return $item; // return the last one
  4972. return NULL;
  4973. }
  4974. /// Shows date of opening and closing activities
  4975. function view_dates () {
  4976. global $USER, $CFG, $DB, $OUTPUT;
  4977. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4978. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4979. $status_iassign = "";
  4980. $status_iassign1 = "";
  4981. $status_iassign2 = "";
  4982. if ($this->activity->type_iassign == 1) // activity of type example
  4983. $type_iassign = get_string('example_iassign', 'iassign');
  4984. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4985. $type_iassign = get_string('test_iassign', 'iassign');
  4986. if ($this->activity->timeavailable > time()) {
  4987. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4988. } elseif ($this->activity->timedue < time()) {
  4989. $status_iassign = get_string('last_timedue', 'iassign');
  4990. }
  4991. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4992. $type_iassign = get_string('exercise_iassign', 'iassign');
  4993. if ($this->activity->timeavailable > time()) {
  4994. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4995. } elseif ($this->activity->timedue < time()) { // after delivery
  4996. $status_iassign = get_string('last_timedue', 'iassign');
  4997. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4998. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4999. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  5000. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  5001. if ($this->activity->test == 1) // allowed to test after of deadline
  5002. $status_iassign2 = get_string('test_preventlate', 'iassign');
  5003. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  5004. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  5005. } // elseif ($iassign_statement_activity_item->test == 0)
  5006. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  5007. } // elseif ($iassign_statement_activity_item->timedue < time())
  5008. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  5009. $output = '<table width=100% >' . "\n";
  5010. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  5011. $output .= '<tr>' . "\n";
  5012. //leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  5013. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  5014. //leo $output .= '<td width=80%>' . $type_iassign;
  5015. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  5016. // $output .= '</td>' . "\n";
  5017. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  5018. // Link (with icon) to report survey (to present all interactivy exercises inside this block)
  5019. $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>";
  5020. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  5021. }
  5022. else {
  5023. // Get all previous/next solution sent by this student (present link to his last answer)
  5024. // $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  5025. $iassign_previous = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position-1); // previous activity of this student inside this block
  5026. // $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  5027. $iassign_next = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position+1); // next activity of this student inside this block
  5028. $link_next = "";
  5029. $link_previous = "";
  5030. if ($iassign_previous) { // previous_activity
  5031. $url_previous = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_previous->id;
  5032. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>\n";
  5033. }
  5034. if ($iassign_next) { // next_activity
  5035. $url_next = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_next->id;
  5036. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>\n";
  5037. }
  5038. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  5039. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  5040. $output .= '</tr></table>' . "\n";
  5041. $output .= '<table width=100% >' . "\n";
  5042. if ($this->activity->type_iassign > 1) {
  5043. if ($this->activity->timeavailable)
  5044. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  5045. if ($this->activity->timedue)
  5046. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  5047. } // if ($iassign_statement_activity_item->type_iassign > 1)
  5048. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  5049. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  5050. $output .= '</table>' . "\n";
  5051. print $OUTPUT->box($output);
  5052. } // function view_dates()
  5053. } // class activity
  5054. /// Class to manage Interactive Learning Module (iLM)
  5055. class ilm {
  5056. var $ilm;
  5057. /// Constructor of class
  5058. // @param int $id Id of iLM
  5059. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  5060. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  5061. function __construct ($id) {
  5062. global $DB;
  5063. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  5064. if (empty($this->ilm))
  5065. $this->ilm = null;
  5066. }
  5067. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  5068. // @calledby view_iassign_current()
  5069. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  5070. global $USER, $CFG, $DB;
  5071. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  5072. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5073. $typec = strtolower($iassign_ilm->type);
  5074. require_once 'ilm_handlers/' . $typec . '.php';
  5075. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  5076. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  5077. return $retorno;
  5078. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  5079. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  5080. // @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);
  5081. // @param int $iassign_statement_activity_itemid Id of iassign statement
  5082. // @param Object $file File in use in activity
  5083. // @return int Return the id of log
  5084. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  5085. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  5086. $newentry = new stdClass();
  5087. $newentry->iassign_statementid = $iassign_activity_itemid;
  5088. $newentry->userid = $USER->id;
  5089. $newentry->filesid = $content_or_id_from_ilm_security;
  5090. $newentry->timecreated = time();
  5091. $newentry->view = 1;
  5092. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  5093. if (!$id_iLM_security) {
  5094. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  5095. } // from (!$DB->insert_record("iassign_security", $newentry))
  5096. return $id_iLM_security;
  5097. }
  5098. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  5099. // @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);
  5100. // @param int $userid
  5101. // @param int $iassign_activity_itemid Id of iassign statement
  5102. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  5103. global $DB;
  5104. // 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")
  5105. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  5106. }
  5107. } // class ilm
  5108. /// Class to manage settings of iLM.
  5109. class ilm_settings {
  5110. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  5111. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5112. // @param int $ilm_id Id of iLM
  5113. // @param array $options An array with options for create dynamic tag html APPLET
  5114. // @return string Return with a tag html APPLET created
  5115. static function build_ilm_tags ($ilm_id, $options = array()) {
  5116. global $DB;
  5117. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5118. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5119. $typec = strtolower($iassign_ilm->type);
  5120. require_once 'ilm_handlers/' . $typec . '.php';
  5121. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  5122. return $retorno;
  5123. } // static function build_ilm_tags($ilm_id, $options = array())
  5124. /// Function for get modified date of iLM file
  5125. // @param string $file_jar String with Ids of iLM files
  5126. // @return string Return with the filenames and modified date
  5127. static function applet_filetime ($file_jar) {
  5128. $filetime = "";
  5129. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5130. $files_jar = explode(",", $file_jar);
  5131. foreach ($files_jar as $one_file) {
  5132. $file = $fs->get_file_by_id($one_file);
  5133. if ($file)
  5134. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  5135. }
  5136. return $filetime;
  5137. }
  5138. /// Function for verify an default applet
  5139. // @param String $file_jar String containing an list de ids of applet files
  5140. // @return boolean Return true or fale if applet is default
  5141. static function applet_default ($file_jar) {
  5142. $is_default = true;
  5143. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5144. $files_jar = explode(",", $file_jar);
  5145. foreach ($files_jar as $one_file) {
  5146. $file = $fs->get_file_by_id($one_file);
  5147. if ($file)
  5148. $is_default &= ($file->get_itemid() == 0);
  5149. }
  5150. return $is_default;
  5151. }
  5152. /// Function for get form variables for add, edit, or copy iLM
  5153. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  5154. // @see settings_form.php
  5155. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  5156. // @param int $ilm_id Id of iLM
  5157. // @param string $action String with the action
  5158. // @return object Return an object with forms variables
  5159. static function add_edit_copy_ilm ($ilm_id, $action) {
  5160. global $USER, $DB, $CFG;
  5161. require_once('settings_form.php'); // put the form
  5162. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5163. $param = new stdClass();
  5164. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  5165. $param->action = $action;
  5166. $param->ilm_id = $ilm_id;
  5167. $CFG->action_ilm = $action;
  5168. $CFG->ilm_id = $ilm_id;
  5169. if ($action == 'add') {
  5170. $param->title = get_string('add_ilm', 'iassign');
  5171. $param->name = "";
  5172. $param->version = "";
  5173. $param->url = "";
  5174. $param->description = "";
  5175. $param->extension = "";
  5176. $param->author = $USER->id;
  5177. $param->file_jar = "";
  5178. $param->file_jar_static = "";
  5179. $param->file_class = "";
  5180. $param->width = 800;
  5181. $param->height = 600;
  5182. $param->enable = 0; // 0 - hide / 1 - show
  5183. $param->timecreated = time();
  5184. $param->timemodified = time();
  5185. $param->evaluate = 0;
  5186. $param->parent = 0;
  5187. }
  5188. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  5189. if ($iassign_ilm) {
  5190. $description = json_decode($iassign_ilm->description);
  5191. $param->title = get_string('edit_ilm', 'iassign');
  5192. $param->id = $iassign_ilm->id;
  5193. $param->name_ilm = $iassign_ilm->name;
  5194. $param->name = $iassign_ilm->name;
  5195. $param->version = $iassign_ilm->version;
  5196. $param->ilm_type = $iassign_ilm->type;
  5197. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5198. $param->url = $iassign_ilm->url; // iLM official URL
  5199. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  5200. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  5201. $param->editingbehavior = $iassign_ilm->editingbehavior;
  5202. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  5203. if (!isset($description->{current_language()})) {
  5204. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  5205. else
  5206. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  5207. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  5208. }
  5209. else
  5210. $param->description = $description->{current_language()};
  5211. $param->description_lang = $iassign_ilm->description;
  5212. $param->extension = $iassign_ilm->extension;
  5213. $param->author = $iassign_ilm->author;
  5214. $param->file_jar = $iassign_ilm->file_jar;
  5215. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  5216. $param->file_class = $iassign_ilm->file_class;
  5217. $param->width = $iassign_ilm->width;
  5218. $param->height = $iassign_ilm->height;
  5219. $param->enable = $iassign_ilm->enable;
  5220. $param->timecreated = $iassign_ilm->timecreated;
  5221. $param->timemodified = time();
  5222. $param->evaluate = $iassign_ilm->evaluate;
  5223. $param->parent = $iassign_ilm->parent;
  5224. }
  5225. }
  5226. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  5227. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  5228. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5229. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  5230. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  5231. // echo "Sem dados<br/>"; exit;
  5232. return;
  5233. }
  5234. $description = json_decode($iassign_ilm->description);
  5235. if ($iassign_ilm) {
  5236. if ($iassign_ilm->parent == 0)
  5237. $iassign_ilm->parent = $ilm_id;
  5238. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  5239. $param->title = get_string('new_version_ilm', 'iassign');
  5240. $param->name_ilm = $iassign_ilm->name;
  5241. $param->name = $iassign_ilm->name;
  5242. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  5243. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  5244. $param->version = $iassign_ilm->version; // do not erase field 'version'
  5245. $param->ilm_type = $iassign_ilm->type;
  5246. $param->url = $iassign_ilm->url;
  5247. $param->description = $description->{current_language()};
  5248. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  5249. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5250. $param->extension = $iassign_ilm->extension;
  5251. $param->author = $USER->id;
  5252. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  5253. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  5254. $param->file_jar_static = '';
  5255. $param->file_class = $iassign_ilm->file_class;
  5256. $param->width = $iassign_ilm->width;
  5257. $param->height = $iassign_ilm->height;
  5258. $param->enable = 0;
  5259. $param->timecreated = time();
  5260. $param->timemodified = time();
  5261. $param->evaluate = $iassign_ilm->evaluate;
  5262. $param->parent = $iassign_ilm->parent;
  5263. }
  5264. }
  5265. elseif ($action == 'copy') {
  5266. $description = json_decode($iassign_ilm->description);
  5267. if ($iassign_ilm) {
  5268. if ($iassign_ilm->parent == 0)
  5269. $iassign_ilm->parent = $ilm_id;
  5270. $param->title = get_string('copy_ilm', 'iassign');
  5271. $param->id = $iassign_ilm->id;
  5272. $param->name_ilm = $iassign_ilm->name;
  5273. $param->name = $iassign_ilm->name;
  5274. $param->version = "";
  5275. $param->ilm_type = $iassign_ilm->type;
  5276. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5277. $param->url = $iassign_ilm->url;
  5278. $param->description = $description->{current_language()};
  5279. $param->description_lang = $iassign_ilm->description;
  5280. $param->extension = $iassign_ilm->extension;
  5281. $param->author = $USER->id;
  5282. $param->file_jar = '';
  5283. $param->file_jar_static = '';
  5284. $param->file_class = $iassign_ilm->file_class;
  5285. $param->width = $iassign_ilm->width;
  5286. $param->height = $iassign_ilm->height;
  5287. $param->enable = 0;
  5288. $param->timecreated = time();
  5289. $param->timemodified = time();
  5290. $param->evaluate = $iassign_ilm->evaluate;
  5291. $param->parent = $iassign_ilm->parent;
  5292. }
  5293. }
  5294. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  5295. //D var_dump(debug_backtrace());
  5296. //D print_r(debug_backtrace());
  5297. return $param;
  5298. } // static function add_edit_copy_ilm($ilm_id, $action)
  5299. /// Function for save iLM file in moodledata
  5300. // @param int $itemid Itemid of file save in draft (upload file)
  5301. // @param int $ilm_id Id of iLM
  5302. // @return string Return an string with ids of iLM files
  5303. static function new_file_ilm ($itemid, $iassign_ilm) {
  5304. global $CFG, $USER, $DB;
  5305. $return = null;
  5306. $file_jar = array();
  5307. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5308. $contextuser = context_user::instance($USER->id);
  5309. $contextsystem = context_system::instance();
  5310. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  5311. if ($files_ilm) {
  5312. foreach ($files_ilm as $value) {
  5313. // CHECK IF file is HTML type
  5314. if ($iassign_ilm->type == 1) {
  5315. // Check if the file extension is ZIP
  5316. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  5317. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  5318. if ((strtolower($ext) == 'zip')) {
  5319. // Coping...:
  5320. $destination = 'ilm_debug/' . $value->get_filename();
  5321. $value->copy_content_to($destination);
  5322. // Extracting content...:
  5323. $zip = new ZipArchive();
  5324. $extracted = './ilm';
  5325. $dir = "";
  5326. if ($zip->open($destination) === TRUE) {
  5327. $dir = './ilm/' . trim($zip->getNameIndex(0));
  5328. if (is_dir($dir)) {
  5329. $i = 1;
  5330. $previous = str_replace("/", "", $zip->getNameIndex(0));
  5331. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  5332. $i++;
  5333. }
  5334. $name = $previous . "_" . $i;
  5335. $dir = './ilm/' . $name . "/";
  5336. $j = 0;
  5337. while ($item_name = $zip->getNameIndex($j)) {
  5338. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  5339. $j++;
  5340. }
  5341. $zip->close();
  5342. }
  5343. $zip->open($destination);
  5344. $zip->extractTo($extracted);
  5345. $zip->close();
  5346. // After the extraction, remove it from DEBUG
  5347. unlink($destination);
  5348. } else { // Error trying to open destination...
  5349. // After the extraction error, also remove it from DEBUG
  5350. unlink($destination);
  5351. print_error('error_add_ilm_zip', 'iassign');
  5352. }
  5353. return $dir;
  5354. }
  5355. } // if ($iassign_ilm->type == 1)
  5356. if ($value->get_filename() != '.') {
  5357. $file_ilm = array(
  5358. 'userid' => $USER->id,
  5359. 'contextid' => $contextsystem->id,
  5360. 'component' => 'mod_iassign',
  5361. 'filearea' => 'ilm',
  5362. 'itemid' => rand(1, 999999999),
  5363. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  5364. 'filename' => $value->get_filename());
  5365. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  5366. array_push($file_jar, $file_ilm->get_id());
  5367. }
  5368. }
  5369. if (!empty($file_jar)) {
  5370. $return = implode(",", $file_jar);
  5371. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  5372. foreach ($old_file_jar as $value) {
  5373. $file = $fs->get_file_by_id($value);
  5374. if ($file)
  5375. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  5376. }
  5377. }
  5378. }
  5379. else // if ($files_ilm)
  5380. $return = $iassign_ilm->file_jar;
  5381. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  5382. return $return;
  5383. } // static function new_file_ilm($itemid, $iassign_ilm)
  5384. /// Function for save in database an new iLM
  5385. // @param object $param An object with iLM params
  5386. static function new_ilm ($itemid) {
  5387. global $CFG, $USER, $OUTPUT;
  5388. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5389. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5390. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5391. }
  5392. $pathtemp = $CFG->dataroot . '/temp/';
  5393. $contextuser = context_user::instance($USER->id);
  5394. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5395. $zip = new zip_packer();
  5396. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5397. foreach ($files as $file) {
  5398. if (!$file->is_directory())
  5399. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5400. }
  5401. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5402. // Verifica se o pacote possui o XML
  5403. if (!$application_xml) {
  5404. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5405. return;
  5406. } else {
  5407. $missing = "";
  5408. if (!isset($application_xml->name)) {
  5409. $missing .= "name";
  5410. }
  5411. if (!isset($application_xml->version)) {
  5412. $missing .= ", version";
  5413. }
  5414. if (!isset($application_xml->type)) {
  5415. $missing .= ", type";
  5416. }
  5417. if (!isset($application_xml->extension)) {
  5418. $missing .= ", extension";
  5419. }
  5420. if (!isset($application_xml->file_jar)) {
  5421. $missing .= ", file_jar";
  5422. }
  5423. if (!isset($application_xml->file_class)) {
  5424. $missing .= ", file_class";
  5425. }
  5426. if (!isset($application_xml->width)) {
  5427. $missing .= ", width";
  5428. }
  5429. if (!isset($application_xml->height)) {
  5430. $missing .= ", height";
  5431. }
  5432. if (!isset($application_xml->evaluate)) {
  5433. $missing .= ", evaluate";
  5434. }
  5435. if (strlen($missing) > 2) {
  5436. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5437. return;
  5438. }
  5439. }
  5440. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5441. $typec = strtolower($application_xml->type);
  5442. require_once 'ilm_handlers/' . $typec . '.php';
  5443. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5444. return $retorno;
  5445. } // static function new_ilm($itemid)
  5446. /// Function for save in database an iLM edit
  5447. // @param object $param An object with iLM params
  5448. static function edit_ilm ($param, $itemid) {
  5449. // Descobrir o tipo de iLM:
  5450. global $DB, $USER, $CFG;
  5451. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5452. $pathtemp = $CFG->dataroot . '/temp/';
  5453. $contextuser = context_user::instance($USER->id);
  5454. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5455. $zip = new zip_packer();
  5456. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5457. $files_extract = null;
  5458. foreach ($files as $file) {
  5459. if (!$file->is_directory())
  5460. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5461. }
  5462. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5463. $typec = strtolower($iassign_t->type);
  5464. require_once 'ilm_handlers/' . $typec . '.php';
  5465. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5466. }
  5467. /// Function for register the new iLM (in database and in the directory)
  5468. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5469. // @param object $param An object with iLM params
  5470. static function copy_new_version_ilm ($param) {
  5471. global $DB, $CFG, $USER;
  5472. $itemid = $param->file;
  5473. $pathtemp = $CFG->dataroot . '/temp/';
  5474. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5475. //D echo "pathtemp=$pathtemp<br/>";
  5476. $contextuser = context_user::instance($USER->id);
  5477. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5478. $zip = new zip_packer();
  5479. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5480. $files_extract = null;
  5481. foreach ($files as $file) {
  5482. if (!$file->is_directory())
  5483. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5484. }
  5485. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5486. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5487. $typec = strtolower($iassign_t->type);
  5488. require_once 'ilm_handlers/' . $typec . '.php';
  5489. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5490. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5491. } // static function copy_new_version_ilm($param)
  5492. //VER::
  5493. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5494. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5495. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5496. /// Function for change visibility of iLM
  5497. // @param int $ilm_id Id of iLM
  5498. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5499. static function visible_ilm ($ilm_id, $status) {
  5500. global $DB;
  5501. if ($status == 0)
  5502. $visible = 1;
  5503. else
  5504. $visible = 0;
  5505. $newentry = new stdClass();
  5506. $newentry->id = $ilm_id;
  5507. $newentry->enable = $visible;
  5508. if (!$DB->update_record("iassign_ilm", $newentry))
  5509. error(get_string('error_edit_ilm', 'iassign'));
  5510. }
  5511. /// Function for confirm change default iLM
  5512. // @param int $ilm_id Id of iLM
  5513. // @param int $ilm_parent Id of parent iLM
  5514. // @return string Return with an string for create default page confirmation
  5515. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5516. global $OUTPUT, $DB;
  5517. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5518. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5519. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5520. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5521. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5522. return $return;
  5523. }
  5524. /// Function for change the default iLM
  5525. // @see settings_ilm.php
  5526. // @param int $ilm_id Id of iLM
  5527. // @return int Return Id of default iLM
  5528. static function default_ilm ($ilm_id) {
  5529. global $DB;
  5530. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5531. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5532. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5533. $iassign_ilm_default->id = $iassign_ilm->id;
  5534. $iassign_ilm_default->parent = 0;
  5535. $iassign_ilm->parent = $iassign_ilm_default->id;
  5536. $iassign_ilm->id = 0;
  5537. $iassign_ilm_default->enable = 1;
  5538. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5539. print_error('error_edit_ilm', 'iassign');
  5540. }
  5541. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5542. if (!$inserted) {
  5543. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5544. print_error($msg_error);
  5545. //xx print_error('error_add_ilm', 'iassign');
  5546. }
  5547. return $iassign_ilm_default->id;
  5548. } // static function default_ilm ($ilm_id)
  5549. /// Function for confirm delete iLM
  5550. // @param int $ilm_id Id of iLM
  5551. // @param int $ilm_parent Id of parent iLM
  5552. // @return string Return with an string for create delete page confirmation
  5553. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5554. global $OUTPUT, $DB;
  5555. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5556. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5557. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5558. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5559. }
  5560. /// Function for delete directory where the iLM is allocated.
  5561. // @param string $dirPath
  5562. // @throws InvalidArgumentException
  5563. public static function delete_dir ($dirPath) {
  5564. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5565. $dirPath .= '/';
  5566. }
  5567. $files = glob($dirPath . '*', GLOB_MARK);
  5568. foreach ($files as $file) {
  5569. if (is_dir($file)) {
  5570. ilm_settings::delete_dir($file);
  5571. } else {
  5572. unlink($file);
  5573. }
  5574. }
  5575. rmdir($dirPath);
  5576. }
  5577. /// Function for delete iLM
  5578. // @param int $ilm_id Id of iLM
  5579. // @return int Return Id of parent iLM
  5580. static function delete_ilm ($ilm_id) {
  5581. global $DB;
  5582. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5583. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5584. $typec = strtolower($iassign_ilm->type);
  5585. require_once 'ilm_handlers/' . $typec . '.php';
  5586. $retorno = $typec::delete_ilm($ilm_id);
  5587. return $retorno;
  5588. }
  5589. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5590. // @param int $ilm_id Id of iLM
  5591. static function export_ilm ($ilm_id) {
  5592. global $DB;
  5593. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5594. if (!$iassign_ilm) return; // security debug...
  5595. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5596. $typec = strtolower($iassign_ilm->type);
  5597. if (!$typec) $typec = "html5"; // security debug...
  5598. require_once 'ilm_handlers/' . $typec . '.php';
  5599. $typec::export_ilm($ilm_id);
  5600. } // static function export_ilm($ilm_id)
  5601. //TODO iLM_HTML5 :: //MOOC 2016
  5602. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5603. // @param int $ilm_id Id of iLM
  5604. static function export_update_ilm ($ilm_id) {
  5605. global $DB, $CFG;
  5606. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5607. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5608. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5609. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5610. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5611. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5612. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5613. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5614. $upgrade_descriptor .= '</upgrade>' . "\n";
  5615. file_put_contents($xml_filename, $upgrade_descriptor);
  5616. header("Pragma: public");
  5617. header("Expires: 0");
  5618. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5619. header("Cache-Control: private", false);
  5620. header('Content-Type: application/xml; charset=utf-8');
  5621. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5622. header("Content-Length: " . @filesize($xml_filename));
  5623. set_time_limit(0);
  5624. @readfile("$xml_filename") || die("File not found.");
  5625. unlink($xml_filename);
  5626. exit;
  5627. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5628. /// Function for save iLM from XML descriptor
  5629. // @param array $application_xml Data of XML descriptor
  5630. // @param array $files_extract Filenames of extract files
  5631. // @return array Return an array content id of JAR files
  5632. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5633. global $CFG, $USER;
  5634. // Tratamento diferenciado se for do tipo HTML5:
  5635. $source = "";
  5636. $diretorio = "";
  5637. if (strtolower($application_xml->type) == 'html5') {
  5638. $i = 0;
  5639. foreach ($files_extract as $key => $value) {
  5640. $file = $CFG->dataroot . '/temp/' . $key;
  5641. // Verifica se já existe a pasta no diretório dos iLM:
  5642. if ($i == 0) {
  5643. $source = $file;
  5644. if (file_exists("ilm/" . basename($file))) {
  5645. $j = 1;
  5646. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5647. $j++;
  5648. }
  5649. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5650. // mkdir($diretorio, 0777, true);
  5651. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5652. }
  5653. else {
  5654. $diretorio = 'ilm/' . basename($file);
  5655. // mkdir($diretorio, 0777, true);
  5656. mkdir($diretorio, 0755, true);
  5657. }
  5658. break;
  5659. }
  5660. $i++;
  5661. }
  5662. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5663. if ($item->isDir()) {
  5664. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5665. }
  5666. else {
  5667. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5668. }
  5669. }
  5670. ilm_settings::delete_dir($source);
  5671. return "./" . $diretorio;
  5672. }
  5673. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5674. $file_jar = array();
  5675. $files_ilm = explode(",", $application_xml->file_jar);
  5676. $contextsystem = context_system::instance();
  5677. foreach ($files_ilm as $value) {
  5678. $file_ilm = array(
  5679. 'userid' => $USER->id,
  5680. 'contextid' => $contextsystem->id,
  5681. 'component' => 'mod_iassign',
  5682. 'filearea' => 'ilm',
  5683. 'itemid' => rand(1, 999999999),
  5684. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5685. 'filename' => $value);
  5686. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5687. array_push($file_jar, $file_ilm->get_id());
  5688. }
  5689. foreach ($files_extract as $key => $value) {
  5690. $file = $CFG->dataroot . '/temp/' . $key;
  5691. if (file_exists($file))
  5692. unlink($file);
  5693. }
  5694. return $file_jar;
  5695. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5696. /// Function for import the iLM from an package
  5697. // @param int $itemid Itemid of zip file
  5698. static function import_ilm ($itemid) {
  5699. global $CFG, $USER, $OUTPUT;
  5700. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5701. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5702. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5703. }
  5704. $pathtemp = $CFG->dataroot . '/temp/';
  5705. $contextuser = context_user::instance($USER->id);
  5706. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5707. $zip = new zip_packer();
  5708. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5709. foreach ($files as $file) {
  5710. if (!$file->is_directory())
  5711. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5712. }
  5713. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5714. // Verifica se o pacote possui o XML
  5715. if (!$application_xml) {
  5716. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5717. return;
  5718. } else {
  5719. $missing = "";
  5720. if (!isset($application_xml->name)) {
  5721. $missing .= "name";
  5722. }
  5723. if (!isset($application_xml->version)) {
  5724. $missing .= ", version";
  5725. }
  5726. if (!isset($application_xml->type)) {
  5727. $missing .= ", type";
  5728. }
  5729. if (!isset($application_xml->extension)) {
  5730. $missing .= ", extension";
  5731. }
  5732. if (!isset($application_xml->file_jar)) {
  5733. $missing .= ", file_jar";
  5734. }
  5735. if (!isset($application_xml->file_class)) {
  5736. $missing .= ", file_class";
  5737. }
  5738. if (!isset($application_xml->width)) {
  5739. $missing .= ", width";
  5740. }
  5741. if (!isset($application_xml->height)) {
  5742. $missing .= ", height";
  5743. }
  5744. if (!isset($application_xml->evaluate)) {
  5745. $missing .= ", evaluate";
  5746. }
  5747. if (strlen($missing) > 2) {
  5748. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5749. return;
  5750. }
  5751. }
  5752. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5753. $typec = strtolower($application_xml->type);
  5754. require_once 'ilm_handlers/' . $typec . '.php';
  5755. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5756. } // static function import_ilm($itemid)
  5757. /// Function for list iLM defaults
  5758. // @return string Return an string with a table of iLM
  5759. static function list_ilm () {
  5760. global $DB, $OUTPUT;
  5761. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5762. $str = '';
  5763. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5764. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5765. if ($iassign_ilm) {
  5766. foreach ($iassign_ilm as $ilm) {
  5767. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5768. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5769. $str .= '<tr><td>';
  5770. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5771. $str .= '<tr>';
  5772. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5773. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5774. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5775. $str .= '</tr>';
  5776. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5777. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5778. $str .= '</table>';
  5779. $str .= '</td></tr>';
  5780. }
  5781. }
  5782. $str .= '</table>';
  5783. return $str;
  5784. }
  5785. /// Function for download and install an upgrade of an iLM
  5786. // @param int $ilm_id Id of iLM
  5787. static function upgrade_ilm ($ilm_id) {
  5788. global $DB, $CFG, $USER;
  5789. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5790. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5791. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5792. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5793. if (!$result)
  5794. print_error('error_upgrade_ilm', 'iassign');
  5795. else {
  5796. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5797. $extension = explode(".", $zip_filename);
  5798. if ($extension[count($extension) - 1] != 'ipz') {
  5799. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5800. die;
  5801. }
  5802. $zip = new zip_packer();
  5803. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5804. $contextuser = context_user::instance($USER->id);
  5805. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5806. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5807. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5808. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5809. if (file_exists($zip_filename))
  5810. unlink($zip_filename);
  5811. if (empty($file_jar)) {
  5812. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5813. print_error($msg_error);
  5814. //xx print_error('error_add_ilm', 'iassign');
  5815. }
  5816. else {
  5817. $newentry = new stdClass();
  5818. $newentry->name = (String) $application_xml->name;
  5819. $newentry->version = (String) $application_xml->version;
  5820. $newentry->url = (String) $application_xml->url;
  5821. $newentry->description = $description_str;
  5822. $newentry->extension = strtolower((String) $application_xml->extension);
  5823. $newentry->file_jar = implode(",", $file_jar);
  5824. $newentry->file_class = (String) $application_xml->file_class;
  5825. $newentry->width = (String) $application_xml->width;
  5826. $newentry->height = (String) $application_xml->height;
  5827. $newentry->enable = 0;
  5828. $newentry->timemodified = time();
  5829. $newentry->author = $USER->id;
  5830. $newentry->timecreated = time();
  5831. $newentry->evaluate = (String) $application_xml->evaluate;
  5832. $newentry->parent = $ilm_id;
  5833. }
  5834. }
  5835. return $iassign_ilm->id;
  5836. } // static function upgrade_ilm($ilm_id)
  5837. //MOOC2014 -- inicio
  5838. //TODO: REVIEW
  5839. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5840. // static function move_iassign($ilm_id)
  5841. //MOOC2014 -- final
  5842. /// Function for list iLM versions with all informations, under "admin" plugin view: .../mod/iassign/settings_ilm.php?action=view&ilm_id=".$ilmid."&from=admin
  5843. // @return string Return an string with a table of iLM
  5844. static function view_ilm ($ilmid, $from) {
  5845. global $DB;
  5846. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5847. // Get the iLM type and calls its correspondent handler ('Java' or 'HTML5')
  5848. $typec = strtolower($iassign_ilm->type);
  5849. require_once 'ilm_handlers/' . $typec . '.php';
  5850. $retorno = $typec::view_ilm($ilmid, $from);
  5851. return $retorno;
  5852. }
  5853. /// Function for get form variables for add, edit, or copy iLM params
  5854. // @param int $ilm_param_id Id of iLM param
  5855. // @param string $action String with the action
  5856. // @return object Return an object with forms variables
  5857. static function add_edit_copy_param ($ilm_param_id, $action) {
  5858. global $DB;
  5859. require_once('params_form.php');
  5860. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5861. $param = new stdClass();
  5862. $param->action = $action;
  5863. $param->ilm_param_id = $ilm_param_id;
  5864. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5865. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5866. $type = $iassign_ilm_config->param_type;
  5867. if ($action == 'add') {
  5868. $param->title = get_string('add_ilm', 'iassign');
  5869. $param->iassign_ilmid = $ilm_param_id;
  5870. $param->param_name = "";
  5871. $param->param_value = "";
  5872. $param->description = "";
  5873. $param->visible = 1;
  5874. }
  5875. elseif ($action == 'edit') {
  5876. if ($iassign_ilm_config) {
  5877. $param->title = get_string('edit_ilm', 'iassign');
  5878. $param->id = $iassign_ilm_config->id;
  5879. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5880. $param->param_type = $type; //MOOC2014
  5881. $param->param_name = $iassign_ilm_config->param_name;
  5882. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5883. $param->param_value = $iassign_ilm_config->param_value;
  5884. else //MOOC2014
  5885. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5886. $param->param_value = $iassign_ilm_config->param_value;
  5887. $param->description = $iassign_ilm_config->description;
  5888. $param->visible = $iassign_ilm_config->visible;
  5889. }
  5890. }
  5891. elseif ($action == 'copy') {
  5892. if ($iassign_ilm_config) {
  5893. $param->title = get_string('copy_ilm', 'iassign');
  5894. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5895. $param->param_type = $type; //MOOC2014
  5896. $param->param_name = $iassign_ilm_config->param_name;
  5897. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5898. $param->param_value = $iassign_ilm_config->param_value;
  5899. else //MOOC2014
  5900. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5901. $param->description = $iassign_ilm_config->description;
  5902. $param->visible = $iassign_ilm_config->visible;
  5903. }
  5904. }
  5905. return $param;
  5906. } // static function add_edit_copy_param($ilm_param_id, $action)
  5907. /// Function for change visibility of iLM param
  5908. // @param int $ilm_param_id Id of iLM param
  5909. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5910. static function visible_param ($ilm_param_id, $status) {
  5911. global $DB, $CFG;
  5912. if ($status == 0)
  5913. $visible = 1;
  5914. else
  5915. $visible = 0;
  5916. $newentry = new stdClass();
  5917. $newentry->id = $ilm_param_id;
  5918. $newentry->visible = $visible;
  5919. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5920. error(get_string('error_edit_param', 'iassign'));
  5921. }
  5922. /// Function for save in database an new iLM param
  5923. // @param object $param An object with iLM params
  5924. static function add_param ($param) {
  5925. global $DB;
  5926. $newentry = new stdClass();
  5927. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5928. //MOOC2014 $newentry->param_name = $param->param_name;
  5929. $newentry->param_type = $param->param_type; //MOOC2014
  5930. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5931. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5932. $newentry->param_value = $param->param_value;
  5933. else //MOOC2014
  5934. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5935. $newentry->description = $param->description;
  5936. $newentry->visible = $param->visible;
  5937. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5938. if (!$newentry->id) {
  5939. print_error('error_add_param', 'iassign');
  5940. }
  5941. }
  5942. /// Function for save in database a iLM param edit
  5943. // @param object $param An object with iLM params
  5944. static function edit_param ($param) {
  5945. global $DB;
  5946. $updentry = new stdClass();
  5947. $updentry->id = $param->id;
  5948. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5949. $updentry->param_type = $param->param_type; //MOOC2014
  5950. // $updentry->param_name = $param->param_name;
  5951. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5952. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5953. $updentry->param_value = $param->param_value;
  5954. else //MOOC2014
  5955. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5956. $updentry->description = $param->description;
  5957. $updentry->visible = $param->visible;
  5958. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5959. error(get_string('error_edit_param', 'iassign'));
  5960. }
  5961. }
  5962. /// Function for save in database a iLM param copy
  5963. // @param object $param An object with iLM params
  5964. static function copy_param ($param) {
  5965. global $DB;
  5966. $newentry = new stdClass();
  5967. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5968. //$newentry->param_name = $param->param_name;
  5969. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5970. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5971. $newentry->param_value = $param->param_value;
  5972. else //MOOC2014
  5973. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5974. $newentry->description = $param->description;
  5975. $newentry->visible = $param->visible;
  5976. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5977. if (!$newentry->id) {
  5978. print_error('error_add_param', 'iassign');
  5979. }
  5980. }
  5981. /// Function for delete iLM param of database
  5982. // @param int $param_id Id of iLM param
  5983. static function delete_param ($param_id) {
  5984. global $DB;
  5985. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5986. print_error('error_delete_param', 'iassign');
  5987. }
  5988. }
  5989. } // class ilm_settings
  5990. /// Class for manage iLM files (editor).
  5991. class ilm_manager {
  5992. var $id; // course id
  5993. var $url;
  5994. var $from;
  5995. /// Constructor for the base ilm_manager class
  5996. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5997. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5998. function __construct ($id, $url, $from) {
  5999. $this->id = $id; // course id
  6000. $this->url = $url;
  6001. $this->from = $from;
  6002. }
  6003. /// Function to get iAssign content file in Moodle data (exercise)
  6004. // @calledby x function preview_ilm($iassign_ilm) :
  6005. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  6006. function get_file_ilm () {
  6007. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6008. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6009. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  6010. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6011. $md_file = $fs->get_file_by_id($fileid);
  6012. $ilm_content_file = $md_file->get_content();
  6013. return $ilm_content_file;
  6014. }
  6015. /// Function for creating a new file from the iLM online editor
  6016. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  6017. function ilm_editor_new () {
  6018. global $CFG, $DB, $OUTPUT, $PAGE;
  6019. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6020. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6021. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6022. $context = context_course::instance($this->id);
  6023. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6024. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  6025. if (!$iassign) {
  6026. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  6027. die();
  6028. }
  6029. $temp = explode(",", $iassign->extension);
  6030. $extension = $temp[0]; // default extension for this iLM
  6031. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  6032. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6033. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  6034. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  6035. if ($stringArchiveContent != NULL) {
  6036. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  6037. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6038. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  6039. $filename = optional_param('filename', NULL, PARAM_RAW);
  6040. //Leo $filename = iassign_utils::format_filename($filename); //
  6041. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  6042. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  6043. //2019/02 $arrayfilename = explode(".", $filename);
  6044. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  6045. //2019/02 $count_dots = count($arrayfilename);
  6046. //2019/02 if ($count_dots > 0) { // at least one dot mark
  6047. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  6048. //2019/02 if ($last_name != $extension)
  6049. //2019/02 $filename = $filename . '.' . $extension;
  6050. //2019/02 }
  6051. //2019/02 else { // no extension...
  6052. //2019/02 $filename = $filename . '.' . $extension;
  6053. //2019/02 }
  6054. // Store the name of recent created file
  6055. $_SESSION['file_name'] = $filename;
  6056. //$this->write_file_iassign($string, $filename);
  6057. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  6058. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  6059. die();
  6060. }
  6061. else { // if ($stringArchiveContent != NULL)
  6062. // iLM On-line editor
  6063. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6064. $str_get_iLM = "window.frames.iLM";
  6065. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6066. }
  6067. else { // otherwise it is JAR named 'iLM'
  6068. $str_get_iLM = "document.iLM";
  6069. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6070. }
  6071. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6072. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  6073. $files_array = '';
  6074. foreach ($files as $value) {
  6075. if ($value->get_filename() != ".")
  6076. $files_array .= "'" . $value->get_filename() . "',";
  6077. }
  6078. $files_array .= "''";
  6079. $file = null;
  6080. $ia_content = "";
  6081. $filename = "";
  6082. $error_files_exists = get_string('error_file_exists', 'iassign');
  6083. $output = "<script type='text/javascript'>
  6084. //<![CDATA[
  6085. //D alert('locallib.php: ilm_editor_new');
  6086. function submit_iLM_Answer () {
  6087. var docFormOnLineEditor = document.formEnvio;
  6088. var resposta_exerc = new Array(3);
  6089. var valor_resposta = new Array(3);
  6090. var sessao = new Array(3);
  6091. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6092. resposta_exerc[0] = doc_iLM.getAnswer();
  6093. valor_resposta[0] = doc_iLM.getEvaluation();
  6094. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  6095. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  6096. var files = new Array(" . $files_array . ");
  6097. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  6098. if (docFormOnLineEditor.filename.value=='') {
  6099. // ERROR: the file name is empty
  6100. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  6101. return false;
  6102. }
  6103. // }
  6104. for (i=0; i<files.length; i++) {
  6105. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  6106. alert('" . $error_files_exists . "');
  6107. return false;
  6108. }
  6109. }
  6110. docFormOnLineEditor.submit();
  6111. return true;
  6112. }
  6113. //]]>
  6114. </script>\n";
  6115. $output .= "
  6116. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6117. $output .= $OUTPUT->box_start();
  6118. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  6119. $output .= "
  6120. <table width='100%' cellpadding='20'>
  6121. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  6122. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  6123. </tr>
  6124. </table>\n";
  6125. $output .= $OUTPUT->box_end();
  6126. $output .= "<center>\n";
  6127. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  6128. // Since it is the activity file, it is not necessary to use 'ilm_security'
  6129. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  6130. $output .= $output_ilm;
  6131. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  6132. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  6133. </center>
  6134. </form>\n";
  6135. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6136. $PAGE->navbar->add($title);
  6137. $PAGE->set_title($title);
  6138. $PAGE->set_heading($title); // insert title above the navigation bar
  6139. print $OUTPUT->header();
  6140. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6141. print $output;
  6142. print $OUTPUT->footer();
  6143. }
  6144. die();
  6145. } // function ilm_editor_new()
  6146. /// Function for editing an file in online editor
  6147. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  6148. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  6149. global $CFG, $DB, $OUTPUT, $PAGE;
  6150. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6151. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6152. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6153. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6154. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6155. // If iLM is not registered, error!
  6156. if (!$iassign) {
  6157. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  6158. die;
  6159. }
  6160. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  6161. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  6162. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  6163. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  6164. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6165. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6166. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  6167. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  6168. if ($stringArchiveContent != NULL) {
  6169. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  6170. die();
  6171. } else { // if ($stringArchiveContent != NULL)
  6172. $end_file = '';
  6173. if ($content_file) {
  6174. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  6175. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  6176. }
  6177. $temp = explode(",", $iassign->extension);
  6178. $extension = $temp[0]; // default extension for this iLM
  6179. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6180. $str_get_iLM = "window.frames.iLM";
  6181. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6182. } else { // otherwise it is JAR named 'iLM'
  6183. $str_get_iLM = "document.iLM";
  6184. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6185. }
  6186. $output = "<script type='text/javascript'>
  6187. //<![CDATA[
  6188. function submit_iLM_Answer () {
  6189. var docFormEditor = document.formEnvio;
  6190. var activityAnswer; // to get activity answer (text)
  6191. var activityValue; // to get activity answer value (float)
  6192. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6193. //activityAnswer = doc_iLM.getAnswer();
  6194. //activityValue = doc_iLM.getEvaluation();
  6195. activityAnswer = " . $str_get_iLM . ".getAnswer();
  6196. activityValue = " . $str_get_iLM . ".getEvaluation();
  6197. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  6198. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  6199. docFormEditor.submit();
  6200. return true;
  6201. }
  6202. //]]>
  6203. </script>\n";
  6204. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  6205. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  6206. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  6207. // return true;
  6208. // }
  6209. $output .= "
  6210. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6211. $output .= $OUTPUT->box_start();
  6212. $output .= "
  6213. <table width='100%' cellpadding='20'>
  6214. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  6215. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  6216. <input type='hidden' name='filename' value='$filename'/></td>
  6217. <td>
  6218. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  6219. </tr>
  6220. </table>\n";
  6221. $output .= $OUTPUT->box_end();
  6222. $output .= " <center>\n";
  6223. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  6224. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  6225. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  6226. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  6227. </center>
  6228. </form>\n";
  6229. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6230. $PAGE->navbar->add($title);
  6231. $PAGE->set_title($title);
  6232. $PAGE->set_heading($title); // insert title above the navigation bar
  6233. print $OUTPUT->header();
  6234. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6235. print $output;
  6236. print $OUTPUT->footer();
  6237. } // else if ($stringArchiveContent != NULL)
  6238. die();
  6239. } // function ilm_editor_update()
  6240. /// Function for write iAssign file in Moodle data (exercise)
  6241. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  6242. // @param string $stringArchiveContent Content of iassign file
  6243. // @param string $filename Filename of iassign file
  6244. function write_file_iassign ($stringArchiveContent, $filename) {
  6245. global $USER;
  6246. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6247. $context = context_course::instance($this->id);
  6248. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6249. $dirid = $this->get_dir_ilm('dirid');
  6250. $dir = $fs->get_file_by_id($dirid);
  6251. $fileinfo = array('contextid' => $context->id, // ID of course
  6252. 'component' => 'mod_iassign', // usually = table name
  6253. 'filearea' => 'activity', // usually = table name
  6254. 'itemid' => 0, // usually = ID of row in table
  6255. 'filepath' => '/', // any path beginning and ending whith '/'
  6256. 'userid' => $USER->id,
  6257. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6258. 'filename' => $filename); // any filename
  6259. // Create file containing text. '$stringArchiveContent'
  6260. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6261. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  6262. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  6263. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  6264. // 'Activité interactive enregistrée avec succès sous le nom:';
  6265. // 'Atividade interativa gravada com sucesso sob o nome:'
  6266. $output = "
  6267. <script type='text/javascript'>
  6268. //<![CDATA[
  6269. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  6270. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6271. //]]>
  6272. </script>";
  6273. print $output;
  6274. die();
  6275. }
  6276. /// Function for write iAssign file in Moodle data (exercise)
  6277. // @param string $stringArchiveContent Content of iassign file
  6278. // @param string $filename Filename of iassign file
  6279. // @param int $itemid Itemid of iassign file
  6280. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  6281. global $OUTPUT, $USER;
  6282. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6283. $context = context_course::instance($this->id);
  6284. $dirid = $this->get_dir_ilm('dirid');
  6285. if ($stringArchiveContent != (-1)) {
  6286. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6287. $file = $fs->get_file_by_id($fileid);
  6288. if (!$file) {
  6289. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  6290. die;
  6291. }
  6292. $fileinfo = array('contextid' => $context->id, // ID of context
  6293. 'component' => 'mod_iassign', // usually = table name
  6294. 'filearea' => 'activity', // usually = table name
  6295. 'itemid' => 0, // usually = ID of row in table
  6296. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  6297. 'userid' => $USER->id,
  6298. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6299. 'license' => 'allrightsreserved', // allrightsreserved
  6300. 'timecreated' => $file->get_timecreated(),
  6301. 'filename' => $file->get_filename()); // any filename
  6302. $file->delete();
  6303. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6304. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  6305. }
  6306. $output = "<script type='text/javascript'>
  6307. //<![CDATA[
  6308. alert('" . get_string('sucess_update', 'iassign') . "');\n
  6309. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6310. //]]>
  6311. </script>";
  6312. print $output;
  6313. die();
  6314. }
  6315. /// Function for create an tag for iAssign filter
  6316. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  6317. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6318. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  6319. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6320. // @param int $fileid Id of file
  6321. // @return string Return an string with an tag of iassign filter
  6322. function tag_ilm ($fileid) {
  6323. global $DB;
  6324. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6325. $width = '600';
  6326. $height = '400';
  6327. $file = $fs->get_file_by_id($fileid);
  6328. $filetype = explode(".", $file->get_filename());
  6329. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  6330. foreach ($iassign_ilm as $value) {
  6331. $extensions = explode(",", $value->extension);
  6332. if (in_array($filetype[1], $extensions)) {
  6333. $width = $value->width;
  6334. $height = $value->height;
  6335. }
  6336. }
  6337. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  6338. }
  6339. /// Function for delete iAssign file in Moodle data (exercise)
  6340. function delete_file_ilm () {
  6341. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6342. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6343. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  6344. $file = $fs->get_file_by_id($fileid);
  6345. if ($file)
  6346. $file->delete();
  6347. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6348. die();
  6349. }
  6350. /// Function for delete selected iAssign file in Moodle data (exercise)
  6351. function delete_selected_ilm () {
  6352. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6353. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6354. $context = context_course::instance($this->id);
  6355. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6356. $dirid = $this->get_dir_ilm('dirid');
  6357. foreach ($files_id as $file_id) {
  6358. $file = $fs->get_file_by_id($file_id);
  6359. if ($file) {
  6360. if (!$file->is_directory())
  6361. $file->delete();
  6362. else {
  6363. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6364. foreach ($files_delete as $value)
  6365. $value->delete();
  6366. $file->delete();
  6367. }
  6368. }
  6369. }
  6370. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6371. die();
  6372. }
  6373. /// Function for duplicate iAssign file from "online" edition
  6374. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  6375. function duplicate_file_ilm () {
  6376. global $USER, $COURSE;
  6377. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6378. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6379. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6380. $filename = optional_param('filename', NULL, PARAM_RAW);
  6381. $file = $fs->get_file_by_id($fileid);
  6382. $context = context_course::instance($this->id);
  6383. $fileinfo = array(
  6384. 'contextid' => $context->id, // ID of context
  6385. 'component' => 'mod_iassign', // usually = table name
  6386. 'filearea' => 'activity', // usually = table name
  6387. 'itemid' => 0, // usually = ID of row in table
  6388. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  6389. 'userid' => $USER->id,
  6390. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6391. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  6392. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  6393. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  6394. die();
  6395. }
  6396. /// Function for rename iAssign file
  6397. function rename_file_ilm () {
  6398. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6399. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6400. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6401. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6402. $file = $fs->get_file_by_id($fileid);
  6403. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  6404. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  6405. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6406. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  6407. die();
  6408. }
  6409. /// Function for get iassign file for iassign form
  6410. function add_ilm () {
  6411. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6412. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6413. $output = "
  6414. <script type='text/javascript'>
  6415. //<![CDATA[
  6416. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  6417. iassign_file_link.innerHTML = '$filename';
  6418. window.opener.document.forms['mform1'].file.value='$fileid';
  6419. window.opener.document.forms['mform1'].filename.value='$filename';
  6420. window.close();
  6421. //]]>
  6422. </script>";
  6423. print $output;
  6424. die();
  6425. }
  6426. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  6427. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  6428. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  6429. function preview_ilm ($courseid, $iassign_ilm) {
  6430. global $OUTPUT, $CFG, $USER;
  6431. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6432. $title = get_string('modulename', 'iassign'); // iAssign
  6433. print $OUTPUT->header();
  6434. print $OUTPUT->box_start();
  6435. $javascript = "
  6436. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  6437. <script type='text/javascript'>
  6438. //<![CDATA[
  6439. function submit_close () {
  6440. window.opener.location.reload();
  6441. window.close();
  6442. }
  6443. //]]>
  6444. </script>\n";
  6445. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6446. // to the complete "applet" tag
  6447. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6448. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6449. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6450. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6451. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6452. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6453. if ($ilm_name != "ivprog") {
  6454. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6455. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6456. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6457. } else {
  6458. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6459. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6460. $timecreated = time();
  6461. $token = md5($timecreated);
  6462. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6463. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6464. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6465. $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)
  6466. }
  6467. $html = "
  6468. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6469. <table border='1'>
  6470. <tr><td>
  6471. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6472. <!-- iLM calls : end -->
  6473. </td></tr>
  6474. </table>
  6475. <table>
  6476. <tr>
  6477. <td align='center'>
  6478. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6479. </td></tr>
  6480. </table>
  6481. </form>\n";
  6482. print $javascript . $html;
  6483. print $OUTPUT->box_end();
  6484. //NAO echo format_string($html); // Moodle 3.X
  6485. die();
  6486. } // function preview_ilm($courseid, $iassign_ilm)
  6487. //r_ function preview_ilm ($iassign_ilm)
  6488. //r_ /// Function for preview iassign file from iassign filter.
  6489. //r_ function preview_ilm() {
  6490. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6491. //r_ $tag_filter = $this->tag_ilm($fileid);
  6492. //r_ $javascript = "<script type='text/javascript'>
  6493. //r_ //<![CDATA[
  6494. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6495. //r_ //]]>
  6496. //r_ </script>";
  6497. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6498. //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>
  6499. //r_ </table></form></body></html>";
  6500. //r_ echo $javascript . format_text($html);
  6501. //r_ die;
  6502. //r_ }
  6503. /// Function for export an package (zip) of iassign files
  6504. function export_files_ilm () {
  6505. global $CFG;
  6506. $context = context_course::instance($this->id);
  6507. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6508. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6509. $zip = new zip_archive();
  6510. $zip->open($zip_filename);
  6511. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6512. foreach ($files_id as $file_id) {
  6513. $file = $fs->get_file_by_id($file_id);
  6514. if (!$file->is_directory())
  6515. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6516. else {
  6517. $zip->add_directory($file->get_filepath());
  6518. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6519. foreach ($files_zip as $value) {
  6520. if (!$value->is_directory())
  6521. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6522. else
  6523. $zip->add_directory($value->get_filepath());
  6524. }
  6525. }
  6526. }
  6527. $zip->close();
  6528. header("Pragma: public");
  6529. header("Expires: 0");
  6530. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6531. header("Cache-Control: private", false);
  6532. header("Content-Type: application/zip");
  6533. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6534. header("Content-Transfer-Encoding: binary");
  6535. header("Content-Length: " . @filesize($zip_filename));
  6536. set_time_limit(0);
  6537. @readfile("$zip_filename") || die("File not found.");
  6538. unlink($zip_filename);
  6539. exit;
  6540. }
  6541. /// Function of execute a command in button editor tinymce
  6542. // @param int $fileid Id of file
  6543. function tinymce_ilm ($fileid) {
  6544. $tag_filter = $this->tag_ilm($fileid);
  6545. $output = "<script type='text/javascript'>
  6546. //<![CDATA[
  6547. var tag_filter = '$tag_filter';
  6548. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6549. // all right, insert it
  6550. } else {
  6551. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6552. }
  6553. // window.close();
  6554. //]]>
  6555. </script>\n";
  6556. print $output;
  6557. die();
  6558. }
  6559. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6560. /// Function to add content to the Editor Window
  6561. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6562. // @param int $fileid Id of file
  6563. function editor_ilm ($fileid, $editor) {
  6564. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6565. $output1 = "<script type='text/javascript'>
  6566. //<![CDATA[
  6567. var tag_filter = '$tag_filter';\n";
  6568. if ($editor == 'atto') {
  6569. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6570. } elseif ($editor == 'tinyMCE') {
  6571. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6572. } else
  6573. $output2 = "";
  6574. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6575. window.close();
  6576. //]]>
  6577. </script>\n";
  6578. //D var_dump($output);
  6579. print $output1 . $output2 . $output3;
  6580. die();
  6581. }
  6582. /// Function to add content to the Atto Editor Window
  6583. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6584. // @param int $fileid Id of file
  6585. function atto_ilm ($fileid) {
  6586. global $CFG, $DB;
  6587. $tag_filter = $this->tag_ilm($fileid);
  6588. $output = "<script type='text/javascript'>
  6589. //<![CDATA[
  6590. var tag_filter = '$tag_filter';
  6591. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6592. // all right, insert iLM tag to this editor
  6593. } else {
  6594. // error trying to insert
  6595. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6596. }
  6597. //window.close();
  6598. //]]>
  6599. </script>\n";
  6600. print $output;
  6601. die();
  6602. }
  6603. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6604. // @param string $key Key for return information
  6605. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6606. function get_dir_ilm ($key) {
  6607. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6608. $context = context_course::instance($this->id);
  6609. $dirid = optional_param('dirid', 0, PARAM_INT);
  6610. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6611. if ($dirid == 0) {
  6612. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6613. $dirid = $dir->get_id();
  6614. }
  6615. else {
  6616. $dir = $fs->get_file_by_id($dirid);
  6617. $dir_base = $dir->get_filepath();
  6618. }
  6619. $dir_parent = $dir->get_parent_directory();
  6620. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6621. return $data[$key];
  6622. }
  6623. /// Function for create an new dir
  6624. function new_dir_ilm () {
  6625. global $USER;
  6626. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6627. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6628. $dir_base = $this->get_dir_ilm('dir_base');
  6629. $context = context_course::instance($this->id);
  6630. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6631. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6632. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6633. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6634. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6635. }
  6636. /// Function for delete an dir
  6637. function delete_dir_ilm () { //
  6638. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6639. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6640. $context = context_course::instance($this->id);
  6641. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6642. $dir_parent = $this->get_dir_ilm('dir_parent');
  6643. if ($dir) {
  6644. if ($dir->is_directory()) {
  6645. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6646. foreach ($files_delete as $value)
  6647. $value->delete();
  6648. $dir->delete();
  6649. }
  6650. }
  6651. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6652. die();
  6653. }
  6654. /// Function for rename an dir
  6655. function rename_dir_ilm () {
  6656. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6657. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6658. $context = context_course::instance($this->id);
  6659. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6660. $dir_parent = $this->get_dir_ilm('dir_parent');
  6661. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6662. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6663. if ($dir->is_directory()) {
  6664. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6665. foreach ($files_rename_path as $value)
  6666. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6667. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6668. }
  6669. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6670. die();
  6671. }
  6672. /// Function for move an dir and your content for other dir
  6673. function selected_move_ilm () {
  6674. global $PAGE, $OUTPUT, $CFG;
  6675. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6676. $context = context_course::instance($this->id);
  6677. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6678. $dirid = $this->get_dir_ilm('dirid');
  6679. $dir_base = $this->get_dir_ilm('dir_base');
  6680. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6681. $code_javascript_ilm = "
  6682. <script type='text/javascript'>
  6683. //<![CDATA[
  6684. function getRadiobutton () {
  6685. var radioButtons = document.getElementsByTagName('input');
  6686. var param = '';
  6687. for (var counter=0; counter < radioButtons.length; counter++) {
  6688. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6689. param = radioButtons[counter].value;
  6690. }
  6691. return param;
  6692. }
  6693. function move_selected_ilm () {
  6694. var msgAnswer;
  6695. if (getRadiobutton() != '') {
  6696. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6697. if (msgAnswer)
  6698. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6699. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6700. }
  6701. else
  6702. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6703. }
  6704. function cancel_selected_ilm () {
  6705. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6706. }
  6707. //]]>
  6708. </script>\n";
  6709. $title = get_string('move_files', 'iassign');
  6710. $PAGE->set_title($title);
  6711. $PAGE->set_pagelayout('base');
  6712. print $OUTPUT->header();
  6713. print $OUTPUT->heading($title);
  6714. $dir_paths = array();
  6715. print $OUTPUT->box_start();
  6716. print "<center>";
  6717. foreach ($files_id as $file_id) {
  6718. $file = $fs->get_file_by_id($file_id);
  6719. if ($file) {
  6720. if (!$file->is_directory())
  6721. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6722. else {
  6723. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6724. array_push($dir_paths, $file->get_filepath());
  6725. }
  6726. }
  6727. }
  6728. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6729. if ($dir_base != '/') {
  6730. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6731. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6732. }
  6733. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6734. foreach ($files_tree as $file) {
  6735. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6736. $is_parent = false;
  6737. foreach ($dir_paths as $dir) {
  6738. $path = explode("/", $dir);
  6739. array_pop($path);
  6740. $path[count($path) - 1] = '';
  6741. $path = implode("/", $path);
  6742. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6743. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6744. }
  6745. if ($is_parent == false) {
  6746. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6747. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6748. }
  6749. }
  6750. }
  6751. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6752. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6753. print "</center>";
  6754. print $OUTPUT->box_end();
  6755. print $OUTPUT->footer();
  6756. print $code_javascript_ilm;
  6757. die;
  6758. }
  6759. /// Function for move files for an dir
  6760. function move_files_ilm () {
  6761. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6762. $context = context_course::instance($this->id);
  6763. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6764. $dirid = $this->get_dir_ilm('dirid');
  6765. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6766. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6767. foreach ($files_id as $file_id) {
  6768. $file = $fs->get_file_by_id($file_id);
  6769. if ($file) {
  6770. if ($file->is_directory()) {
  6771. $pathname = explode("/", $file->get_filepath());
  6772. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6773. foreach ($files_move_path as $value) {
  6774. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6775. $value->rename($path_move, $value->get_filename());
  6776. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6777. }
  6778. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6779. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6780. $file->rename($path_move, $file->get_filename());
  6781. } else {
  6782. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6783. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6784. }
  6785. }
  6786. }
  6787. //die;
  6788. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6789. die();
  6790. } // function move_files_ilm()
  6791. /// Function for recover files in use on all activities of a course
  6792. function recover_files_ilm () {
  6793. global $DB, $USER;
  6794. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6795. $courseid = optional_param('id', NULL, PARAM_INT);
  6796. $dirid = $this->get_dir_ilm('dirid');
  6797. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6798. $contextfile = context_course::instance($this->id);
  6799. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6800. foreach ($iassigns as $iassign) {
  6801. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6802. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6803. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6804. $context = context_module::instance($cm->id);
  6805. // Before associtaion 'files.id' with 'iassign_statement.iassign_ilmid': $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6806. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
  6807. if ($files) {
  6808. foreach ($files as $value) {
  6809. $extension = explode(".", $value->get_filename());
  6810. if (!$value->is_directory()) {
  6811. $fileinfo = array('contextid' => $contextfile->id,
  6812. 'component' => 'mod_iassign',
  6813. 'filearea' => 'activity',
  6814. 'itemid' => 0,
  6815. 'filepath' => $this->get_dir_ilm('dir_base'),
  6816. 'userid' => $USER->id,
  6817. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6818. 'license' => 'allrightsreserved',
  6819. 'timecreated' => time(),
  6820. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6821. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6822. }
  6823. }
  6824. } // if ($files)
  6825. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6826. } // foreach ($iassigns as $iassign)
  6827. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6828. die();
  6829. } // function recover_files_ilm()
  6830. /// Auxiliary function the get all files in a given context
  6831. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6832. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6833. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6834. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6835. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6836. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6837. // (NAO s_iassign_statement.file = s_files.id)
  6838. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6839. $dir_base = $this->get_dir_ilm('dir_base');
  6840. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6841. $countf = 0;
  6842. $array_files_id = array(); // all files from this context
  6843. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6844. //$filename = $item_fc->get_filename();
  6845. //$filepath = $item_fc->get_filepath();
  6846. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6847. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6848. // $array_files_aux[] = $item_fc;
  6849. $itemid = $item_fc->get_id();
  6850. if (!in_array($itemid, $array_files_id)) {
  6851. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6852. if ($fileuserid == $userid)
  6853. $filesfrommine[] = $item_fc;
  6854. else
  6855. $filesfromothers[] = $item_fc;
  6856. $array_files_id[] = $itemid;
  6857. $countf++;
  6858. }
  6859. }
  6860. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6861. return $countf;
  6862. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6863. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6864. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6865. function get_all_ilm_files_by_fileid ($fileid) {
  6866. global $DB, $USER;
  6867. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6868. //TODO Criar coluna 'authorid'
  6869. $str_query = "SELECT * FROM {iassign_statement} WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6870. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6871. return $array_iassign_ilm;
  6872. }
  6873. //NN
  6874. //NN
  6875. // Build string with JavaScript code with function to edit/remove/double iLM files
  6876. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6877. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6878. global $CFG;
  6879. $error_files_exists = get_string('error_file_exists', 'iassign');
  6880. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6881. $code_javascript_ilm = "
  6882. <script type='text/javascript'>
  6883. //<![CDATA[
  6884. function preview_ilm (fileid, ilmid) { //JavaScript function
  6885. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6886. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6887. }
  6888. function update_ilm (ilmid, fileid) { //JavaScript function
  6889. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6890. }
  6891. function delete_ilm (ilmid, fileid) { //JavaScript function
  6892. var msgAnswer;
  6893. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6894. if (msgAnswer) {
  6895. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6896. }
  6897. }
  6898. function delete_selected_ilm () { //JavaScript function
  6899. var msgAnswer;
  6900. var param = getCheckbox();
  6901. if (param.join() != '') {
  6902. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6903. if (msgAnswer)
  6904. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6905. }
  6906. else
  6907. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6908. }
  6909. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6910. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6911. }
  6912. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6913. var filenamecopy;
  6914. var i;
  6915. var files = new Array(" . $files_array . ");
  6916. do {
  6917. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6918. } while (filenamecopy == '');
  6919. if (filenamecopy == null)
  6920. return false;\n
  6921. else {
  6922. for (i=0;i<files.length;i++) {
  6923. if (files[i]==filenamecopy) {
  6924. alert('" . $error_files_exists . "');
  6925. return false;\n
  6926. }
  6927. }\n" .
  6928. // @see: function 'duplicate_file_ilm()' above
  6929. "
  6930. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6931. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6932. } // else
  6933. }
  6934. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6935. var filenamecopy;
  6936. var i;
  6937. var files = new Array($files_array);
  6938. do {
  6939. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6940. } while (filenamecopy == '');
  6941. if (filenamecopy == null)
  6942. return false;
  6943. else {
  6944. for (i=0;i<files.length;i++) {
  6945. if (files[i]==filenamecopy) {
  6946. alert('" . $error_files_exists . "');
  6947. return false;
  6948. }
  6949. }
  6950. 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;
  6951. }
  6952. }
  6953. function export_files_ilm () { //JavaScript function
  6954. var param = getCheckbox();
  6955. if (param.join() != '')
  6956. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6957. else
  6958. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6959. }
  6960. function select_all_ilm () { //JavaScript function
  6961. var checkBoxes = document.getElementsByTagName('input');
  6962. var selectAll = document.getElementById('select_all');
  6963. for (var counter=0; counter < checkBoxes.length; counter++) {
  6964. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6965. checkBoxes[counter].checked = selectAll.checked;
  6966. }
  6967. }
  6968. function getCheckbox () { //JavaScript function
  6969. var checkBoxes = document.getElementsByTagName('input');
  6970. var param = new Array();
  6971. for (var counter=0; counter < checkBoxes.length; counter++) {
  6972. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6973. param.push(checkBoxes[counter].value);
  6974. }
  6975. return param;
  6976. }
  6977. function new_dir_ilm () { //JavaScript function
  6978. var dirname = '';
  6979. var i;
  6980. var dirs = new Array(" . $dirs_array . ");
  6981. do {
  6982. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6983. } while (dirname == '');
  6984. if (dirname == null)
  6985. return false;\n
  6986. else {
  6987. for (i=0;i<dirs.length;i++) {
  6988. if (dirs[i]==dirname) {
  6989. alert('" . $error_dir_exists . "');
  6990. return false;\n
  6991. }
  6992. }
  6993. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6994. }
  6995. }
  6996. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6997. var msgAnswer;
  6998. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6999. if (msgAnswer) {
  7000. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7001. }
  7002. }
  7003. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  7004. var dirnamecopy;
  7005. var i;
  7006. var dirs = new Array($dirs_array);
  7007. do {
  7008. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7009. } while (dirnamecopy == '');
  7010. if (dirnamecopy == null)
  7011. return false;\n
  7012. else {
  7013. for (i=0;i<dirs.length;i++) {
  7014. if (dirs[i]==dirnamecopy) {
  7015. alert('" . $error_dir_exists . "');
  7016. return false;\n
  7017. }
  7018. }
  7019. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7020. }
  7021. }
  7022. function move_selected_ilm (ilmid) { //JavaScript function
  7023. var param = getCheckbox();
  7024. if (param.join() != '')
  7025. 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();
  7026. else
  7027. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7028. }
  7029. function recover_files_ilm () { //JavaScript function
  7030. var msgAnswer;
  7031. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7032. if (msgAnswer) {
  7033. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7034. }
  7035. }
  7036. window.onload = function() { //JavaScript function
  7037. var xPosition = 0;
  7038. var yPosition = 0;
  7039. element=document.getElementById('new_file');
  7040. while(element) {
  7041. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7042. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7043. element = element.offsetParent;
  7044. }
  7045. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7046. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7047. location.hash = '#new_file';
  7048. };
  7049. //]]>
  7050. </script>\n"; // end of $code_javascript_ilm
  7051. return $code_javascript_ilm;
  7052. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  7053. /// List iassign files from course directory
  7054. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  7055. function view_files_ilm ($iassign_ilm_class, $extension) {
  7056. global $CFG, $DB, $USER, $OUTPUT;
  7057. $fs = get_file_storage();
  7058. $context = context_course::instance($this->id);
  7059. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  7060. $dirid = $this->get_dir_ilm('dirid');
  7061. $dir_base = $this->get_dir_ilm('dir_base');
  7062. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  7063. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  7064. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  7065. $files_array = '';
  7066. foreach ($files_course as $value) {
  7067. if (!$value->is_directory())
  7068. $files_array .= "'" . $value->get_filename() . "',";
  7069. }
  7070. $files_array .= "''";
  7071. $error_files_exists = get_string('error_file_exists', 'iassign');
  7072. $dirs_array = '';
  7073. foreach ($files_course as $value) {
  7074. if ($value->is_directory()) {
  7075. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  7076. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  7077. }
  7078. }
  7079. $dirs_array .= "''";
  7080. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  7081. //TODO: Rever o 'preview', pois so' apresenta uma vez!
  7082. $code_javascript_ilm = "
  7083. <script type='text/javascript'>
  7084. //<![CDATA[
  7085. function preview_ilm (fileid, ilmid) {
  7086. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  7087. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  7088. }
  7089. function update_ilm (ilmid, fileid) {
  7090. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7091. }
  7092. function delete_ilm (ilmid, fileid) {
  7093. var msgAnswer;
  7094. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  7095. if (msgAnswer) {
  7096. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7097. }
  7098. }
  7099. function delete_selected_ilm () {
  7100. var msgAnswer;
  7101. var param = getCheckbox();
  7102. if (param.join() != '') {
  7103. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  7104. if (msgAnswer)
  7105. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  7106. }
  7107. else
  7108. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  7109. }
  7110. function add_ilm_iassign (ilmid, filename, fileid) {
  7111. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  7112. }
  7113. function duplicate_ilm (ilmid, filename, fileid) {
  7114. var filenamecopy;
  7115. var i;
  7116. var files = new Array($files_array);
  7117. do {
  7118. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  7119. } while (filenamecopy == '');
  7120. if (filenamecopy == null)
  7121. return false;\n
  7122. else {
  7123. for (i=0;i<files.length;i++) {
  7124. if (files[i]==filenamecopy) {
  7125. alert('$error_files_exists');
  7126. return false;\n
  7127. }
  7128. }\n" .
  7129. // @see: function 'duplicate_file_ilm()' above
  7130. "
  7131. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  7132. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  7133. } // else
  7134. }
  7135. function rename_ilm (ilmid, filename, fileid) {
  7136. var filenamecopy;
  7137. var i;
  7138. var files = new Array($files_array);
  7139. do {
  7140. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  7141. } while (filenamecopy == '');
  7142. if (filenamecopy == null)
  7143. return false;
  7144. else {
  7145. for (i=0;i<files.length;i++) {
  7146. if (files[i]==filenamecopy) {
  7147. alert('$error_files_exists');
  7148. return false;
  7149. }
  7150. }
  7151. 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;
  7152. }
  7153. }
  7154. function export_files_ilm () {
  7155. var param = getCheckbox();
  7156. if (param.join() != '')
  7157. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  7158. else
  7159. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  7160. }
  7161. function select_all_ilm () {
  7162. var checkBoxes = document.getElementsByTagName('input');
  7163. var selectAll = document.getElementById('select_all');
  7164. for (var counter=0; counter < checkBoxes.length; counter++) {
  7165. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  7166. checkBoxes[counter].checked = selectAll.checked;
  7167. }
  7168. }
  7169. function getCheckbox () {
  7170. var checkBoxes = document.getElementsByTagName('input');
  7171. var param = new Array();
  7172. for (var counter=0; counter < checkBoxes.length; counter++) {
  7173. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  7174. param.push(checkBoxes[counter].value);
  7175. }
  7176. return param;
  7177. }
  7178. function new_dir_ilm () {
  7179. var dirname = '';
  7180. var i;
  7181. var dirs = new Array($dirs_array);
  7182. do {
  7183. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  7184. } while (dirname == '');
  7185. if (dirname == null)
  7186. return false;\n
  7187. else {
  7188. for (i=0;i<dirs.length;i++) {
  7189. if (dirs[i]==dirname) {
  7190. alert('$error_dir_exists');
  7191. return false;\n
  7192. }
  7193. }
  7194. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  7195. }
  7196. }
  7197. function delete_dir_ilm (ilmid, dirid) {
  7198. var msgAnswer;
  7199. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7200. if (msgAnswer) {
  7201. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7202. }
  7203. }
  7204. function rename_dir_ilm (ilmid, dirname, dirid) {
  7205. var dirnamecopy;
  7206. var i;
  7207. var dirs = new Array($dirs_array);
  7208. do {
  7209. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7210. } while (dirnamecopy == '');
  7211. if (dirnamecopy == null)
  7212. return false;\n
  7213. else {
  7214. for (i=0;i<dirs.length;i++) {
  7215. if (dirs[i]==dirnamecopy) {
  7216. alert('$error_dir_exists');
  7217. return false;\n
  7218. }
  7219. }
  7220. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7221. }
  7222. }
  7223. function move_selected_ilm (ilmid) {
  7224. var param = getCheckbox();
  7225. if (param.join() != '')
  7226. 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();
  7227. else
  7228. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7229. }
  7230. function recover_files_ilm () {
  7231. var msgAnswer;
  7232. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7233. if (msgAnswer) {
  7234. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7235. }
  7236. }
  7237. window.onload = function() {
  7238. var xPosition = 0;
  7239. var yPosition = 0;
  7240. element=document.getElementById('new_file');
  7241. while(element) {
  7242. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7243. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7244. element = element.offsetParent;
  7245. }
  7246. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7247. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7248. location.hash = '#new_file';
  7249. };
  7250. //]]>
  7251. </script>\n";
  7252. $output = "";
  7253. $select_all = "";
  7254. $count_files = 0;
  7255. $extensions_allow = array();
  7256. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  7257. foreach ($iassign_ilm as $item_iassign_ilm)
  7258. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  7259. foreach ($files_course as $value) {
  7260. $filename = $value->get_filename();
  7261. $filepath = $value->get_filepath();
  7262. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  7263. $pathname = $pathname[count($pathname) - 1];
  7264. $fileid = $value->get_id();
  7265. $tmp = explode(".", $filename);
  7266. if (count($tmp)>1) // avoid error if the file has no extension
  7267. $filetype = $tmp[1];
  7268. else // probably error...
  7269. $filetype = '';
  7270. $author = $value->get_author();
  7271. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  7272. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  7273. $extensions = explode(",", $extension);
  7274. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  7275. $count_files++;
  7276. // buscar fileid nas tabelas do iassign
  7277. $list_filein_use = "";
  7278. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  7279. if ($iassign_statement_activity_list) {
  7280. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  7281. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  7282. }
  7283. }
  7284. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  7285. if (!$iassign_ilm) {
  7286. $iassign_ilm = new stdClass();
  7287. $iassign_ilm->id = $ilmid;
  7288. }
  7289. // Do not use $var inside "..." - problem with some "unusual" operational system
  7290. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  7291. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  7292. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  7293. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  7294. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7295. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7296. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7297. $check_select = "";
  7298. $link_rename = "";
  7299. $link_delete = "";
  7300. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7301. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7302. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7303. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  7304. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7305. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7306. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7307. if ($value->get_userid() == $USER->id) {
  7308. if ($iassign_statement_activity_list) {
  7309. $check_select = "";
  7310. $link_edit = iassign_icons::insert('edit_iassign_disable');
  7311. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  7312. $link_rename = "";
  7313. } else {
  7314. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  7315. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  7316. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  7317. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  7318. }
  7319. }
  7320. if (!in_array($filetype, $extensions_allow)) {
  7321. $link_edit = "";
  7322. $link_add_ilm_iassign = "";
  7323. $link_add_ilm_tinymce = "";
  7324. $link_add_ilm_atto = "";
  7325. $link_filter = "";
  7326. }
  7327. if ($value->is_directory()) {
  7328. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  7329. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  7330. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  7331. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  7332. <td><center>$author</center></td>
  7333. <td><center>$timecreated</center></td>
  7334. <td><center>$timemodified</center></td></tr>\n";
  7335. }
  7336. else if ($this->from == 'iassign') {
  7337. $new_id = "";
  7338. $new_class = "";
  7339. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  7340. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  7341. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  7342. }
  7343. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  7344. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7345. <td><center>$author</center></td>
  7346. <td><center>$timecreated</center></td>
  7347. <td><center>$timemodified</center></td></tr>\n";
  7348. }
  7349. else if ($this->from == 'block') {
  7350. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  7351. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7352. <td><center>$author</center></td>
  7353. <td><center>$timecreated</center></td>
  7354. <td><center>$timemodified</center></td></tr>\n";
  7355. }
  7356. else if ($this->from == 'tinymce') {
  7357. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  7358. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7359. <td><center>$author</center></td>
  7360. <td><center>$timecreated</center></td>
  7361. <td><center>$timemodified</center></td></tr>\n";
  7362. }
  7363. else if ($this->from == 'atto') {
  7364. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  7365. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7366. <td><center>$author</center></td>
  7367. <td><center>$timecreated</center></td>
  7368. <td><center>$timemodified</center></td></tr>\n";
  7369. }
  7370. }
  7371. }
  7372. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  7373. $dir_base = "";
  7374. $header = "";
  7375. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  7376. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  7377. foreach ($basename as $value) {
  7378. $dir_base .= $value . "/";
  7379. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  7380. if ($dir_id) {
  7381. if ($value == "") {
  7382. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7383. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  7384. } else {
  7385. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7386. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  7387. }
  7388. }
  7389. } // foreach ($basename as $value)
  7390. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  7391. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  7392. $html .= "
  7393. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  7394. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  7395. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  7396. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  7397. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  7398. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  7399. </table>\n";
  7400. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  7401. $html .= "<table width='100%'><tr>\n";
  7402. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  7403. if ($count_files != 0) {
  7404. $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";
  7405. $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";
  7406. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  7407. }
  7408. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  7409. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  7410. $html .= "</form>\n";
  7411. print $code_javascript_ilm;
  7412. print $html;
  7413. } // function view_files_ilm($extension)
  7414. } // class ilm_manager
  7415. /// Class to insert of icons
  7416. class iassign_icons {
  7417. static function insert ($icon) {
  7418. global $CFG;
  7419. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  7420. return $string;
  7421. }
  7422. }
  7423. /// Class with util functions for plugin manage
  7424. class iassign_utils {
  7425. /// Function to return the filename extension
  7426. // @param string The $filename as an string
  7427. // @return string Return an string (last group after '.')
  7428. static function filename_extension ($filename) {
  7429. if ($filename == null || $filename == '') {
  7430. return null;
  7431. }
  7432. $itens = explode('.', $filename);
  7433. $num = count($itens);
  7434. if ($num < 2) {
  7435. return null;
  7436. }
  7437. return $itens[$num - 1];
  7438. }
  7439. /// Use the PHP class/package ZipArchive to create a Zip file
  7440. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  7441. // 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
  7442. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  7443. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  7444. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7445. $zip = new zip_archive(); //2
  7446. $res = $zip->open($full_path_zip_filename);
  7447. $total_vet = count($vet_student_filename);
  7448. for ($ii=0; $ii<$total_vet; $ii++) {
  7449. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7450. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7451. }
  7452. $ret = $zip->close();
  7453. iassign_utils::download_file($full_path_zip_filename);
  7454. $filenameZip = $zip->filename;
  7455. return array($ret, $zip);
  7456. }
  7457. static function download_file ($zip_filename) {
  7458. header("Pragma: public");
  7459. header("Expires: 0");
  7460. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7461. header("Cache-Control: private", false);
  7462. header("Content-Type: application/zip");
  7463. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7464. header("Content-Transfer-Encoding: binary");
  7465. header("Content-Length: " . @filesize($zip_filename));
  7466. set_time_limit(0);
  7467. @readfile("$zip_filename") || die("File not found.");
  7468. unlink($zip_filename);
  7469. }
  7470. /// Function for format filename remove special caracters
  7471. // @param string $text String for clean
  7472. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7473. // @return string Return an string in clean format
  7474. static function format_filename ($text) {
  7475. if ($text != '.') {
  7476. //D $text = htmlspecialchars(urldecode($text));
  7477. //D echo "locallib.php: format_filename: $text<br/>";
  7478. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7479. $text = json_decode($text)->{current_language()};
  7480. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7481. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7482. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7483. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7484. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7485. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7486. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7487. // E.g. text = "exerc_midpoint.course.geo"
  7488. // 0123456789012345678901234
  7489. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7490. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7491. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7492. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7493. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7494. //$ext = strrpos($text, ".");
  7495. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7496. //$text = str_replace($array1, $array2, $text);
  7497. }
  7498. return $text;
  7499. }
  7500. /// Function to filter characters to the file name to iLM content
  7501. // @param string $text String for clean
  7502. // @param string $ext String ot the extension of the iLM
  7503. // @return string Return an string in clean format
  7504. static function filter_filename_extension ($filename, $ext) {
  7505. if ($filename != '.') {
  7506. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7507. $arrTo = array("_","","","","","","","","","","","","");
  7508. $filename = str_replace($arrFrom, $arrTo, $filename);
  7509. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7510. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7511. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7512. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7513. $index_lastposition = strlen($filenameF);
  7514. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7515. $text = str_replace(".", "_", $text); // erase all other "."
  7516. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7517. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7518. }
  7519. else
  7520. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7521. return $filenameF;
  7522. }
  7523. /// Function for format pathname remove special caracters
  7524. // @param string $text String for clean
  7525. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7526. // @return string Return an string in clean format
  7527. static function format_pathname ($text, $is_lowercase = true) {
  7528. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7529. $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", "-", "_", "", "", "");
  7530. $text = str_replace($array1, $array2, $text);
  7531. if ($is_lowercase)
  7532. $text = strtolower($text);
  7533. return $text;
  7534. }
  7535. /// Function for format file name from iLM original name
  7536. // @param string $text String to build the file neam
  7537. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7538. // @return string Return an string in clean format
  7539. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7540. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7541. $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", "-", "_", "", "", "");
  7542. $index_firstposition_blank = strpos($ilm_name, " ");
  7543. if ($index_firstposition_blank) { // truncate the name!
  7544. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7545. }
  7546. $index_firstposition_dots = strpos($ilm_name, ":");
  7547. if ($index_firstposition_dots) { // truncate the name!
  7548. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7549. }
  7550. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7551. if ($is_lowercase)
  7552. $namefiltered = strtolower($namefiltered);
  7553. return $namefiltered;
  7554. }
  7555. /// Function for insert version in the filename
  7556. // @param string $filename Name of file
  7557. // @return string Return the filename with version
  7558. static function version_filename ($filename) {
  7559. $array_filename = explode('.', $filename);
  7560. if (count($array_filename) > 1)
  7561. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7562. else
  7563. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7564. return $filename;
  7565. }
  7566. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7567. static function remove_code_message ($string) {
  7568. $array = explode("&lt;ia_uc&gt;", $string);
  7569. return $array[0];
  7570. }
  7571. }
  7572. // class iassign_utils
  7573. /// Class with language functions for plugin manage
  7574. class iassign_language {
  7575. /// Function for return text in language or get default language (en)
  7576. // @param string $lang Code of language
  7577. // @param string $description JSON text content all languages
  7578. // @return string Return an string in the language selected
  7579. static function get_description_lang ($lang, $descriptions) {
  7580. $description_lang = "";
  7581. $description = json_decode($descriptions);
  7582. if ($description == null) {
  7583. $description_lang = $descriptions;
  7584. }
  7585. else {
  7586. if (isset($description->{$lang}))
  7587. $description_lang = $description->{$lang};
  7588. else
  7589. if (isset($description->en)) //MOOC2014
  7590. $description_lang = $description->en;
  7591. else //MOOC2014
  7592. $description_lang = "en"; //MOOC2014
  7593. }
  7594. return $description_lang;
  7595. }
  7596. /// Function for return all language supported by iLM
  7597. // @param string $descriptions JSON text content all languages
  7598. // @return string Return as string with all languages
  7599. static function get_all_lang ($descriptions) {
  7600. $langs = "";
  7601. $description = json_decode($descriptions);
  7602. if ($description) {
  7603. foreach ($description as $key => $value) {
  7604. $langs .= $key . " ; ";
  7605. }
  7606. $langs = substr($langs, 0, strlen($langs) - 3);
  7607. }
  7608. return $langs;
  7609. }
  7610. /// Function for convert json in xml //MOOC2014
  7611. // @param string $json JSON text
  7612. // @return string Return as string with xml tags
  7613. static function json_to_xml ($json) {
  7614. $xml = "";
  7615. $json = json_decode($json);
  7616. foreach ($json as $key => $value) {
  7617. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7618. }
  7619. return $xml;
  7620. }
  7621. }
  7622. // class iassign_language
  7623. /// Class with log functions for plugin manage.
  7624. class iassign_log {
  7625. /// Function for insert log event
  7626. // @param string $action Code action of event
  7627. // @param string $information Text for describe action of event
  7628. // @param int $cmid Id of context module
  7629. // @param int $ilmid Id of iLM
  7630. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7631. global $COURSE, $CFG, $USER, $DB;
  7632. $newentry = new stdClass();
  7633. $newentry->time = time();
  7634. $newentry->userid = $USER->id;
  7635. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7636. $newentry->course = $COURSE->id;
  7637. $newentry->cmid = $cmid;
  7638. $newentry->ilmid = $ilmid;
  7639. $newentry->action = $action;
  7640. $newentry->info = $information;
  7641. $newentry->language = current_language();
  7642. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7643. if (ini_get("browscap") && function_exists('get_browse')) {
  7644. $browser = get_browse(null, true);
  7645. $newentry->javascript = $browser['javascript'];
  7646. $newentry->java = $browser['javaapplets'];
  7647. }
  7648. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7649. print_error('error_add_log', 'iassign');
  7650. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7651. } // class iassign_log