locallib.php 359 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.4 2020/05/28
  7. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  8. *
  9. * - v 4.9.3 2020/01/16
  10. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  11. *
  12. * - v 4.9.2 2019/03/13
  13. * + Several fixes to allow iLM under HTML stack
  14. *
  15. * - v 4.9.1 2017/11/02
  16. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  17. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  18. *
  19. * - v 4.9 2017/03/13
  20. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  21. *
  22. * - v 4.8 2016/05/12
  23. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  24. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  25. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  26. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  27. * replaced by
  28. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  29. * - v 4.7 2016/02/17
  30. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  31. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  32. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  33. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  34. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  35. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  36. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  37. *
  38. * --------------- (code bellow was used at our MOOC 2014)
  39. * - v 4.6 2014/02/25
  40. * + Fix bugs in filter function for open applets.
  41. * - v 4.5 2014/02/24
  42. * + Fix bugs in params.
  43. * + Insert new param type.
  44. * - v 4.4 2014/01/24
  45. * + Allow select type of params.
  46. * + Insert the use of applet params specific for activities.
  47. * - v 4.3 2014/01/23
  48. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  49. * - v 4.2 2016/02/13
  50. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  51. * --------------- (above code used at our MOOC 2014)
  52. *
  53. * - v 4.1 2013/12/13
  54. * + Insert log in iAssign actions.
  55. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  56. * + Insert class for Log actions in system.
  57. * - v 4.0 2013/10/31
  58. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  59. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  60. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  61. * - v 3.9 2013/10/25
  62. * + Insert support of upgrade iLM.
  63. * + Insert support for more than one extension in iLM.
  64. * + Fix bugs in verion control.
  65. * - v 3.8 2013/09/19
  66. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  67. * - v 3.7 2013/09/12
  68. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  69. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  70. * - v 3.6 2013/09/05
  71. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  72. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  73. * + Change tag APPLET in function ilm_settings::view_ilm.
  74. * - v 3.5 2013/08/26
  75. * + Fix bug in download package iassign without answers (iassign::report).
  76. * - v 3.4 2013/08/23
  77. * + Fix bug in export package iassign.
  78. * - v 3.3 2013/08/22
  79. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  80. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  81. * - v 3.2 2013/08/21
  82. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  83. * + Change functions for import files for ilm_manager.php.
  84. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  85. * - v 3.1 2013/08/15
  86. * + Change return file selected (ilm_manager::add_ilm).
  87. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  88. * - v 3.0 2013/08/02
  89. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  90. * - v 2.9 2013/08/01
  91. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  92. * - v 2.8 2013/07/25
  93. * + Insert the activity name in header of view (activity::view_dates).
  94. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  95. * - v 2.7 2013/07/24
  96. * + Create link previous and next for student view in one activity (activity::view_dates).
  97. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  98. * - v 2.6 2013/07/23
  99. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  100. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  101. * - v 2.5 2013/07/12
  102. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  103. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  104. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  105. *
  106. * @author Patricia Alves Rodrigues
  107. * @author Leônidas O. Brandão
  108. * @contributor Igor Moreira Félix (2018-)
  109. * @contributor Márcio de Lima Passos (2014)
  110. * @version v 4.9.2 2019/03/13
  111. * @version v 4.8 2016/05/12
  112. * @package mod_iassign_lib
  113. * @since 2010/09/27
  114. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  115. *
  116. * <b>License</b>
  117. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  118. */
  119. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  120. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  121. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  122. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  123. /**
  124. * Standard base class for all iAssign
  125. */
  126. class iassign {
  127. var $cm;
  128. var $course;
  129. var $iassign;
  130. var $striassign;
  131. var $striassigns;
  132. var $context;
  133. var $activity;
  134. var $iassign_up;
  135. var $iassign_down;
  136. var $action;
  137. var $iassign_submission_current;
  138. var $userid_iassign;
  139. var $bottonPost;
  140. var $write_solution;
  141. var $view_iassign;
  142. // 3.1 update PHP 7.0 compatibility for all moodle versions
  143. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  144. /// Constructor for the base iassign class
  145. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  146. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  147. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  148. function __construct ($iassign, $cm, $course) {
  149. global $COURSE, $CFG, $USER, $DB;
  150. $botton = optional_param('botton', NULL, PARAM_TEXT);
  151. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  152. if (!is_null($botton))
  153. $USER->iassignEdit = $botton;
  154. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  155. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  156. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  157. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  158. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  159. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  160. $this->action = optional_param('action', NULL, PARAM_TEXT);
  161. $this->cm = $cm;
  162. $this->context = context_module::instance($this->cm->id);
  163. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  164. $this->userid_iassign = $USER->id;
  165. if ($course) {
  166. $this->course = $course;
  167. }
  168. else if ($this->cm->course == $COURSE->id) {
  169. $this->course = $COURSE;
  170. }
  171. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  172. print_error('invalidid', 'iassign');
  173. }
  174. $this->coursecontext = context_course::instance($this->course->id);
  175. if ($iassign) {
  176. $this->iassign = $iassign;
  177. }
  178. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  179. print_error('invalidid', 'iassign');
  180. }
  181. $USER->context = context_module::instance($this->cm->id);
  182. $USER->cm = $this->cm->id;
  183. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  184. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  185. $this->context = context_module::instance($this->cm->id);
  186. $this->striassign = get_string('modulename', 'iassign');
  187. $this->striassigns = get_string('modulenameplural', 'iassign');
  188. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  189. $this->bottonPost = 0;
  190. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  191. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  192. $this->view();
  193. } // function __construct($iassign, $cm, $course)
  194. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  195. // This method provides the page to view each iLM with any interactive activity
  196. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  197. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  198. global $USER, $DB, $OUTPUT;
  199. // $iassign_statementid = $this->iassign->iassign_statementid;
  200. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  201. $iassign_statementid = $this->activity->get_activity()->id;
  202. else
  203. $iassign_statementid = "";
  204. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  205. // If this user has no capability to View 'iassign': stop here
  206. require_capability('mod/iassign:view', $this->context);
  207. // Trigger module view event
  208. $event = \mod_iassign\event\course_module_viewed::create(array(
  209. 'objectid' => $this->iassign->id,
  210. 'context' => $this->context
  211. ));
  212. $event->add_record_snapshot('course', $this->course);
  213. $event->trigger();
  214. if ($this->action) { // when student do/redo activity or teacher see student solution
  215. $this->action(); // calls '$this->view_iLM();'
  216. }
  217. else {
  218. print $OUTPUT->header();
  219. $this->view_iassigns(); // show the iLM with the content
  220. print $OUTPUT->footer();
  221. }
  222. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  223. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  226. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  229. //D else echo "Apagou!<br/>";
  230. die();
  231. } // function view()
  232. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  233. function action () {
  234. global $USER;
  235. // action:
  236. // up - move up activity (mover atividade para cima)
  237. // down - move down activity (mover atividade para baixo)
  238. // visible - view/hide activity (exibir/ocultar atividade)
  239. // delete - delete activity (excluir atividade)
  240. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  241. // deleteno - does not erase activity (não apaga atividade)
  242. // add - add activity (adicionar atividade)
  243. // edit - edit activity (modificar atividade)
  244. $action_iassign = array(
  245. 'newcomment' => '$this->get_answer();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();');
  253. $action_iassign_limit = array(
  254. 'view' => '$this->view_iassign_current();',
  255. 'newcomment' => '$this->get_answer();',
  256. 'viewsubmission' => '$this->view_iassign_current();',
  257. 'edit_status' => '$this->edit_status();',
  258. 'edit_grade' => '$this->edit_grade();',
  259. 'export_csv' => '$this->export_csv();',
  260. 'report' => '$this->report();',
  261. 'print' => '$this->report();',
  262. 'stats' => '$this->stats();',
  263. 'printstats' => '$this->stats();');
  264. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  265. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  266. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  267. 'visible' => '$this->activity->visible_iassign($this->return);',
  268. 'delete' => '$this->activity->delete($this->return);',
  269. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  270. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  271. 'add' => '$this->add_edit_iassign();',
  272. 'edit' => '$this->add_edit_iassign();',
  273. 'get_answer' => '$this->get_answer();',
  274. 'duplicate_activity' => '$this->duplicate_activity();',
  275. 'move_activity' => '$this->move_activity();',
  276. 'auto_evaluate' => '$this->auto_evaluate();',
  277. 'get_student_submission' => '$this->get_student_submission();',
  278. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  279. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  280. );
  281. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  282. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  283. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  284. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  285. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  286. }
  287. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  288. eval($action_iassign_limit[$this->action]);
  289. }
  290. else { // Student reaches this point
  291. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  292. // Arrive here with: "get_answer"; "view"
  293. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  294. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  295. }
  296. } // function action()
  297. /// This method prints the student submission to a specific exercise
  298. function get_student_submission () {
  299. global $DB;
  300. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  301. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  302. if (!$student || !$exercise) exit;
  303. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  304. if ($iassign_submission)
  305. print($iassign_submission->answer);
  306. die();
  307. }
  308. /// This method prints the teacher exercise
  309. function get_teacher_exercise () {
  310. global $DB, $COURSE;
  311. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  312. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  313. $fs = get_file_storage(); // Get reference to all files in Moodle data
  314. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  315. foreach ($files as $file) {
  316. if ($file->get_filename() != ".") {
  317. print($file->get_content());
  318. }
  319. }
  320. die();
  321. }
  322. /// This method receives the data from auto_eval event
  323. /// @see auto_evaluate()
  324. function post_auto_eval_result () {
  325. global $COURSE, $CFG, $USER, $DB;
  326. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  327. exit;
  328. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  329. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  330. $student = optional_param('student', -1, PARAM_INT);
  331. $grade = optional_param('grade', 0, PARAM_FLOAT);
  332. // 1: Recuperar a nota atual:
  333. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  334. // 2: Atualizar a tabela:
  335. $update_entry = new stdClass();
  336. $update_entry->id = $actual->id;
  337. $update_entry->previous_grade = $actual->grade;
  338. $update_entry->grade = $grade;
  339. // Update the iassign_submission
  340. $DB->update_record("iassign_submission", $update_entry);
  341. }
  342. /// This method runs activities auto evaluation in teacher area
  343. function auto_evaluate () {
  344. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  345. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  346. exit;
  347. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  348. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  349. // Get list of exercises in the instance:
  350. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  351. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  352. // Get list of enrolled students:
  353. $params = array('shortname' => 'student');
  354. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  355. $context = context_course::instance($this->course->id);
  356. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  357. $students_list = $DB->get_records_sql(
  358. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  359. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  360. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  361. print $OUTPUT->header();
  362. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  363. print '<ul style="list-style-type: none; margin: 1em;">';
  364. foreach ($exercises_list as $exercise) {
  365. $matches = [];
  366. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  367. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  368. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  369. if ($matches[0][0]) {
  370. 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>';
  371. } else {
  372. 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>';
  373. }
  374. } else {
  375. if ($matches[0][0]) {
  376. 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>';
  377. } else {
  378. 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>';
  379. }
  380. }
  381. }
  382. print '</ul>
  383. <center>
  384. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  385. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  386. <div id="evaluate_message" style="color: red"></div>
  387. <div id="evaluate_alerts"></div>
  388. <div>
  389. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  390. <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>
  391. </div>
  392. </center>'; // close "
  393. print ' </div>' + "\n";
  394. print ' <script>';
  395. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  396. print ' var submissions = [';
  397. // Get list of student id have submit for each exercise:
  398. foreach ($exercises_list as $exercise) {
  399. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  400. print '
  401. {
  402. "exerciseid": "' . $exercise->id . '",
  403. "grade": ' . $exercise->grade . ',
  404. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  405. "submited": ['; // "
  406. $params = array('iassign_statementid' => $exercise->id);
  407. $submited = $DB->get_records_sql( // Get userid and his grade
  408. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  409. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  410. foreach ($submited as $ss) {
  411. print($ss->userid . ',');
  412. }
  413. print '],';
  414. print '"allgrades": [';
  415. foreach ($submited as $ss) {
  416. print( $ss->grade . ',');
  417. }
  418. print ']
  419. },'; // close "
  420. } // foreach ($exercises_list as $exercise)
  421. print " ];\n";
  422. print '
  423. var total_submissions = 0;
  424. var selected_exercises;
  425. var count_steps;
  426. var value_by_step;
  427. var stoped = false;
  428. var time_interval = 5000;
  429. var var_interval;
  430. function add_hover_th (id_th, id_li) {
  431. $("#" + id_th).hover(function() {
  432. $("#" + id_li).css("background-color", "#d9d8d8");
  433. $(this).css("background-color", "#d9d8d8");
  434. }, function() {
  435. $("#" + id_li).css("background-color", "");
  436. $(this).css("background-color", "");
  437. });
  438. }
  439. function start_evaluation () {
  440. stoped = false;
  441. $("#progress_bar").css("display", "none");
  442. $("#evaluate_message").text("");
  443. $("#evaluate_alerts").text("");
  444. $(".added-col").remove();
  445. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  446. selected_exercises = [];
  447. var c = 0;
  448. for (var i = 0; i < exercises.length; i++) {
  449. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  450. selected_exercises[c++] = exercises[i];
  451. }
  452. }
  453. if (selected_exercises.length == 0) {
  454. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  455. return;
  456. } else {
  457. $("input:checkbox").attr("disabled", true);
  458. for (var i = 0; i < selected_exercises.length; i++) {
  459. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  460. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  461. $("#table-results tbody tr").each(function(e) {
  462. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  463. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  464. });
  465. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  466. }
  467. $("#button_start").prop("disabled", true);
  468. $("#button_stop").prop("disabled", false);
  469. $("#progress_bar").css("display", "block");
  470. }
  471. total_submissions = selected_exercises.length * students.length;
  472. count_steps = 0;
  473. value_by_step = 100/total_submissions;
  474. actual_exercise = 0;
  475. actual_student = 0;
  476. actual_submission = 0;
  477. get_original_propositions();
  478. var_interval = setInterval(verifyBreak, time_interval);
  479. } // function start_evaluation()
  480. var actual_exercise;
  481. var actual_student;
  482. var actual_submission;
  483. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  484. function run_individual_evaluation () {
  485. if (stoped) return;
  486. // Verify if student really sent his answer
  487. var found = false;
  488. for (var j = 0; j < submissions.length; j++) {
  489. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  490. for (var k = 0; k < submissions[j].submited.length; k++) {
  491. if (students[actual_student] == submissions[j].submited[k]) {
  492. found = true;
  493. break;
  494. }
  495. }
  496. break;
  497. }
  498. }
  499. if (found == false) {
  500. postResultAutoEval();
  501. } else {
  502. // If it was sent, search it...
  503. var final_url = "";
  504. 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];
  505. for (var j = 0; j < submissions.length; j++) {
  506. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  507. final_url = submissions[j].ilm;
  508. break;
  509. }
  510. }
  511. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  512. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  513. window.frames["ifrm"].location=final_url;
  514. }
  515. } // function run_individual_evaluation()
  516. var break_student = -1;
  517. var break_exercise = -1;
  518. function verifyBreak () {
  519. if (actual_student == break_student && actual_exercise == break_exercise) {
  520. postResultAutoEval(-6);
  521. break_student = -1;
  522. break_exercise = -1;
  523. return;
  524. } else {
  525. break_student = actual_student;
  526. break_exercise = actual_exercise;
  527. }
  528. }
  529. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  530. function getStudentAnswerURL () {
  531. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  532. }
  533. // This function is called by the iLM!!!
  534. function getAutoEvalOriginalData () {
  535. return original_propositions[actual_exercise];
  536. }
  537. function updateProgressBar () {
  538. if (stoped) return;
  539. var temp = (count_steps * value_by_step)|0;
  540. count_steps ++;
  541. temp = temp > 100 ? 100 : temp;
  542. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  543. if (temp >= 100) {
  544. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  545. $("#button_start").prop("disabled", false);
  546. $("#button_stop").prop("disabled", true);
  547. $("input:checkbox").attr("disabled", false);
  548. clearInterval(var_interval);
  549. }
  550. }
  551. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  552. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  553. function postResultAutoEval (grade = null) {
  554. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  555. if (grade == null) {
  556. $("#"+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>\');
  557. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  558. } else {
  559. // Verify if the re-evaluation grade is the of that one registered:
  560. var actual_value = 0;
  561. var actual_student_grade = 0;
  562. for (var k = 0; k < submissions.length; k++) {
  563. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  564. actual_value = submissions[k].grade;
  565. for (var h = 0; h < submissions[k].submited.length; h++) {
  566. if (submissions[k].submited[h] == students[actual_student]) {
  567. actual_student_grade = submissions[k].allgrades[h];
  568. break;
  569. }
  570. }
  571. break;
  572. }
  573. }
  574. // @FeedbackConvention
  575. if (grade < 0) {
  576. switch (grade) {
  577. case -1:
  578. // Test-cases are empty:
  579. $("#"+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>\');
  580. var mm = actual_exercise;
  581. $("#"+id_t).find(".details-button").click(function(e) {
  582. $(".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>\');
  583. });
  584. break;
  585. case -2:
  586. // Test-cases were manually altered by the student (fraud!):
  587. $("#"+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>\');
  588. var mm = actual_exercise;
  589. $("#"+id_t).find(".details-button").click(function(e) {
  590. $(".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>");
  591. });
  592. $.ajax({
  593. dataType: "html",
  594. 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",
  595. success: function(d) {}
  596. });
  597. break;
  598. case -5:
  599. // Execution failed:
  600. $("#"+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>\');
  601. var mm = actual_exercise;
  602. $("#"+id_t).find(".details-button").click(function(e) {
  603. $(".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>\');
  604. });
  605. break;
  606. case -6: // iLM not answering was detected in "verifyBreak()"
  607. // The iLM are not answering:
  608. $("#"+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>\');
  609. $("#"+id_t).find(".details-button").click(function(e) {
  610. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  611. });
  612. break;
  613. }
  614. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  615. } else {
  616. console.log((grade), (actual_student_grade));
  617. if ((grade) == (actual_student_grade)) {
  618. $("#"+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>\');
  619. } else { // Notas diferem:
  620. $("#"+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>\');
  621. var mm = actual_exercise;
  622. $("#"+id_t).find(".details-button").click(function(e) {
  623. $(".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>\');
  624. });
  625. // Send to the endpoint the post_auto_eval_result to verify:
  626. $.ajax({
  627. dataType: "html",
  628. 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),
  629. success: function(d) {}
  630. });
  631. }
  632. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  633. }
  634. }
  635. updateProgressBar();
  636. // Does it must continue in the same exercise or stop?
  637. if (actual_student < students.length) {
  638. actual_student ++;
  639. run_individual_evaluation();
  640. } else {
  641. actual_student = 0;
  642. // Does it go to next exercise or is it finished?
  643. if (actual_exercise < selected_exercises.length) {
  644. actual_exercise++;
  645. run_individual_evaluation();
  646. } else {
  647. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  648. }
  649. }
  650. }
  651. var original_propositions;
  652. function get_original_propositions () {
  653. original_propositions = [];
  654. var count = 0;
  655. for (var i = 0; i < exercises.length; i++) {
  656. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  657. $.ajax({
  658. dataType: "html",
  659. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  660. success: function(d) { // variable "d" has the iLM content
  661. original_propositions[count] = d; // exercise original content
  662. count ++;
  663. if (count == selected_exercises.length) {
  664. run_individual_evaluation();
  665. }
  666. }
  667. });
  668. }
  669. }
  670. }
  671. function stop_evaluation () {
  672. stoped = true;
  673. $("#button_start").prop("disabled", false);
  674. $("#button_stop").prop("disabled", true);
  675. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  676. $("input:checkbox").attr("disabled", false);
  677. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  678. clearInterval(var_interval);
  679. }
  680. var exercises = [ '; // '
  681. foreach ($exercises_list as $exercise) {
  682. print $exercise->id . ',';
  683. }
  684. print ' ];';
  685. print ' var students = [ ';
  686. foreach ($students_list as $student) {
  687. print $student->userid . ',';
  688. }
  689. print '];';
  690. print ' var ilms = [';
  691. foreach ($exercises_list as $exercise) {
  692. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  693. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  694. }
  695. print ']';
  696. print '</script>';
  697. print '
  698. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  699. <div class="modal-dialog modal-dialog-centered" role="document">
  700. <div class="modal-content">
  701. <div class="modal-header">
  702. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  703. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  704. <span aria-hidden="true">&times;</span>
  705. </button>
  706. </div>
  707. <div class="modal-body">
  708. ...
  709. </div>
  710. <div class="modal-footer">
  711. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  712. </div>
  713. </div>
  714. </div>
  715. </div>'; //
  716. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  717. print '<table id="table-results" class="table table-hover m-t-1">
  718. <thead>
  719. <tr id="cols-exercises">
  720. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  721. </tr>
  722. </thead>
  723. <tbody>'; // "
  724. foreach ($students_list as $student) {
  725. $user = $DB->get_record('user', array('id' => $student->userid));
  726. $avatar = new user_picture($user);
  727. $avatar->courseid = $COURSE->id;
  728. $avatar->link = true;
  729. print
  730. '<tr data-student="'.$student->userid.'">
  731. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  732. </tr>'; // "
  733. }
  734. print '</tbody>
  735. </table>'; // "
  736. print $OUTPUT->footer();
  737. } // function auto_evaluate()
  738. /// This method moves an iAssign activity
  739. function move_activity () {
  740. global $USER, $CFG, $DB, $COURSE;
  741. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  742. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  743. $update_entry_new_iassign = new stdClass();
  744. $update_entry_new_iassign->id = $iassign_id;
  745. $update_entry_new_iassign->iassignid = $iassign_destiny;
  746. // Update the iassign_statement
  747. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  748. // Update file context
  749. $c_i = context_module::instance($this->cm->id);
  750. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  751. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  752. $path_module = context_course::instance($COURSE->id);
  753. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  754. if ($context_file) {
  755. $id_context = $context_file->id;
  756. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  757. $fs = get_file_storage(); // Get reference to all files in Moodle data
  758. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  759. foreach ($files as $value) {
  760. if ($value->get_filename() != ".") {
  761. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  762. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  763. $updateentry = new stdClass();
  764. $updateentry->id = $iassign_id;
  765. $updateentry->file = $newfile->get_itemid();
  766. $DB->update_record("iassign_statement", $updateentry);
  767. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  768. break;
  769. }
  770. }
  771. }
  772. $this->return_home_course('moved_activity');
  773. exit;
  774. }
  775. /// This method duplicates an iAssign activity
  776. function duplicate_activity () {
  777. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  778. $id = $this->cm->id;
  779. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  780. $context = context_module::instance($this->cm->id);
  781. $contextuser = context_user::instance($USER->id);
  782. // Get the the iAssign acitivity to be duplicated
  783. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  784. // Remove the current id of activity
  785. $iassign_statement->id=0;
  786. // Get the information about current author, and add this information in author_modified field
  787. $author = $DB->get_record("user", array('id' => $USER->id));
  788. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  789. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  790. // Store the activity in the table
  791. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  792. // Duplicate activity file
  793. $fs = get_file_storage(); // Get reference to all files in Moodle data
  794. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  795. foreach ($files as $value) {
  796. if ($value->get_filename() != ".") {
  797. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  798. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  799. $updateentry = new stdClass();
  800. $updateentry->id = $id_;
  801. $updateentry->file = $newfile->get_itemid();
  802. // Update the duplicated iLM iAssign with new file id
  803. $DB->update_record("iassign_statement", $updateentry);
  804. }
  805. }
  806. }
  807. // log event --------------------------------------------------------------------------------------
  808. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  809. $this->return_home_course('duplicated_activity');
  810. exit;
  811. }
  812. /// This method gets the content from the iLM and register it
  813. // It could be the "exercise template" (teacher) or an answer (student)
  814. function get_answer () {
  815. global $USER, $CFG, $DB, $OUTPUT;
  816. $id = $this->cm->id;
  817. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  818. $comment = false;
  819. if ($submission_comment)
  820. $comment = $this->write_comment_submission();
  821. // receives data of iLM using the current activity
  822. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  823. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  824. // receives data of submission of current activity
  825. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  826. // receives post and get
  827. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  828. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  829. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  830. $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)
  831. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  832. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  833. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  834. $msg = '';
  835. // Feedback
  836. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  837. $str_action = "view"; // repeat
  838. if (strtolower($iassign_ilm->name) == "igeom") {
  839. }
  840. $title = get_string('evaluate_iassign', 'iassign');
  841. print $OUTPUT->header();
  842. print $OUTPUT->box_start();
  843. // Action = { view ; repeat ; viewsubmission }
  844. // * '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")
  845. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  846. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  847. $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;
  848. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  849. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  850. print '<table width=100% >';
  851. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  852. //TODO alterar aqui???
  853. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  854. // empty_answer_post = No solution was posted.
  855. if ($comment)
  856. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  857. else
  858. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  859. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  860. } else {
  861. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  862. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  863. // Correct answer!!
  864. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  865. $this->write_solution = 1; //
  866. $status = 3;
  867. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  868. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  869. // log record
  870. $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;
  871. // Trigger module viewed event.
  872. $event = \mod_iassign\event\submission_created::create(array(
  873. 'objectid' => $this->iassign->id,
  874. 'context' => $this->context,
  875. 'other' => $info
  876. ));
  877. $event->add_record_snapshot('course', $this->course);
  878. $event->trigger();
  879. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  880. // Wrong answer...: get_answer_incorrect
  881. $status = 2;
  882. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  883. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  884. // log record
  885. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  886. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  887. // Trigger module viewed event.
  888. $event = \mod_iassign\event\submission_created::create(array(
  889. 'objectid' => $this->iassign->id,
  890. 'context' => $this->context,
  891. 'other' => $info
  892. ));
  893. $event->add_record_snapshot('course', $this->course);
  894. $event->trigger();
  895. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  896. // Presents to the learner the result of the automatic evaluate?
  897. if ($this->activity->get_activity()->show_answer == 0) { // no...
  898. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  899. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  900. print '<tr>';
  901. // log record
  902. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  903. // Trigger module viewed event.
  904. $event = \mod_iassign\event\submission_created::create(array(
  905. 'objectid' => $this->iassign->id,
  906. 'context' => $this->context,
  907. 'other' => $info
  908. ));
  909. $event->add_record_snapshot('course', $this->course);
  910. $event->trigger();
  911. } else { // yes!!!
  912. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  913. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  914. print '<tr>';
  915. print $msg;
  916. }
  917. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  918. $status = 1;
  919. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  920. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  921. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  922. print '<tr>';
  923. // log record
  924. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  925. $event = \mod_iassign\event\submission_created::create(array(
  926. 'objectid' => $this->iassign->id,
  927. 'context' => $this->context,
  928. 'other' => $info
  929. ));
  930. $event->add_record_snapshot('course', $this->course);
  931. $event->trigger();
  932. } // if ($iassign_ilm->evaluate == 1)
  933. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  934. print '</tr></table>';
  935. print $OUTPUT->box_end();
  936. // add or update evaluate
  937. if ($this->write_solution == 1) {
  938. $timenow = time();
  939. // new record
  940. if (!$iassign_submission) {
  941. $newentry = new stdClass();
  942. $newentry->userid = $this->userid_iassign;
  943. // $newentry->userid = $USER->id;
  944. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  945. $newentry->timecreated = $timenow;
  946. $newentry->timemodified = $timenow;
  947. $newentry->answer = $iLM_PARAM_ArchiveContent;
  948. $newentry->grade = round($grade_student, 2);
  949. $newentry->status = $status;
  950. $newentry->experiment = 1;
  951. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  952. print_error('error_insert', 'iassign');
  953. } else {
  954. // Trigger module viewed event.
  955. $event = \mod_iassign\event\submission_created::create(array(
  956. 'objectid' => $this->iassign->id,
  957. 'context' => $this->context
  958. ));
  959. $event->add_record_snapshot('course', $this->course);
  960. $event->trigger();
  961. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  962. }
  963. } elseif ($iassign_submission->status != 3) {
  964. $newentry = new stdClass();
  965. $newentry->id = $iassign_submission->id;
  966. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  967. $newentry->userid = $iassign_submission->userid;
  968. $newentry->timecreated = $iassign_submission->timecreated;
  969. $newentry->timemodified = $timenow;
  970. $newentry->answer = $iLM_PARAM_ArchiveContent;
  971. $newentry->grade = round($grade_student, 2);
  972. $newentry->status = $status;
  973. $newentry->experiment = $iassign_submission->experiment + 1;
  974. if (!$DB->update_record("iassign_submission", $newentry)) {
  975. print_error('error_update', 'iassign');
  976. //D depurar...
  977. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  978. //D $fp = fopen("teste1.txt","w");
  979. //D fwrite($fp,$stringAux);
  980. } else {
  981. // Trigger module viewed event.
  982. $event = \mod_iassign\event\submission_updated::create(array(
  983. 'objectid' => $this->iassign->id,
  984. 'context' => $this->context
  985. ));
  986. $event->add_record_snapshot('course', $this->course);
  987. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  988. }
  989. } else {
  990. if ($return_get_answer == 1) {
  991. $newentry = new stdClass();
  992. $newentry->id = $iassign_submission->id;
  993. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  994. $newentry->userid = $iassign_submission->userid;
  995. $newentry->timecreated = $iassign_submission->timecreated;
  996. $newentry->timemodified = $timenow;
  997. $newentry->answer = $iLM_PARAM_ArchiveContent;
  998. $newentry->grade = round($grade_student, 2);
  999. $newentry->status = $status;
  1000. $newentry->experiment = $iassign_submission->experiment + 1;
  1001. if (!$DB->update_record("iassign_submission", $newentry))
  1002. print_error('error_update', 'iassign');
  1003. else {
  1004. $event = \mod_iassign\event\submission_updated::create(array(
  1005. 'objectid' => $this->iassign->id,
  1006. 'context' => $this->context
  1007. ));
  1008. $event->add_record_snapshot('course', $this->course);
  1009. $event->trigger();
  1010. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1011. print $OUTPUT->box_start();
  1012. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1013. print $OUTPUT->box_end();
  1014. }
  1015. } elseif ($return_get_answer == 2) {
  1016. print $OUTPUT->box_start();
  1017. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1018. print $OUTPUT->box_end();
  1019. } else {
  1020. print $OUTPUT->box_start();
  1021. print "
  1022. <script type='text/javascript'>
  1023. //<![CDATA[
  1024. function overwrite () {
  1025. document.formEnvio.return_get_answer.value = 1;
  1026. document.formEnvio.submit();
  1027. }
  1028. function nooverwrite () {
  1029. document.formEnvio.return_get_answer.value = 2;
  1030. document.formEnvio.submit();
  1031. }
  1032. //]]>
  1033. </script>";
  1034. $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;
  1035. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1036. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1037. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1038. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1039. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1040. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1041. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1042. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1043. <input type='hidden' name='return_get_answer'/> ";
  1044. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1045. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1046. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1047. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1048. print " </form>";
  1049. print $OUTPUT->box_end();
  1050. }
  1051. }
  1052. } // if ($this->write_solution == 1)
  1053. print $OUTPUT->footer();
  1054. die();
  1055. } // function get_answer()
  1056. /// Export in file the answer of student.
  1057. function export_file_answer () {
  1058. global $DB;
  1059. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1060. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1061. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1062. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1063. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1064. $extensions = explode(",", $iassign_ilm->extension);
  1065. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1066. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1067. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1068. header("Pragma: public");
  1069. header("Expires: 0");
  1070. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1071. header("Cache-Control: private", false);
  1072. header("Content-Type: document/unknown");
  1073. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1074. set_time_limit(0);
  1075. print($iassign_submission->answer);
  1076. exit;
  1077. } // function export_file_answer()
  1078. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1079. // @calledby $this->export_package_answer()
  1080. //TODO Precisa terminar! //TODO_HTML
  1081. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1082. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1083. <head>
  1084. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1085. $str_html .= " </head>
  1086. <body>\n";
  1087. $tam = sizeof($array_iassign_name);
  1088. for ($ii=0; $ii<$tam; $ii++) {
  1089. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1090. }
  1091. $str_html .= "
  1092. </body>\n</html>";
  1093. return $str_html;
  1094. }
  1095. /// Export an package (zip) with all answer of students
  1096. // @calledby $this->action()
  1097. function export_package_answer () {
  1098. global $DB, $CFG, $OUTPUT;
  1099. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1100. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1101. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1102. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1103. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1104. $userid = optional_param('userid', NULL, PARAM_INT);
  1105. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1106. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1107. //TODO_HTML echo "username=$username<br/>"; exit;
  1108. $current_date = date('Y_m_d_H');
  1109. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1110. // If temporary directory under Moodle data does not exists => create it
  1111. if (!is_dir($diretorio)) {
  1112. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1113. // created directory with permissions to be seen by everyone
  1114. }
  1115. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1116. if (!is_writable($diretorio)) { // send a highlighted message!
  1117. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1118. exit; // just in case
  1119. }
  1120. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1121. $zip = new zip_archive(); // create ZIP
  1122. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1123. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1124. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1125. $vet_student_filename = array();
  1126. $vet_student_content = array();
  1127. foreach ($iassign_statements as $iassign_statement) {
  1128. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1129. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1130. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1131. $extensions = explode(",", $iassign_ilm->extension);
  1132. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1133. if ($iassign_submission) {
  1134. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1135. $student_content = $iassign_submission->answer;
  1136. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1137. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1138. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1139. if ($resp) {
  1140. $vet_student_filename[] = $student_filename;
  1141. $vet_student_content[] = $student_content;
  1142. }
  1143. else { // send a highlighted message!
  1144. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1145. exit; // just in case
  1146. }
  1147. }
  1148. }
  1149. $zip->close(); // close the ZIP file
  1150. if (count($vet_student_filename)>0) {
  1151. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1152. $result_tf = $vet_result[0];
  1153. $filenameZip = $vet_result[1]->filename;
  1154. }
  1155. iassign_utils::download_file($zip_filename); // download the ZIP file
  1156. exit;
  1157. } // function export_package_answer()
  1158. /// Editing status of interactive activities
  1159. function edit_status () {
  1160. global $USER, $DB, $OUTPUT;
  1161. $newentry = new stdClass();
  1162. $newentry->id = $this->iassign_submission_current;
  1163. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1164. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1165. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1166. $newentry->status = $iassign_submission->status;
  1167. $newentry->teacher = $USER->id;
  1168. if (!$DB->update_record('iassign_submission', $newentry))
  1169. print_error('error_update', 'iassign');
  1170. else {
  1171. // Trigger module viewed event.
  1172. $event = \mod_iassign\event\submission_updated::create(array(
  1173. 'objectid' => $this->iassign->id,
  1174. 'context' => $this->context
  1175. ));
  1176. $event->add_record_snapshot('course', $this->course);
  1177. $event->trigger();
  1178. $this->action = 'viewsubmission';
  1179. $this->view_iassign_current();
  1180. } // if (!$DB->update_record('iassign_submission', $newentry))
  1181. } // function edit_status()
  1182. /// Editing grade of interactive activities
  1183. function edit_grade () {
  1184. global $USER, $DB, $OUTPUT;
  1185. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1186. if ($newgrade && $newgrade >= 0) {
  1187. $newentry = new stdClass();
  1188. $newentry->id = $this->iassign_submission_current;
  1189. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1190. $newentry->teacher = $USER->id;
  1191. if (!$DB->update_record('iassign_submission', $newentry))
  1192. print_error('error_update', 'iassign');
  1193. else {
  1194. // Trigger module viewed event.
  1195. $event = \mod_iassign\event\submission_updated::create(array(
  1196. 'objectid' => $this->iassign->id,
  1197. 'context' => $this->context
  1198. ));
  1199. $event->add_record_snapshot('course', $this->course);
  1200. $event->trigger();
  1201. }
  1202. } // if ($newgrade >= 0)
  1203. $this->action = 'viewsubmission';
  1204. $this->view_iassign_current();
  1205. }
  1206. /// Add or Edit interactive activities
  1207. // @calledby $this->action()
  1208. function add_edit_iassign () {
  1209. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1210. require_once('iassign_form.php');
  1211. $id = $this->cm->id;
  1212. $iassignid = $this->iassign->id;
  1213. $param = new stdClass();
  1214. $param->action = $this->action; // oculto
  1215. $param->id = $id; // oculto
  1216. $COURSE->cm = $id;
  1217. $COURSE->iassignid = $iassignid;
  1218. $COURSE->iassign_file_id = NULL;
  1219. $context = context_module::instance($this->cm->id);
  1220. $contextuser = context_user::instance($USER->id);
  1221. $component = 'mod_iassign';
  1222. $filearea = 'exercise';
  1223. if (!empty($this->iassign_current))
  1224. $COURSE->iassign_id = $this->iassign_current;
  1225. else
  1226. $COURSE->iassign_id = 0;
  1227. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1228. if ($this->action == 'add') {
  1229. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1230. $params = array('iassignid' => $iassignid);
  1231. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1232. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1233. $total_of_activities = count($iassign_statement);
  1234. $param->iassignid = $iassignid;
  1235. $param->name = "";
  1236. $param->oldname = "";
  1237. $param->type_iassign = 3;
  1238. $param->proposition = "";
  1239. $author = $DB->get_record("user", array("id" => $USER->id));
  1240. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1241. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1242. $param->author = $param->author_name;
  1243. $param->author_modified = $param->author_modified_name;
  1244. $COURSE->iassign_list = array();
  1245. $param->iassign_list = array();
  1246. if ($iassign_statement) {
  1247. foreach ($iassign_statement as $iassign) {
  1248. $iassignid = $iassign->id;
  1249. $param->iassign_list[$iassignid] = 0;
  1250. $COURSE->iassign_list[$iassignid] = new stdClass();
  1251. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1252. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1253. $COURSE->iassign_list[$iassignid]->enable = 1;
  1254. } // foreach ($iassign_statement as $iassign)
  1255. }
  1256. $param->iassign_ilmid = 0;
  1257. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1258. $param->file = 0;
  1259. $param->fileold = 0;
  1260. $param->filename = "";
  1261. $param->grade = $iassign_data->grade;
  1262. $param->timemodified = time();
  1263. $param->timecreated = time();
  1264. $param->timeavailable = $iassign_data->timeavailable;
  1265. $param->timedue = $iassign_data->timedue;
  1266. $param->preventlate = $iassign_data->preventlate;
  1267. $param->test = $iassign_data->test;
  1268. $param->special_param1 = 0;
  1269. $param->visible = 1;
  1270. $param->max_experiment = $iassign_data->max_experiment;
  1271. $param->dependency = 0;
  1272. $param->automatic_evaluate = 1;
  1273. $param->show_answer = 1;
  1274. } // if ($this->action == 'add')
  1275. elseif ($this->action == 'edit') {
  1276. $COURSE->iassign_list = array();
  1277. $this_activity = $this->activity->get_activity();
  1278. if ($this_activity != null) {
  1279. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1280. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1281. $param->iassign_id = $iassign_statement_current->id; // oculto
  1282. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1283. $param->name = $iassign_statement_current->name;
  1284. $param->oldname = $iassign_statement_current->name;
  1285. $param->type_iassign = $iassign_statement_current->type_iassign;
  1286. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1287. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1288. //2019 $param->proposition = $iassign_statement_current->proposition;
  1289. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1290. $param->author_name = $iassign_statement_current->author_name; // oculto
  1291. $param->author = $iassign_statement_current->author_name;
  1292. $author = $DB->get_record("user", array('id' => $USER->id));
  1293. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1294. $param->author_modified = $param->author_modified_name;
  1295. $dependency = explode(';', $iassign_statement_current->dependency);
  1296. $param->iassign_list = array();
  1297. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1298. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1299. $array_dependency = array();
  1300. $subdependency = "";
  1301. $sub_subdependency = "";
  1302. // dependent on this exercise
  1303. if ($iassign_statement_dependency) {
  1304. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1305. // to whom this exercise depends
  1306. foreach ($inter as $tmp)
  1307. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1308. $list_dependency = $subdependency . $sub_subdependency;
  1309. $array_dependency = explode(";", $list_dependency);
  1310. }
  1311. // Get all activity with the same iLM - iassignid
  1312. $str_query = "SELECT id, name FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' ORDER BY s.position ASC";
  1313. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1314. $total_of_activities = count($all_others_iassign_statement) + 1;
  1315. $inter = array();
  1316. if ($all_others_iassign_statement) {
  1317. foreach ($all_others_iassign_statement as $iassign)
  1318. if (in_array($iassign->id, $dependency))
  1319. $inter[] = $iassign->id;
  1320. }
  1321. if ($all_others_iassign_statement) {
  1322. foreach ($all_others_iassign_statement as $iassign) {
  1323. $iassignid = $iassign->id;
  1324. $COURSE->iassign_list[$iassignid] = new stdClass();
  1325. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1326. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1327. if (in_array($iassignid, $dependency))
  1328. $param->iassign_list[$iassignid] = 1;
  1329. else
  1330. $param->iassign_list[$iassignid] = 0;
  1331. if (in_array($iassignid, $array_dependency))
  1332. $COURSE->iassign_list[$iassignid]->enable = 0;
  1333. else
  1334. $COURSE->iassign_list[$iassignid]->enable = 1;
  1335. } // foreach ($all_others_iassign_statement as $iassign)
  1336. }
  1337. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1338. $param->fileold = 0;
  1339. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1340. $param->filename = '';
  1341. $param->grade = $iassign_statement_current->grade;
  1342. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1343. $param->timeavailable = $iassign_statement_current->timeavailable;
  1344. $param->timedue = $iassign_statement_current->timedue;
  1345. $param->preventlate = $iassign_statement_current->preventlate;
  1346. $param->test = $iassign_statement_current->test;
  1347. $param->special_param1 = $iassign_statement_current->special_param1;
  1348. $param->position = $iassign_statement_current->position; // oculto
  1349. $param->visible = $iassign_statement_current->visible;
  1350. $param->max_experiment = $iassign_statement_current->max_experiment;
  1351. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1352. $param->show_answer = $iassign_statement_current->show_answer;
  1353. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1354. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1355. if ($files) {
  1356. foreach ($files as $file) {
  1357. if ($file->get_filename() != '.') {
  1358. $param->filename = $file->get_filename();
  1359. $param->file = $file->get_id();
  1360. $param->fileold = $file->get_id();
  1361. $COURSE->iassign_file_id = $file->get_id();
  1362. }
  1363. }
  1364. }
  1365. //TODO //MOOC2014 -- inicio
  1366. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1367. //D if ($iassign_ilm_configs) {
  1368. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1369. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1370. //D } //MOOC2014 -- fim
  1371. } // if ($this_activity != null)
  1372. } // elseif ($this->action == 'edit')
  1373. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1374. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1375. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1376. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1377. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1378. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1379. $param->position = $total_of_activities;
  1380. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1381. $mform->set_data($param);
  1382. if ($mform->is_cancelled()) {
  1383. $this->return_home_course('iassign_cancel');
  1384. exit;
  1385. }
  1386. else { // if ($mform->is_cancelled())
  1387. $result = $mform->get_data();
  1388. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1389. if ($result) {
  1390. $result->context = $context;
  1391. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1392. $result->grade = 0;
  1393. if ($result->type_iassign == 1) {
  1394. $result->automatic_evaluate = 0;
  1395. $result->show_answer = 0;
  1396. }
  1397. elseif ($result->automatic_evaluate == 0)
  1398. $result->show_answer = 0;
  1399. // $_POST['iassign_list']
  1400. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1401. if ($result->iassign_list) {
  1402. foreach ($result->iassign_list as $key => $value)
  1403. $result->dependency .= $key . ';';
  1404. }
  1405. else
  1406. $result->dependency = 0;
  1407. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1408. //TODO Then get it directly from the form data $_POST!
  1409. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1410. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1411. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1412. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1413. if ($this->action == 'add') {
  1414. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1415. if ($iassign_statement_name) {
  1416. $this->return_home_course('error_iassign_name');
  1417. die();
  1418. }
  1419. // Really insert the new iActivity in table '*_iassign_statement'
  1420. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1421. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1422. // Trigger module viewed event.
  1423. $event = \mod_iassign\event\iassign_created::create(array(
  1424. 'objectid' => $iassignid,
  1425. 'context' => $context
  1426. ));
  1427. $event->add_record_snapshot('course', $this->course);
  1428. $event->trigger();
  1429. $this->return_home_course('iassign_add');
  1430. } // if ($this->action == 'add')
  1431. elseif ($this->action == 'edit') {
  1432. $iassignid = $this->activity->update_iassign($result);
  1433. $this->activity->update_calendar($iassignid, $result->oldname);
  1434. // Trigger module viewed event.
  1435. $event = \mod_iassign\event\iassign_updated::create(array(
  1436. 'objectid' => $iassignid,
  1437. 'context' => $context
  1438. ));
  1439. $event->add_record_snapshot('course', $this->course);
  1440. $event->trigger();
  1441. $this->return_home_course('iassign_update');
  1442. } // elseif ($this->action == 'edit')
  1443. die();
  1444. } // if ($result)
  1445. } // else if ($mform->is_cancelled())
  1446. print $OUTPUT->header();
  1447. $mform->display();
  1448. print $OUTPUT->footer();
  1449. die();
  1450. } // function add_edit_iassign()
  1451. /// Search for dependencies
  1452. function search_dependency ($search_iassing_id, $iassign_statement) {
  1453. global $DB, $OUTPUT;
  1454. $dependency = "";
  1455. if ($iassign_statement)
  1456. foreach ($iassign_statement as $iassign) {
  1457. $inter_dependency = explode(';', $iassign->dependency);
  1458. if (in_array($search_iassing_id, $inter_dependency)) {
  1459. $dependency .= $iassign->id . ";";
  1460. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1461. } // if (in_array($search_iassing_id, $inter_dependency))
  1462. } // foreach ($iassign_statement as $iassign)
  1463. return $dependency;
  1464. }
  1465. /// Search for "sub"dependency
  1466. function search_sub_dependency ($search_iassing_id) {
  1467. global $DB, $OUTPUT;
  1468. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1469. $dependency = "";
  1470. if ($iassign_statement) {
  1471. $inter_dependency = explode(';', $iassign_statement->dependency);
  1472. foreach ($inter_dependency as $tmp) {
  1473. if ($tmp != 0)
  1474. $dependency .= $tmp . ";";
  1475. $dependency .= $this->search_sub_dependency($tmp);
  1476. } // foreach ($inter_dependency as $tmp)
  1477. } // if ($iassign_statement)
  1478. return $dependency;
  1479. }
  1480. // Warning message
  1481. static function warning_message_iassign ($strcode) {
  1482. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1483. }
  1484. /// Update grade of iAssign
  1485. // Called always any iAssign activity is created
  1486. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1487. static function update_grade_iassign ($iassignid) {
  1488. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1489. require_once($CFG->libdir . '/gradelib.php');
  1490. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1491. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1492. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1493. // Each iAssign item is associated with one item on the "gradebook"
  1494. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1495. //$sum_grade = 0;
  1496. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1497. //foreach($grade as $tmp) {
  1498. // $sum_grade += $tmp->grade;
  1499. // }
  1500. //1 Solution 1
  1501. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1502. //1 $sum_grade = 0; //1
  1503. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1504. //2 Solution 2
  1505. $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
  1506. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1507. if (key($array_sum_grade))
  1508. $sum_grade = key($array_sum_grade); //2
  1509. else
  1510. $sum_grade = 0; //2
  1511. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1512. $grades = NULL;
  1513. $params = array('itemname' => $grade_iassign->name);
  1514. $params['iteminstance'] = $iassignid;
  1515. $params['gradetype'] = GRADE_TYPE_VALUE;
  1516. //2016 if ($sum_grade != 0) {
  1517. $params['grademax'] = $sum_grade;
  1518. $params['rawgrademax'] = $sum_grade;
  1519. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1520. $params['grademin'] = 0;
  1521. // @calls /lib/gradelib.php: call to grade_item->insert()
  1522. //TODO: is there any error here in Moodle version 3.0?
  1523. //TODO: Incorrect property 'grademax' found when inserting grade object
  1524. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1525. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1526. }
  1527. /// Update grade of student
  1528. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1529. global $CFG, $DB, $OUTPUT;
  1530. require_once($CFG->libdir . '/gradelib.php');
  1531. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1532. // Review all the student submission for this iAssign activity
  1533. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1534. $total_grade = 0;
  1535. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1536. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1537. if ($iassign_submission)
  1538. $total_grade += $iassign_submission->grade;
  1539. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1540. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1541. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1542. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1543. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1544. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1545. $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
  1546. if (key($array_sum_grade))
  1547. $sum_grade = key($array_sum_grade); //2
  1548. else
  1549. $sum_grade = 0; //2
  1550. $grades['userid'] = $userid;
  1551. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1552. $params = array('itemname' => $grade_iassign->name);
  1553. $params['iteminstance'] = $iassignid;
  1554. $params['gradetype'] = GRADE_TYPE_VALUE;
  1555. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1556. $params['grademax'] = $sum_grade;
  1557. $params['rawgrademax'] = $sum_grade;
  1558. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1559. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1560. }
  1561. /// Display caption of icons
  1562. function view_legend_icons () {
  1563. global $USER, $CFG, $DB, $OUTPUT;
  1564. $id = $this->cm->id;
  1565. if ($this->action == 'print')
  1566. print '<table border=1 width=100%><tr>';
  1567. else
  1568. print '<table width=100%><tr>';
  1569. print '<td >';
  1570. if ($this->action != 'print')
  1571. print $OUTPUT->help_icon('legend', 'iassign');
  1572. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1573. // $imagetext = '');
  1574. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1575. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1576. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1577. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1578. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1579. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1580. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1581. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1582. print '</td>' . "\n";
  1583. if ($this->action != 'print') {
  1584. $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>";
  1585. $link_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=stats&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('results') . '&nbsp;' . get_string('graphic', 'iassign') . "</a>";
  1586. $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>";
  1587. $link_auto_evaluate = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=auto_evaluate&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('correct') . '&nbsp;' . get_string('auto_evaluate_reprocess', 'iassign') . "</a>";
  1588. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1589. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1590. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1591. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1592. } // if ($this->action != 'print')
  1593. print '</tr></table>' . "\n";
  1594. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1595. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1596. $link_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=stats_student&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('results') . '&nbsp;' . get_string('results', 'iassign') . "</a>";
  1597. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1598. print '</tr></table>' . "\n";
  1599. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1600. else
  1601. print '</td></tr></table>' . "\n";
  1602. } // function view_legend_icons()
  1603. /// Display activity current
  1604. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1605. function view_iassign_current () {
  1606. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1607. $id = $this->cm->id;
  1608. $iassignid = $this->iassign->id;
  1609. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1610. $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
  1611. // 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 ...
  1612. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1613. if (!$iassign_statement_activity_item) {
  1614. print $OUTPUT->header();
  1615. \core\notification::error(get_string('activity_not_found', 'iassign'));
  1616. print $OUTPUT->footer();
  1617. exit;
  1618. }
  1619. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1620. $ilm_name = '';
  1621. if ($ilm->ilm)
  1622. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1623. // 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
  1624. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1625. // log record
  1626. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1627. //Trigger module viewed event.
  1628. $event = \mod_iassign\event\submission_viewed::create(array(
  1629. 'objectid' => $iassign->id,
  1630. 'context' => $this->context,
  1631. 'other' => $info
  1632. ));
  1633. $event->add_record_snapshot('course', $this->course);
  1634. $event->trigger();
  1635. // Search of iLM data used in the current activity
  1636. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1637. // Add actual activity to navbar:
  1638. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1639. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1640. print $OUTPUT->header();
  1641. if ($this->action == 'viewsubmission') {
  1642. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1643. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1644. else
  1645. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1646. } else {
  1647. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1648. }
  1649. if ($iassign_submission)
  1650. $this->update_comment($iassign_submission->id);
  1651. $file = $iassign_statement_activity_item->file;
  1652. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1653. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1654. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1655. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1656. $this->bottonPost = 0; // hide submit button
  1657. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1658. $this->view_iassign = false; // disable visualization of activity
  1659. $repeat = "";
  1660. $last_iassign = "";
  1661. $student_answer = "";
  1662. $comment = "";
  1663. // *** Teacher access (view learner's submission)
  1664. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1665. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1666. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1667. // ---> access teacher for test
  1668. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1669. $this->bottonPost = 1;
  1670. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1671. $this->activity->view_dates();
  1672. $USER->iassignEdit = $this->bottonPost;
  1673. $this->activity->show_info_iassign();
  1674. if ($iassign_submission) {
  1675. //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;
  1676. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1677. } else {
  1678. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1679. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1680. }
  1681. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1682. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1683. // Prepare tags to present the iLM
  1684. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1685. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1686. // *** (end) Teacher access (view the activity)
  1687. // *** Teacher access (view learner's submission to the activity)
  1688. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1689. // It is teacher or 'nonediting teacher' that can evaluate
  1690. // ----> area teacher evaluate
  1691. $row = optional_param('row', 0, PARAM_INT);
  1692. $column = optional_param('column', 0, PARAM_INT);
  1693. $link_next = iassign_icons::insert('right_disable');
  1694. $link_previous = iassign_icons::insert('left_disable');
  1695. $link_up = iassign_icons::insert('up_disable');
  1696. $link_down = iassign_icons::insert('down_disable');
  1697. // next_activity
  1698. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1699. $url_next = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column + 1]->iassign_submission_current . "&userid_iassign=$this->userid_iassign&iassign_current=" . $USER->matrix_iassign[$row][$column]->iassign_next . "&view_iassign=report&row=" . ($row) . "&column=" . ($column + 1);
  1700. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1701. }
  1702. // previous_activity
  1703. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1704. $url_previous = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column - 1]->iassign_submission_current . "&userid_iassign=$this->userid_iassign&iassign_current=" . $USER->matrix_iassign[$row][$column]->iassign_previous . "&view_iassign=report&row=" . ($row) . "&column=" . ($column - 1);
  1705. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1706. }
  1707. // previous_student
  1708. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1709. $url_down = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row + 1][$column]->iassign_submission_current . "&userid_iassign=" . $USER->matrix_iassign[$row][$column]->user_next . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row + 1) . "&column=" . ($column);
  1710. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1711. }
  1712. // next_student
  1713. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1714. $url_up = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row - 1][$column]->iassign_submission_current . "&userid_iassign=" . $USER->matrix_iassign[$row][$column]->user_previous . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row - 1) . "&column=" . ($column);
  1715. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1716. }
  1717. if ($iassign_submission) {
  1718. $student_answer = $iassign_submission->answer;
  1719. }
  1720. $last_iassign = get_string('last_iassign', 'iassign');
  1721. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1722. // Messages related to due date (and user role)
  1723. $this->activity->view_dates();
  1724. print $OUTPUT->box_start();
  1725. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1726. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1727. print $OUTPUT->user_picture($user_data);
  1728. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1729. print '</td>' . "\n";
  1730. print '<td width=20% align=right>' . "\n";
  1731. print '<table width=50 cellpadding="0">';
  1732. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1733. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1734. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1735. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1736. print '</table>' . "\n";
  1737. print '</td></tr></table>' . "\n";
  1738. print $OUTPUT->box_end();
  1739. print $OUTPUT->box_start();
  1740. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1741. print '<td width=60% valign="top">' . "\n";
  1742. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1743. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1744. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1745. $resp = get_string('yes');
  1746. else
  1747. $resp = get_string('no');
  1748. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1749. if ($iassign_statement_activity_item->show_answer == 1)
  1750. $resp = get_string('yes');
  1751. else
  1752. $resp = get_string('no');
  1753. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1754. print '</td>';
  1755. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1756. print '<td width=40% valign="top" align="left">';
  1757. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1758. // check status of solution sent by the student
  1759. if ($iassign_submission) {
  1760. switch ($iassign_submission->status) {
  1761. case 3 :
  1762. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1763. break;
  1764. case 2 :
  1765. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1766. break;
  1767. case 1 :
  1768. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1769. break;
  1770. default :
  1771. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1772. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1773. } // switch ($iassign_submission->status)
  1774. }
  1775. else { // if ($iassign_submission)
  1776. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1777. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1778. }
  1779. // update_status
  1780. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1781. $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);
  1782. print " <script type='text/javascript'>
  1783. //<![CDATA[
  1784. function overwriteStatus (newstatus) {
  1785. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1786. document.formEditStatus.return_status.value=newstatus;
  1787. document.formEditStatus.submit();
  1788. }
  1789. else
  1790. document.formEditStatus.return_status.value=-1;
  1791. }
  1792. //]]>
  1793. </script>";
  1794. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1795. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1796. 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";
  1797. print " <input type='hidden' name='return_status'>\n";
  1798. print "</form>\n";
  1799. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1800. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1801. $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);
  1802. print "
  1803. <script type='text/javascript'>
  1804. //<![CDATA[
  1805. function overwriteGrade (newgrade,maxgrade) {
  1806. if (newgrade<0 || newgrade>maxgrade) {
  1807. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1808. document.formEditGrade.return_grade.value=-1;
  1809. document.formEditGrade.submit();
  1810. }
  1811. else {
  1812. document.formEditGrade.return_grade.value=newgrade;
  1813. document.formEditGrade.submit();
  1814. }
  1815. }
  1816. //]]>
  1817. </script>";
  1818. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1819. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1820. print " <input type='text' name='grade' size='6'>";
  1821. print " <input type='hidden' name='return_grade'> ";
  1822. 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";
  1823. print "</form>";
  1824. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1825. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1826. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1827. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1828. if ($teacher)
  1829. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1830. } // if ($iassign_submission->experiment > 0)
  1831. print '</td>';
  1832. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1833. print '</tr></table>';
  1834. print $OUTPUT->box_end();
  1835. $USER->iassignEdit = $this->bottonPost;
  1836. if ($iassign_submission && $allow_resubmission) {
  1837. // Put the iLM to
  1838. print $OUTPUT->box_start();
  1839. print '<p><strong>' . $last_iassign . '</strong></p>';
  1840. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1841. $enderecoPOST = "";
  1842. // Prepare tags to present the iLM
  1843. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1844. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1845. print $OUTPUT->box_end();
  1846. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1847. // ATTENTION: exception used by iGeom (exercise with "script")
  1848. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1849. if (substr($ilm_name, 0, 5)=="igeom") {
  1850. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1851. $loadTeacherActivity = true;
  1852. }
  1853. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1854. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1855. // Prepare tags to present the iLM
  1856. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1857. }
  1858. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1859. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1860. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1861. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1862. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1863. // *** (end) Teacher access (view learner's submission to the activity)
  1864. // *** Student access (view the activity)
  1865. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1866. // It could be the learner (he could send or resend the activity)
  1867. // ---> access student
  1868. $time_now = time();
  1869. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1870. // activity of type example - not submit button for submission
  1871. $this->view_iassign = true;
  1872. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1873. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1874. // activity of type test - iLM automatic evaluator - submit button for submission
  1875. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1876. $this->bottonPost = 1;
  1877. $this->view_iassign = true;
  1878. } else
  1879. $this->view_iassign = false;
  1880. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1881. // activity of type exercise (learner can send his answer, if yet open...)
  1882. $this->view_iassign = true;
  1883. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1884. $this->view_iassign = false;
  1885. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1886. $this->bottonPost = 1; // allow the submit button
  1887. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1888. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1889. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1890. if (!$iassign_submission) {
  1891. $str_iassign_submission_id = '';
  1892. $str_iassign_submission_answer = '';
  1893. }
  1894. else {
  1895. $str_iassign_submission_id = $iassign_submission->id;
  1896. $str_iassign_submission_answer = $iassign_submission->answer;
  1897. }
  1898. if ($this->action != 'repeat') {
  1899. $repeat = "<a href='view.php?action=repeat&id="
  1900. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1901. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1902. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1903. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1904. }
  1905. $this->bottonPost = 1;
  1906. $this->write_solution = 1; // can register his submission
  1907. $student_answer = $str_iassign_submission_answer;
  1908. }
  1909. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1910. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1911. $last_iassign = get_string('last_iassign', 'iassign');
  1912. if ($iassign_submission) {
  1913. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1914. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1915. $student_answer = $iassign_submission->answer;
  1916. } else {
  1917. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1918. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1919. }
  1920. }
  1921. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1922. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1923. $this->bottonPost = 1;
  1924. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1925. } else {
  1926. $last_iassign = get_string('last_iassign', 'iassign');
  1927. if ($iassign_submission) {
  1928. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1929. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1930. $student_answer = $iassign_submission->answer;
  1931. } else {
  1932. // Symbol of "redo activity"
  1933. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1934. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1935. }
  1936. }
  1937. } // elseif ($iassign_statement_activity_item->test == 1)
  1938. elseif ($iassign_statement_activity_item->test == 0)
  1939. $this->view_iassign = false;
  1940. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1941. if ($iassign_submission)
  1942. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1943. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1944. else
  1945. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1946. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1947. $this->activity->view_dates();
  1948. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1949. print $OUTPUT->box_start();
  1950. print '<table width=100% border=0 valign="top">' . "\n";
  1951. print '<tr><td width=60% valign="top">' . "\n";
  1952. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1953. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1954. $flag_dependency = true;
  1955. if ($iassign_statement_activity_item->type_iassign == 3) {
  1956. if ($iassign_statement_activity_item->dependency == 0) {
  1957. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1958. } else {
  1959. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1960. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1961. foreach ($dependencys as $dependency) {
  1962. if ($dependency) {
  1963. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1964. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1965. if ($dependencysubmissions) {
  1966. if ($dependencysubmissions->status == 3)
  1967. $icon = iassign_icons::insert('correct');
  1968. elseif ($dependencysubmissions->status == 2) {
  1969. $icon = iassign_icons::insert('incorrect');
  1970. $flag_dependency = false;
  1971. } elseif ($dependencysubmissions->status == 1) {
  1972. $icon = iassign_icons::insert('post');
  1973. $flag_dependency = false;
  1974. } elseif ($dependencysubmissions->status == 0) {
  1975. $icon = iassign_icons::insert('not_post');
  1976. $flag_dependency = false;
  1977. }
  1978. } else {
  1979. $icon = iassign_icons::insert('not_post');
  1980. $flag_dependency = false;
  1981. } // if ($dependencysubmissions)
  1982. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1983. } // if ($dependency)
  1984. } // foreach ($dependencys as $dependency)
  1985. } // if ($iassign_statement_activity_item->dependency == 0)
  1986. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1987. if ($flag_dependency == false) {
  1988. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1989. $this->view_iassign = false;
  1990. print '</tr></table>' . "\n";
  1991. }
  1992. else {
  1993. $this->view_iassign = true;
  1994. print '</td>' . "\n";
  1995. } // if ($flag_dependency == false)
  1996. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1997. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1998. // receiver=1 - message to teacher
  1999. // receiver=2 - message to student
  2000. if ($iassign_submission) {
  2001. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2002. if ($verify_message)
  2003. $comment = iassign_icons::insert('comment_unread');
  2004. }
  2005. print '<td width=40% valign="top" align="left">';
  2006. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2007. if ($iassign_statement_activity_item->show_answer == 1) {
  2008. // check status of solution sent by the student
  2009. if ($iassign_submission) {
  2010. switch ($iassign_submission->status) {
  2011. case 3 :
  2012. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2013. break;
  2014. case 2 :
  2015. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2016. break;
  2017. case 1 :
  2018. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2019. break;
  2020. default :
  2021. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2022. $repeat = "";
  2023. $last_iassign = "";
  2024. } // switch ($iassign_submission->status)
  2025. } else {
  2026. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2027. $repeat = "";
  2028. $last_iassign = "";
  2029. }
  2030. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2031. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2032. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2033. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2034. if ($iassign_statement_activity_item->max_experiment == 0)
  2035. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2036. else {
  2037. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2038. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2039. $repeat = "";
  2040. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2041. $this->bottonPost = 0;
  2042. $this->write_solution = 0;
  2043. }
  2044. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2045. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2046. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2047. if ($teacher)
  2048. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2049. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2050. } // if ($iassign_statement_activity_item->show_answer==1)
  2051. else {
  2052. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2053. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2054. $repeat = "";
  2055. $last_iassign = "";
  2056. } elseif ($iassign_submission->status == 1) {
  2057. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2058. }
  2059. }
  2060. print '</td>';
  2061. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2062. print '</tr></table>' . "\n";
  2063. // Presents the iLM
  2064. print '<table width=100% border=0 valign="top">' . "\n";
  2065. print '<td width=80% align="left">';
  2066. 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\".
  2067. print '<td width=20% align="rigth">';
  2068. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2069. print $repeat; // symbol of "redo activity"
  2070. print '</td></tr></table>' . "\n";
  2071. //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)'
  2072. $output = '';
  2073. if (!$iassign_ilm) {
  2074. $iassign_ilm = new stdClass();
  2075. $iassign_ilm->file_jar = "";
  2076. }
  2077. $output .= $OUTPUT->box_start();
  2078. $USER->iassignEdit = $this->bottonPost;
  2079. // ---
  2080. // Presents the iLM
  2081. // Prepare tags to present the iLM
  2082. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2083. $student_answer = ""; //?
  2084. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2085. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2086. $student_answer = "";
  2087. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2088. } else {
  2089. // When student is redoing his activity
  2090. // ATTENTION: exception used by iGeom (exercise with "script")
  2091. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2092. if (substr($ilm_name, 0, 5)=="igeom") {
  2093. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2094. $loadTeacherActivity = true;
  2095. }
  2096. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2097. }
  2098. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2099. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2100. //1 $history_comment = '';
  2101. //1 if ($iassign_submission) {
  2102. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2103. //1 }
  2104. //1 if (!empty($history_comment)) {
  2105. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2106. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2107. //1 $output .= $history_comment;
  2108. //1 $output .= "</table>\n";
  2109. //1 }
  2110. //1 $output .= "</form></center>\n";
  2111. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2112. //1 }
  2113. $output .= $OUTPUT->box_end();
  2114. print $output;
  2115. } // if ($this->view_iassign)
  2116. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2117. } // if ($this->view_iassign)
  2118. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2119. else
  2120. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2121. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2122. print '<table width=100% border=0 valign="top">' . "\n";
  2123. print '<tr><td width=60% valign="top">' . "\n";
  2124. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2125. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2126. print '</tr></table>' . "\n";
  2127. $student_answer = "";
  2128. $enderecoPOST = "";
  2129. // Prepare tags to present the iLM
  2130. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2131. print $output;
  2132. }
  2133. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2134. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2135. 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
  2136. // Put a block with area to sent/answer comments
  2137. $output = '';
  2138. $history_comment = '';
  2139. $row = optional_param('row', 0, PARAM_INT);
  2140. $column = optional_param('column', 0, PARAM_INT);
  2141. if ($iassign_submission) {
  2142. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2143. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2144. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2145. }
  2146. else {
  2147. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2148. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2149. }
  2150. $output .= $OUTPUT->box_start();
  2151. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  2152. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2153. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  2154. $output .= "</form></center>\n";
  2155. if (!empty($history_comment)) {
  2156. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2157. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2158. $output .= $history_comment;
  2159. $output .= "</table>";
  2160. }
  2161. $output .= $OUTPUT->box_end();
  2162. print $output;
  2163. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2164. // final block 'studant'
  2165. print $OUTPUT->footer();
  2166. die();
  2167. } // function view_iassign_current()
  2168. /// Export the data from performance report into CSV file format
  2169. function export_csv () {
  2170. global $USER, $CFG, $DB, $OUTPUT;
  2171. $str = "";
  2172. $fields = "student_id, student_name";
  2173. // Finding all iassign activities for the iassign:
  2174. $id = $this->cm->id;
  2175. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2176. $c = 1;
  2177. foreach ($iassign_list as $iassign) {
  2178. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2179. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2180. $c ++;
  2181. }
  2182. // Finding enrolled students:
  2183. $params = array('shortname' => 'student');
  2184. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2185. $context = context_course::instance($this->course->id);
  2186. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2187. $students = $DB->get_records_sql(
  2188. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2189. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2190. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2191. foreach ($students as $student) {
  2192. $str .= $student->userid . ',';
  2193. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2194. foreach ($iassign_list as $iassign) {
  2195. $str .= ',' . $iassign->id . ',';
  2196. $str .= '"' . $iassign->name . '",';
  2197. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2198. if ($student_submissions) {
  2199. $str .= $student_submissions->experiment . ',';
  2200. $str .= $student_submissions->grade . ',';
  2201. switch ($student_submissions->status) {
  2202. case 3:
  2203. $str .= '"correct",';
  2204. break;
  2205. case 2:
  2206. $str .= '"incorrect",';
  2207. break;
  2208. case 1:
  2209. $str .= '"post",';
  2210. break;
  2211. case 0:
  2212. $str .= '"not_post",';
  2213. break;
  2214. }
  2215. } else {
  2216. $str .= ',,"not_post",';
  2217. }
  2218. $str .= $iassign->iassign_ilmid . ',';
  2219. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2220. $str .= '"' . $ilm_activity->name . '"';
  2221. }
  2222. $str .= "\n";
  2223. }
  2224. $str = $fields . "\n" . $str;
  2225. header("Content-type: text/csv");
  2226. header("Content-disposition: attachment; filename=report.csv");
  2227. header("Pragma: no-cache");
  2228. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2229. header('Content-Length: ' . strlen($str));
  2230. header('Connection: close');
  2231. print $str;
  2232. flush();
  2233. } // function export_csv()
  2234. /// Display report of performance
  2235. function report () {
  2236. global $USER, $CFG, $DB, $OUTPUT;
  2237. $id = $this->cm->id;
  2238. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2239. if ($this->action != 'print') {
  2240. $title = get_string('report', 'iassign');
  2241. print $OUTPUT->header();
  2242. } // if ($this->action != 'print')
  2243. print $OUTPUT->box_start();
  2244. $this->view_legend_icons();
  2245. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2246. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2247. print $OUTPUT->box_end();
  2248. if ($this->action == 'print')
  2249. print '<table border=1 width="100%">' . "\n";
  2250. else
  2251. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2252. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2253. // $num = array();
  2254. $i = 1;
  2255. $num = array();
  2256. foreach ($iassign_list as $iassign) {
  2257. $test_exercise = "";
  2258. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2259. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2260. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2261. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2262. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2263. $num[$i] = new stdClass();
  2264. $num[$i]->name = $iassign->name;
  2265. $num[$i]->id = $i;
  2266. $num[$i]->iassignid = $iassign->id;
  2267. print ' <tr >' . "\n";
  2268. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2269. print "<td class=\"cell c0 actvity\">";
  2270. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2271. print ' </tr>' . "\n";
  2272. $i ++;
  2273. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2274. } // foreach ($iassign_list as $iassign)
  2275. print "</table>";
  2276. print "<p></p>";
  2277. if ($this->action == 'print')
  2278. print '<table border=1 width="100%">' . "\n";
  2279. else
  2280. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2281. $context = context_course::instance($this->course->id);
  2282. if ($i > 1) {
  2283. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2284. $params = array('shortname' => 'student');
  2285. $role = $DB->get_record_sql(
  2286. "SELECT s.id, s.shortname FROM {role} s " .
  2287. " WHERE s.shortname = :shortname", $params);
  2288. // $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");
  2289. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2290. $students = $DB->get_records_sql(
  2291. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2292. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2293. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2294. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2295. for ($j = 1; $j < $i; $j ++) {
  2296. $sum_iassign_correct[$j] = 0;
  2297. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2298. }
  2299. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2300. $sum_iassign = $j - 1;
  2301. print '</tr>' . "\n";
  2302. $total = 0;
  2303. $sum_student = 0;
  2304. $comment = iassign_icons::insert('comment_read');
  2305. $sum_comment = 0;
  2306. $sum_correct_iassign = array();
  2307. $sum_correct_student = array();
  2308. $USER->matrix_iassign = array();
  2309. if ($students) {
  2310. $w = 0;
  2311. foreach ($students as $tmp) {
  2312. $users_array[$w] = $tmp;
  2313. $w ++;
  2314. }
  2315. for ($x = 0; $x < $w; $x ++) {
  2316. print '<tr>' . "\n";
  2317. $sum_student ++;
  2318. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2319. print ' <td >' . $name . '</td>' . "\n";
  2320. $total_student = 0;
  2321. $tentativas = 0;
  2322. for ($j = 1; $j < $i; $j ++) {
  2323. $sum_comment = 0;
  2324. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2325. print ' <td valign="bottom" align="center">' . "\n";
  2326. if ($student_submissions) {
  2327. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2328. $tentativas = $student_submissions->experiment;
  2329. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2330. $params = array('iassign_submissionid' => $student_submissions->id);
  2331. $student_submissions_comment = $DB->get_record_sql(
  2332. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2333. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2334. if ($student_submissions_comment)
  2335. foreach ($student_submissions_comment as $tmp)
  2336. $sum_comment = $tmp;
  2337. // informations to previous activities
  2338. if ($j - 1 < 1 || $j == $i)
  2339. $iassign_previous = "-1";
  2340. else
  2341. $iassign_previous = $num[$j - 1]->iassignid;
  2342. if ($x - 1 < 0 || $x == $w)
  2343. $user_previous = "-1";
  2344. else
  2345. $user_previous = $users_array[$x - 1]->userid;
  2346. // next
  2347. if ($i - 1 > $j)
  2348. $iassign_next = $num[$j + 1]->iassignid;
  2349. else
  2350. $iassign_next = "-1";
  2351. if ($w - 1 > $x)
  2352. $user_next = $users_array[$x + 1]->userid;
  2353. else
  2354. $user_next = "-1";
  2355. $position = "&row= $x&column=$j";
  2356. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2357. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2358. $url .= $position;
  2359. // receiver=1 - message to teacher
  2360. // receiver=2 - message to student
  2361. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2362. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2363. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2364. $verify_message = $DB->get_record_sql(
  2365. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2366. "WHERE iassign_submissionid = :iassign_submissionid " .
  2367. " AND return_status= :return_status " .
  2368. " AND receiver= :receiver", $params);
  2369. if ($verify_message)
  2370. foreach ($verify_message as $tmp)
  2371. $sum_verify_message = $tmp;
  2372. if ($sum_verify_message > 0)
  2373. $comment = iassign_icons::insert('comment_unread');
  2374. else
  2375. $comment = iassign_icons::insert('comment_read');
  2376. if ($student_submissions->status == 3) {
  2377. $sum_iassign_correct[$j] ++;
  2378. $total_student ++;
  2379. $feedback = iassign_icons::insert('correct');
  2380. }
  2381. elseif ($student_submissions->status == 2) {
  2382. $feedback = iassign_icons::insert('incorrect');
  2383. }
  2384. elseif ($student_submissions->status == 1) {
  2385. $feedback = iassign_icons::insert('post');
  2386. }
  2387. elseif ($student_submissions->status == 0) {
  2388. $feedback = iassign_icons::insert('not_post');
  2389. }
  2390. if ($this->action != 'print') {
  2391. print '<table><tr>';
  2392. if ($tentativas > 0)
  2393. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2394. else
  2395. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2396. print '<td> &nbsp; </td>';
  2397. print '</tr>' . "\n";
  2398. if ($sum_comment > 0 && $sum_verify_message > 0)
  2399. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2400. else if ($sum_comment > 0)
  2401. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2402. print '</table>' . "\n";
  2403. }
  2404. if ($this->action == 'print')
  2405. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2406. } // if ($student_submissions)
  2407. else { // if ($student_submissions)
  2408. // informations to browse previous activities
  2409. if ($j - 1 < 1 || $j == $i)
  2410. $iassign_previous = "-1";
  2411. else
  2412. $iassign_previous = $num[$j - 1]->iassignid;
  2413. if ($x - 1 < 0 || $x == $w)
  2414. $user_previous = "-1";
  2415. else
  2416. $user_previous = $users_array[$x - 1]->userid;
  2417. // next
  2418. if ($i - 1 > $j)
  2419. $iassign_next = $num[$j + 1]->iassignid;
  2420. else
  2421. $iassign_next = "-1";
  2422. if ($w - 1 > $x)
  2423. $user_next = $users_array[$x + 1]->userid;
  2424. else
  2425. $user_next = "-1";
  2426. $position = "&row= $x&column=$j";
  2427. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2428. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2429. $url .= $position;
  2430. $feedback = iassign_icons::insert('not_post');
  2431. if ($this->action == 'print')
  2432. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2433. else {
  2434. print '<table><tr>';
  2435. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2436. print '<td> &nbsp; </td>';
  2437. print '</tr><tr>' . "\n";
  2438. print '<td> &nbsp;</td>';
  2439. if ($sum_comment > 0)
  2440. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2441. else
  2442. print '<td> &nbsp;</td>';
  2443. print '</tr></table>';
  2444. }
  2445. } // else if ($student_submissions)
  2446. $USER->matrix_iassign[$x][$j] = new stdClass();
  2447. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2448. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2449. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2450. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2451. if ($student_submissions)
  2452. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2453. else
  2454. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2455. print '</td>' . "\n";
  2456. } // for ($j=1; $j<$i; $j++)
  2457. $total = $total + $total_student;
  2458. $porcentagem = ($total_student / ($j - 1)) * 100;
  2459. if ($tentativas != 0 && $tentativas != null) {
  2460. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2461. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2462. }
  2463. else {
  2464. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2465. }
  2466. print '</tr>' . "\n";
  2467. $sum_correct_student[$sum_student] = new stdClass();
  2468. $sum_correct_student[$sum_student]->name = $name;
  2469. $sum_correct_student[$sum_student]->sum = $total_student;
  2470. } // for ($x = 0; $x < $w; $x ++)
  2471. for ($i = 1; $i < $j; $i ++) {
  2472. if (is_null($sum_iassign_correct[$i]))
  2473. $sum_iassign_correct[$i] = 0;
  2474. $sum_correct_iassign[$i] = new stdClass();
  2475. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2476. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2477. }
  2478. // print '</tr></table>' . "\n";
  2479. }
  2480. } // if ($i>1)
  2481. else {
  2482. print_string('no_activity', 'iassign');
  2483. }
  2484. print "</table>\n";
  2485. if ($this->action != 'print')
  2486. print $OUTPUT->footer();
  2487. die();
  2488. } // function report()
  2489. /// Display graphics of performance
  2490. function stats () {
  2491. global $USER, $CFG, $DB, $OUTPUT;
  2492. $id = $this->cm->id;
  2493. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2494. if ($this->action != 'printstats')
  2495. $title = get_string('graphic', 'iassign');
  2496. $num = array();
  2497. $sum_correct_iassign = array();
  2498. $sum_correct_student = array();
  2499. $sum_student = 0;
  2500. $i = 1;
  2501. foreach ($iassign_list as $iassign) {
  2502. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2503. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2504. $sum_iassign_correct[$i] = 0;
  2505. $num[$i] = new stdClass();
  2506. $num[$i]->name = $iassign->name;
  2507. $num[$i]->id = $i;
  2508. $num[$i]->iassignid = $iassign->id;
  2509. $i ++;
  2510. } // if ($iassign->type_iassign == 3)
  2511. } // foreach ($iassign_list as $iassign)
  2512. $sum_iassign = $i - 1;
  2513. $context = context_course::instance($this->course->id);
  2514. if ($i > 1) {
  2515. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2516. $params = array('shortname' => 'student');
  2517. $role = $DB->get_record_sql(
  2518. "SELECT s.id, s.shortname FROM {role} s " .
  2519. " WHERE s.shortname = :shortname", $params);
  2520. // $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");
  2521. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2522. $students = $DB->get_records_sql(
  2523. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2524. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2525. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2526. $total = 0;
  2527. $sum_student = 0;
  2528. $j = 0;
  2529. $sum_correct_iassign = array();
  2530. $sum_correct_student = array();
  2531. $sum_experiment = array();
  2532. if ($students) {
  2533. foreach ($students as $users) {
  2534. $sum_student ++;
  2535. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2536. // rows
  2537. $total_student = 0;
  2538. for ($j = 1; $j < $i; $j ++) {
  2539. $total_experiment = 0;
  2540. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2541. if ($student_submissions) {
  2542. if ($student_submissions->status == 3) {
  2543. $sum_iassign_correct[$j] ++;
  2544. $total_student ++;
  2545. } // if ($student_submissions->status == 3)
  2546. $total_experiment += $student_submissions->experiment;
  2547. }
  2548. $sum_experiment[$j] = $total_experiment;
  2549. } // for ($j=1; $j<$i; $j++)
  2550. $total = $total + $total_student;
  2551. $sum_correct_student[$sum_student] = new stdClass();
  2552. $sum_correct_student[$sum_student]->name = $name;
  2553. $sum_correct_student[$sum_student]->sum = $total_student;
  2554. } // foreach ($students as $users)
  2555. }
  2556. for ($i = 1; $i < $j; $i ++) {
  2557. if (is_null($sum_iassign_correct[$i]))
  2558. $sum_iassign_correct[$i] = 0;
  2559. $sum_correct_iassign[$i] = new stdClass();
  2560. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2561. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2562. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2563. } // for ($i = 1; $i < $j; $i++)
  2564. } // if ($i > 1)
  2565. if ($this->action != 'printstats') {
  2566. $title = get_string('graphic', 'iassign');
  2567. print $OUTPUT->header();
  2568. $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>";
  2569. $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>";
  2570. print '<table width=100%><tr>';
  2571. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2572. print '<td width=15% align="right">' . $link_report . '</td>';
  2573. print '</td></tr></table>' . "\n";
  2574. print "<br><br>";
  2575. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2576. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2577. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2578. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2579. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2580. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2581. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2582. print '</tr>' . "\n";
  2583. $sum_correct = 0;
  2584. if ($sum_correct_iassign) {
  2585. foreach ($sum_correct_iassign as $iassign) {
  2586. if (is_null($iassign->experiment))
  2587. $iassign->experiment = 0;
  2588. $bar = "";
  2589. $sum = $iassign->sum;
  2590. $percent = ($sum / $sum_student) * 100;
  2591. $text = number_format($percent, 1) . '%';
  2592. $sum_correct += $sum;
  2593. if ($sum > 0) {
  2594. for ($i = 1; $i < $percent * 2; $i ++)
  2595. $bar .= iassign_icons::insert('hbar_blue');
  2596. $bar .= iassign_icons::insert('hbar_blue_r');
  2597. } // if ($sum > 0)
  2598. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2599. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2600. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2601. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2602. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2603. print '</tr>' . "\n";
  2604. } // foreach ($sum_correct_iassign as $iassign)
  2605. }
  2606. print "</table>";
  2607. print "<br><br>";
  2608. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2609. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2610. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2611. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2612. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2613. print '</tr>' . "\n";
  2614. $sum_correct = 0;
  2615. foreach ($sum_correct_student as $student) {
  2616. $bar = "";
  2617. $sum = $student->sum;
  2618. $percent = ($sum / $sum_iassign) * 100;
  2619. $text = number_format($percent, 1) . '%';
  2620. $sum_correct += $sum;
  2621. if ($sum > 0) {
  2622. for ($i = 1; $i < $percent * 2; $i ++)
  2623. $bar .= iassign_icons::insert('hbar_blue');
  2624. $bar .= iassign_icons::insert('hbar_blue_r');
  2625. } // if ($sum > 0)
  2626. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2627. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2628. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2629. print '</tr>' . "\n";
  2630. } // foreach ($sum_correct_student as $student)
  2631. print "</table>\n";
  2632. print "<br><br>\n";
  2633. $var = 0;
  2634. $cv = 0;
  2635. $dv = 0;
  2636. $avg = 0;
  2637. if ($sum_correct_student) {
  2638. $avg = $sum_correct / $sum_student;
  2639. if ($avg > 0) {
  2640. foreach ($sum_correct_student as $student)
  2641. $var += pow($student->sum - $avg, 2);
  2642. $var = $var / $sum_student;
  2643. $dv = sqrt($var);
  2644. $cv = ($dv / $avg) * 100;
  2645. }
  2646. }
  2647. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2648. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2649. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2650. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2651. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2652. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2653. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2654. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2655. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2656. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2657. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2658. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2659. print "</table>\n";
  2660. print $OUTPUT->footer();
  2661. } else {
  2662. print "<STYLE TYPE='text/css'>
  2663. <!--
  2664. .boldtable {
  2665. font-family:sans-serif;
  2666. font-size:10pt;
  2667. }
  2668. -->
  2669. </STYLE>\n";
  2670. print '<table border=1 width=100%>' . "\n";
  2671. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2672. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2673. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2674. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2675. print '</tr>' . "\n";
  2676. $sum_correct = 0;
  2677. foreach ($sum_correct_iassign as $iassign) {
  2678. $bar = "";
  2679. $sum = $iassign->sum;
  2680. $percent = ($sum / $sum_student) * 100;
  2681. $text = number_format($percent, 1) . '%';
  2682. $sum_correct += $sum;
  2683. if ($sum > 0) {
  2684. for ($i = 1; $i < $percent * 2; $i ++)
  2685. $bar .= iassign_icons::insert('hbar_blue');
  2686. $bar .= iassign_icons::insert('hbar_blue_r');
  2687. } // if ($sum > 0)
  2688. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2689. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2690. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2691. print '</tr>' . "\n";
  2692. } // foreach ($sum_correct_iassign as $iassign)
  2693. print "</table>";
  2694. print "<br><br>";
  2695. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2696. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2697. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2698. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2699. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2700. print '</tr>' . "\n";
  2701. $sum_correct = 0;
  2702. foreach ($sum_correct_student as $student) {
  2703. $bar = "";
  2704. $sum = $student->sum;
  2705. $percent = ($sum / $sum_iassign) * 100;
  2706. $text = number_format($percent, 1) . '%';
  2707. $sum_correct += $sum;
  2708. if ($sum > 0) {
  2709. for ($i = 1; $i < $percent * 2; $i ++)
  2710. $bar .= iassign_icons::insert('hbar_blue');
  2711. $bar .= iassign_icons::insert('hbar_blue_r');
  2712. } // if ($sum > 0)
  2713. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2714. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2715. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2716. print '</tr>' . "\n";
  2717. } // foreach ($sum_correct_student as $student)
  2718. print "</table>\n";
  2719. print "<br/><br/>\n";
  2720. $var = 0;
  2721. $cv = 0;
  2722. $dv = 0;
  2723. $avg = 0;
  2724. if ($sum_correct_student) {
  2725. $avg = $sum_correct / $sum_student;
  2726. if ($avg > 0) {
  2727. foreach ($sum_correct_student as $student)
  2728. $var += pow($student->sum - $avg, 2);
  2729. $var = $var / $sum_student;
  2730. $dv = sqrt($var);
  2731. $cv = ($dv / $avg) * 100;
  2732. }
  2733. }
  2734. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2735. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2736. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2737. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2738. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2739. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2740. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2741. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2742. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2743. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2744. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2745. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2746. print "</table>\n";
  2747. } // if ($this->action != 'printstats')
  2748. die();
  2749. }
  2750. /// Display graphics of performance for students
  2751. function stats_students () {
  2752. global $USER, $CFG, $DB, $OUTPUT;
  2753. $id = $this->cm->id;
  2754. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2755. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2756. $title = get_string('results', 'iassign');
  2757. $sum_correct = 0;
  2758. $sum_incorrect = 0;
  2759. $sum_post = 0;
  2760. $sum_nopost = 0;
  2761. $sum_iassign = count($iassign_statement_list);
  2762. $bar_nopost = "";
  2763. $bar_correct = "";
  2764. $bar_incorrect = "";
  2765. $bar_post = "";
  2766. $text_nopost = "";
  2767. $text_correct = "";
  2768. $text_incorrect = "";
  2769. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2770. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2771. if ($iassign_submission) {
  2772. if ($iassign_submission->status == 3)
  2773. $sum_correct ++;
  2774. elseif ($iassign_submission->status == 2)
  2775. $sum_incorrect ++;
  2776. elseif ($iassign_submission->status == 1)
  2777. $sum_post ++;
  2778. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2779. $sum_nopost ++;
  2780. } // if ($iassign_submission)
  2781. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2782. if ($sum_iassign > 0) {
  2783. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2784. $text_correct = number_format($percent_correct, 1) . '%';
  2785. }
  2786. if ($sum_correct > 0) {
  2787. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2788. $bar_correct .= iassign_icons::insert('hbar_green');
  2789. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2790. } // if ($sum_correct > 0)
  2791. if ($sum_iassign > 0) {
  2792. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2793. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2794. }
  2795. if ($sum_incorrect > 0) {
  2796. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2797. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2798. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2799. } // if ($sum_incorrect > 0)
  2800. if ($sum_iassign > 0) {
  2801. $percent_post = ($sum_post / $sum_iassign) * 100;
  2802. $text_post = number_format($percent_post, 1) . '%';
  2803. }
  2804. if ($sum_post > 0) {
  2805. for ($i = 1; $i < $percent_post * 2; $i ++)
  2806. $bar_post .= iassign_icons::insert('hbar_blue');
  2807. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2808. } // if ($sum_post > 0)
  2809. if ($sum_iassign > 0) {
  2810. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2811. $text_nopost = number_format($percent_nopost, 1) . '%';
  2812. }
  2813. if ($sum_nopost > 0) {
  2814. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2815. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2816. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2817. } // if ($sum_nopost > 0)
  2818. print $OUTPUT->header();
  2819. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2820. print '<table width=100%><tr>';
  2821. print '<td align="right">' . $link_return . '</td>' . "\n";
  2822. print '</td></tr></table>' . "\n";
  2823. print "<br/><br/>\n";
  2824. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2825. print '<tr><th colspan=3 class="header c1">' . "\n";
  2826. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2827. // $imagetext = '');
  2828. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2829. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2830. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2831. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2832. print '</tr>' . "\n";
  2833. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2834. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2835. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2836. print '</tr>' . "\n";
  2837. if ($sum_post) {
  2838. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2839. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2840. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2841. print '</tr>' . "\n";
  2842. } // if ($sum_post)
  2843. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2844. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2845. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2846. print '</tr>' . "\n";
  2847. print "</table>";
  2848. print "<br><br>";
  2849. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2850. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2851. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2852. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2853. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2854. $sum_grade = 0;
  2855. $sum_grade_student = 0;
  2856. $avg = 0;
  2857. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2858. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2859. if (!$iassign_submission) {
  2860. $iassign_submission = new stdClass();
  2861. $iassign_submission->grade = 0;
  2862. }
  2863. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2864. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2865. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2866. print '</tr>' . "\n";
  2867. $sum_grade += $iassign_statement_activity_item->grade;
  2868. $sum_grade_student += $iassign_submission->grade;
  2869. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2870. if ($sum_grade > 0)
  2871. $avg = $sum_grade_student / $sum_grade * 100;
  2872. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2873. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2874. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2875. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2876. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2877. print "</table>";
  2878. print $OUTPUT->footer();
  2879. die();
  2880. } // function stats_students()
  2881. /// Display page of iAssign's activity
  2882. function view_iassigns () {
  2883. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2884. $id = $this->cm->id;
  2885. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2886. $notice = optional_param('notice', '', PARAM_TEXT);
  2887. if (strpos($notice, 'error'))
  2888. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2889. else if ($notice != '')
  2890. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2891. print $OUTPUT->box_start();
  2892. print '<table width=100% border=0><tr>' . "\n";
  2893. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2894. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2895. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2896. $link_add = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=add&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('add_iassign') . get_string('add_iassign', 'iassign') . "</a>";
  2897. $link_report = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('view_report') . get_string('report', 'iassign') . "</a>";
  2898. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2899. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2900. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2901. // Has capability to see "report": teacher or up
  2902. print '<td width=10% align="left">' . "\n";
  2903. print $link_help;
  2904. print '</td>' . "\n";
  2905. print '<td width=10% align="left">' . "\n";
  2906. print $link_report;
  2907. print '</td>' . "\n";
  2908. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2909. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2910. print '<td width=15% align="left">' . "\n";
  2911. print $link_add;
  2912. print "</td>\n";
  2913. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2914. //print '</tr></table>' . "\n";
  2915. print '<div style="float: right;">';
  2916. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2917. if ($iassign_list) {
  2918. print '<td align="right">' . "\n";
  2919. // $USER->iassignEdit == 0 view 'Turn editing off'
  2920. // $USER->iassignEdit == 1 view 'Turn editing on'
  2921. if (!isset($USER->iassignEdit))
  2922. $USER->iassignEdit = 0;
  2923. if ($USER->iassignEdit == 0) {
  2924. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2925. $botton = 1;
  2926. } // if ($USER->iassignEdit == 0)
  2927. elseif ($USER->iassignEdit == 1) {
  2928. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2929. $botton = 0;
  2930. } // elseif ($USER->iassignEdit == 1)
  2931. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2932. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2933. print " <input type=submit value='$bottonEdit_message'/>\n";
  2934. print "</form>\n";
  2935. print "</td>\n";
  2936. } // if ($iassign_list)
  2937. }
  2938. print '</tr></table>' . "\n";
  2939. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2940. // $this->view_legend_icons();
  2941. print $OUTPUT->box_end();
  2942. $iassign_array_exercise = array();
  2943. $i_exercise = 0;
  2944. $iassign_array_test = array();
  2945. $i_test = 0;
  2946. $iassign_array_example = array();
  2947. $i_example = 0;
  2948. $iassign_array_general = array();
  2949. $i_general = 0;
  2950. if ($iassign_list) {
  2951. if ($this->iassign->activity_group == 0) {
  2952. foreach ($iassign_list as $iassign) {
  2953. $iassign_array_general[$i_general] = $iassign;
  2954. $i_general ++;
  2955. }
  2956. } // if ($this->iassign->activity_group == 0)
  2957. else {
  2958. foreach ($iassign_list as $iassign) {
  2959. if ($iassign->type_iassign == 3) {
  2960. $iassign_array_exercise[$i_exercise] = $iassign;
  2961. $i_exercise ++;
  2962. } // if ($iassign->type_iassign == 3)
  2963. if ($iassign->type_iassign == 2) {
  2964. $iassign_array_test[$i_test] = $iassign;
  2965. $i_test ++;
  2966. } // if ($iassign->type_iassign == 2)
  2967. if ($iassign->type_iassign == 1) {
  2968. $iassign_array_example[$i_example] = $iassign;
  2969. $i_example ++;
  2970. } // if ($iassign->type_iassign == 1)
  2971. }
  2972. }
  2973. if ($iassign_array_exercise) {
  2974. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  2975. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2976. }
  2977. if ($iassign_array_test) {
  2978. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  2979. $this->show_iassign($title, $iassign_array_test, $i_test);
  2980. }
  2981. if ($iassign_array_example) {
  2982. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  2983. $this->show_iassign($title, $iassign_array_example, $i_example);
  2984. }
  2985. if ($iassign_array_general) {
  2986. $title = "";
  2987. $this->show_iassign($title, $iassign_array_general, $i_general);
  2988. }
  2989. } else { // if ($iassign_list)
  2990. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2991. }
  2992. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2993. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2994. print $OUTPUT->box_start();
  2995. print '<table width=100% border=0><tr>' . "\n";
  2996. print '<td width=10% align="left">' . "\n";
  2997. print $link_report;
  2998. print '</td>' . "\n";
  2999. print '</tr></table>' . "\n";
  3000. print $OUTPUT->box_end();
  3001. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3002. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3003. print $OUTPUT->box_start();
  3004. print '<table width=100% border=0><tr>' . "\n";
  3005. print '<td align="left">' . "\n";
  3006. print $link_add;
  3007. print '</td>' . "\n";
  3008. print '</tr></table>' . "\n";
  3009. print $OUTPUT->box_end();
  3010. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3011. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3012. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3013. $this->view_legend_icons();
  3014. } // function view_iassigns()
  3015. /// Display all iAssigns
  3016. function show_iassign ($title, $iassign_array, $i) {
  3017. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3018. $id = $this->cm->id;
  3019. print $OUTPUT->box_start();
  3020. print " <script type='text/javascript'>
  3021. //<![CDATA[
  3022. function validate_move () {
  3023. var radios = document.getElementsByName('iassign_destiny');
  3024. var formValid = false;
  3025. //alert('aqui validate_move()');
  3026. var i = 0;
  3027. while (!formValid && i < radios.length) {
  3028. if (radios[i].checked) formValid = true;
  3029. i++;
  3030. }
  3031. if (!formValid) {
  3032. document.getElementById('move_dest').classList.add('alert-danger');
  3033. }
  3034. return formValid;
  3035. }
  3036. var modal;
  3037. function load_move(id_ias) {
  3038. document.form_move_activity.iassign_current.value = id_ias;
  3039. modal.style.display = 'block';
  3040. var radios = document.getElementsByName('iassign_destiny');
  3041. var i = 0;
  3042. while (i < radios.length) {
  3043. radios[i].checked = false;
  3044. i++;
  3045. }
  3046. document.getElementById('move_dest').classList.remove('alert-danger');
  3047. }
  3048. function load_modal_elements() {
  3049. modal = document.getElementById('myModal');
  3050. var span = document.getElementById('close_modal');
  3051. span.onclick = function() {
  3052. modal.style.display = 'none';
  3053. }
  3054. window.onclick = function(event) {
  3055. if (event.target == modal) {
  3056. modal.style.display = 'none';
  3057. }
  3058. }
  3059. }
  3060. window.onload = load_modal_elements;
  3061. //]]>
  3062. </script>\n";
  3063. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3064. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3065. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3066. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3067. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3068. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3069. <input type='hidden' name='iassign_current' value='' />";
  3070. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3071. $section = $course_sections[0];
  3072. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3073. for ($k = 0; $k < count($ids_sections); $k++) {
  3074. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3075. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3076. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3077. if ($c_cm) {
  3078. if ($ccm->instance == $c_cm->instance) {
  3079. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3080. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3081. }
  3082. else {
  3083. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3084. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3085. }
  3086. }
  3087. }
  3088. $radio_buttons .= "</ul>";
  3089. }
  3090. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3091. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3092. </form>
  3093. </div></div> </div></div>\n";
  3094. print " <style>.modal {
  3095. display: none;
  3096. position: fixed;
  3097. z-index: 1;
  3098. left: 0;
  3099. top: 0;
  3100. width: 100%;
  3101. height: 100%;
  3102. overflow: scroll;
  3103. background-color: rgb(0,0,0);
  3104. background-color: rgba(0,0,0,0.4);
  3105. }
  3106. .modal-content {
  3107. background-color: #fefefe;
  3108. margin: 15% auto;
  3109. padding: 10px 10px;
  3110. border: 1px solid #888;
  3111. width: 50%;
  3112. }
  3113. #close_modal {
  3114. color: #aaa;
  3115. float: right;
  3116. font-size: 28px;
  3117. font-weight: bold;
  3118. margin-top: -15px;
  3119. margin-right: -3px;
  3120. }
  3121. #close_modal:hover,
  3122. #close_modal:focus {
  3123. color: black;
  3124. text-decoration: none;
  3125. cursor: pointer;
  3126. }
  3127. #modal_title {
  3128. min-height: 3rem;
  3129. color: initial;
  3130. background: initial;
  3131. font-size: 1.5rem;
  3132. line-height: 1.5;
  3133. padding: 15px;
  3134. border-bottom: 1px solid #e5e5e5;
  3135. }
  3136. .input_move {
  3137. width: 90%;
  3138. padding: 2px;
  3139. }
  3140. .input_move:hover {
  3141. background: #eff0ef;
  3142. }
  3143. </style>";
  3144. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3145. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3146. for ($j = 0; $j < $i; $j ++) {
  3147. $iassign_current = $iassign_array[$j]->id;
  3148. // receiver=1 - message to teacher
  3149. // receiver=2 - message to student
  3150. $sum_comment = 0;
  3151. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3152. foreach ($iassign_submissions as $iassign_submission) {
  3153. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3154. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3155. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3156. if ($verify_message)
  3157. foreach ($verify_message as $tmp)
  3158. $sum_comment += $tmp;
  3159. } // foreach ($iassign_submissions as $iassign_submission)
  3160. if ($sum_comment == 0)
  3161. $comment_unread = "";
  3162. else {
  3163. $comment_unread_message = get_string('comment_unread', 'iassign');
  3164. if ($sum_comment == 1)
  3165. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3166. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3167. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3168. }
  3169. if ($j == $i - 1)
  3170. $iassign_down = $iassign_array[$j]->id;
  3171. else
  3172. $iassign_down = $iassign_array[$j + 1]->id;
  3173. if ($j > 0)
  3174. $iassign_up = $iassign_array[$j - 1]->id;
  3175. else
  3176. $iassign_up = $iassign_array[$j]->id;
  3177. if ($iassign_array[$j]->visible == 0)
  3178. $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>";
  3179. else
  3180. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3181. $links .= $comment_unread;
  3182. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3183. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3184. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3185. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3186. if ($j==0) // first activity
  3187. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3188. else
  3189. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3190. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3191. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3192. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3193. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3194. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3195. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3196. if (count($iassign_array) > 1) {
  3197. if ($j == 0)
  3198. $links .= $link_down;
  3199. elseif ($j == $i - 1)
  3200. $links .= $link_up;
  3201. else
  3202. $links .= $link_up . $link_down;
  3203. } // if (count($iassign_array) > 1)
  3204. $links .= $link_edit . $link_delete;
  3205. if ($iassign_array[$j]->visible == 0)
  3206. $links .= $link_visible_show;
  3207. else
  3208. $links .= $link_visible_hide;
  3209. $links .= $link_duplicate_activity . $link_move_activity;
  3210. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3211. print '<p>' . $links . '</p>' . "\n";
  3212. }
  3213. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3214. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3215. print '<table width=100% ><tr>' . "\n";
  3216. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3217. print '</tr></table>' . "\n";
  3218. for ($j = 0; $j < $i; $j ++) {
  3219. $icon_status = "";
  3220. $icon_comment = "";
  3221. if ($iassign_array[$j]->visible == 1) {
  3222. $iassign_current = $iassign_array[$j]->id;
  3223. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3224. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3225. $icon_status = "";
  3226. $icon_comment = "";
  3227. if ($iassign_submission) {
  3228. // receiver=1 - message to teacher
  3229. // receiver=2 - message to student
  3230. // $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");
  3231. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3232. $verify_message = $DB->get_record_sql(
  3233. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3234. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3235. if ($verify_message)
  3236. foreach ($verify_message as $tmp)
  3237. $sum_comment = $tmp;
  3238. if ($sum_comment > 0) {
  3239. $comment_unread_message = get_string('comment_unread', 'iassign');
  3240. if ($sum_comment == 1)
  3241. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3242. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3243. }
  3244. // $icon_comment = iassign_icons::insert('comment_unread');
  3245. if ($iassign_array[$j]->type_iassign == 3) {
  3246. if ($iassign_array[$j]->show_answer == 1) {
  3247. if ($iassign_submission->status == 3)
  3248. $icon_status = iassign_icons::insert('correct');
  3249. elseif ($iassign_submission->status == 2)
  3250. $icon_status = iassign_icons::insert('incorrect');
  3251. elseif ($iassign_submission->status == 1)
  3252. $icon_status = iassign_icons::insert('post');
  3253. elseif ($iassign_submission->status == 0)
  3254. $icon_status = iassign_icons::insert('not_post');
  3255. } // if ($iassign_array[$j]->show_answer==1)
  3256. else {
  3257. if ($iassign_submission->status == 0)
  3258. $icon_status = iassign_icons::insert('not_post');
  3259. else
  3260. $icon_status = iassign_icons::insert('post');
  3261. }
  3262. } // if ($iassign_array[$j]->type_iassign == 3)
  3263. } // if ($iassign_submission)
  3264. elseif ($iassign_array[$j]->type_iassign == 3) {
  3265. $icon_status = iassign_icons::insert('not_post');
  3266. } // if ($iassign_array[$j]->type_iassign == 3)
  3267. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3268. } // if ($iassign_array[$j]->visible == 1)
  3269. } // for ($j = 0; $j < $i; $j++)
  3270. } else if (isguestuser()) {
  3271. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3272. print '<table width=100% ><tr>' . "\n";
  3273. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3274. print '</tr></table>' . "\n";
  3275. for ($j = 0; $j < $i; $j ++) {
  3276. $icon_status = "";
  3277. $icon_comment = "";
  3278. if ($iassign_array[$j]->visible == 1) {
  3279. $iassign_current = $iassign_array[$j]->id;
  3280. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3281. print '<p>' . $links . '</p>' . "\n";
  3282. } // if ($iassign_array[$j]->visible == 1)
  3283. }
  3284. }
  3285. print $OUTPUT->box_end();
  3286. } // function show_iassign($title, $iassign_array, $i)
  3287. /// Show message of return
  3288. function return_home_course ($message) {
  3289. //D global $DB, $OUTPUT;
  3290. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3291. //D echo $OUTPUT->box_start();
  3292. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3293. //D echo '<tr><td align="left"><strong>' . "\n";
  3294. //D print_string($message, 'iassign');
  3295. //D echo '</strong></td>' . "\n";
  3296. //D echo '<td width=20% align="right">' . "\n";
  3297. //D echo $link_return;
  3298. //D echo '</td></tr></table>' . "\n";
  3299. //D echo $OUTPUT->box_end();
  3300. //D // echo $OUTPUT->footer();
  3301. redirect(new moodle_url($this->return . '&notice=' . $message));
  3302. exit;
  3303. }
  3304. /// Search comment of activity
  3305. function search_comment_submission ($iassign_submissionid) {
  3306. global $USER, $DB, $OUTPUT, $COURSE;
  3307. // $context = context_course::instance($COURSE->id);
  3308. $colorEdit1 = "#a7bede"; // "#dce7ec"
  3309. $colorEdit2 = "#b7ceee";
  3310. $has_capability = 0;
  3311. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3312. $text = "";
  3313. if ($comments) {
  3314. $even = 1;
  3315. foreach ($comments as $tmp) {
  3316. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3317. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3318. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3319. // $text .= $tmp->comment . "</td></tr>";
  3320. //} else {
  3321. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3322. if ($even) {
  3323. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3324. $even = 0;
  3325. } else {
  3326. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3327. $even = 1;
  3328. }
  3329. $text .= $tmp->comment . "</td></tr>\n";
  3330. } // foreach ($comments as $tmp)
  3331. }
  3332. return $text;
  3333. }
  3334. /// Update comment of activity
  3335. function update_comment ($iassign_submissionid) {
  3336. global $USER, $DB, $OUTPUT;
  3337. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3338. $receiver = 1; // student message to teacher
  3339. else
  3340. $receiver = 2; // teacher message to student
  3341. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3342. if ($verify_message) {
  3343. foreach ($verify_message as $message) {
  3344. if ($message->receiver == $receiver) {
  3345. $newentry = new stdClass();
  3346. $newentry->id = $message->id;
  3347. $newentry->return_status = 1;
  3348. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3349. print_error('error_update', 'iassign');
  3350. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3351. } // if ($message->receiver == $receiver)
  3352. // Trigger module viewed event.
  3353. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3354. 'objectid' => $this->iassign->id,
  3355. 'context' => $this->context
  3356. ));
  3357. $event->add_record_snapshot('course', $this->course);
  3358. $event->trigger();
  3359. } // foreach ($verify_message as $message)
  3360. }
  3361. }
  3362. /// Record comment of activity
  3363. function write_comment_submission () {
  3364. global $USER, $CFG, $DB;
  3365. $id = $this->cm->id;
  3366. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3367. $row = optional_param('row', 0, PARAM_INT);
  3368. $column = optional_param('column', 0, PARAM_INT);
  3369. $sum_comment = 0;
  3370. $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);
  3371. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3372. $str1 = trim($submission_comment);
  3373. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3374. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3375. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3376. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3377. $receiver = 1; // student message to teacher
  3378. $this->action = 'view';
  3379. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3380. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3381. } else {
  3382. $receiver = 2; // teacher message to student
  3383. $this->action = 'viewsubmission';
  3384. //D $tousers = array(); //MOOC 2016
  3385. //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
  3386. }
  3387. //MOOC 2016: foi p/ 15 linhas acima:
  3388. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3389. if (!$iassign_submission) {
  3390. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3391. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3392. $this->iassign_submission_current = $id_submission;
  3393. } else {
  3394. $id_submission = $iassign_submission->id;
  3395. } // if (!$iassign_submission)
  3396. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3397. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3398. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3399. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3400. $comments = $DB->get_record_sql(
  3401. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3402. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3403. if ($comments)
  3404. foreach ($comments as $tmp)
  3405. $sum_comment = $tmp;
  3406. if ($sum_comment == 0) {
  3407. $newentry = new stdClass();
  3408. $newentry->iassign_submissionid = $id_submission;
  3409. $newentry->comment_authorid = $USER->id;
  3410. $newentry->timecreated = time();
  3411. $newentry->comment = $submission_comment;
  3412. $newentry->receiver = $receiver;
  3413. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3414. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3415. //T $eventdata = new stdClass();
  3416. //T $eventdata->component = 'mod_iassign'; //your component name
  3417. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3418. //T $eventdata->userfrom = $USER;
  3419. //T $eventdata->userto = $touser;
  3420. //T $eventdata->subject = "Teste de Subject";
  3421. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3422. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3423. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3424. //T $eventdata->smallmessage = "Teste de Mensagem";
  3425. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3426. //T // alteracao tulio faria
  3427. //T //message_send($eventdata);
  3428. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3429. // Trigger module viewed event.
  3430. $event = \mod_iassign\event\submission_comment_created::create(array(
  3431. 'objectid' => $this->iassign->id,
  3432. 'context' => $this->context
  3433. ));
  3434. $event->add_record_snapshot('course', $this->course);
  3435. $event->trigger();
  3436. }
  3437. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3438. // if ($this->action=='viewsubmission') {
  3439. // echo $OUTPUT->header();
  3440. // $this->return_last('confirm_add_comment', $link_return);
  3441. // die;
  3442. // }
  3443. return true;
  3444. } // function write_comment_submission()
  3445. /// Writes a new submission
  3446. // The first student answer is under 'function get_answer()'
  3447. function new_submission ($iassignid, $id_user, $receiver) {
  3448. global $USER, $DB, $OUTPUT;
  3449. $newentry = new stdClass();
  3450. $newentry->iassign_statementid = $iassignid;
  3451. $newentry->userid = $id_user;
  3452. $newentry->timecreated = time();
  3453. $newentry->timemodified = time();
  3454. $newentry->answer = 0; // student only submit message
  3455. if ($receiver == 2) // teacher message to student (write id teacher)
  3456. $newentry->teacher = $USER->id;
  3457. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3458. return_home_course('error_insert_submissions');
  3459. else {
  3460. // Trigger module view event
  3461. $event = \mod_iassign\event\submission_created::create(array(
  3462. 'objectid' => $this->iassign->id,
  3463. 'context' => $this->context
  3464. ));
  3465. $event->add_record_snapshot('course', $this->course);
  3466. $event->trigger();
  3467. }
  3468. return $newentry->id;
  3469. }
  3470. /// Return to a specific address of page
  3471. function return_last ($message, $link_return) {
  3472. global $DB, $OUTPUT;
  3473. print $OUTPUT->box_start();
  3474. print '<table width=100% border=0 valign="top">' . "\n";
  3475. print '<tr><td align="left"><strong>' . "\n";
  3476. print_string($message, 'iassign');
  3477. print '</strong></td>' . "\n";
  3478. print '<td width=20% align="right">' . "\n";
  3479. print $link_return;
  3480. print '</td></tr></table>' . "\n";
  3481. print $OUTPUT->box_end();
  3482. print $OUTPUT->footer();
  3483. die();
  3484. } // function return_last($message, $link_return)
  3485. } // class iassign
  3486. /// Class for manage activities
  3487. class activity {
  3488. var $activity;
  3489. /// Constructor of class.
  3490. // @param int $id Id of activity
  3491. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3492. //D public function activity($id) { self::__construct($id); }
  3493. function __construct ($id) {
  3494. global $DB;
  3495. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3496. if (empty($this->activity))
  3497. $this->activity = null;
  3498. }
  3499. /// Get an activity
  3500. // @return NULL
  3501. function get_activity () {
  3502. if ($this->activity != null)
  3503. return $this->activity;
  3504. else
  3505. return null;
  3506. }
  3507. /// Delete interactive activities
  3508. function delete ($return) {
  3509. global $USER, $CFG, $DB, $OUTPUT;
  3510. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3511. $output = $OUTPUT->header();
  3512. $output .= $OUTPUT->box_start();
  3513. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3514. if ($iassign_submission_currents) {
  3515. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3516. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3517. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3518. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3519. $output .= $OUTPUT->box_end();
  3520. $output .= $OUTPUT->footer();
  3521. print $output;
  3522. die();
  3523. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3524. } // if ($iassign_submission_currents)
  3525. else
  3526. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3527. $output .= '<table width=50% border=0>';
  3528. $output .= '<tr valign="top"><td>';
  3529. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3530. $output .= '</td><td>';
  3531. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3532. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3533. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3534. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3535. $output .= "</form>\n";
  3536. $output .= '</td><td>';
  3537. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3538. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3539. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3540. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3541. $output .= "</form>\n";
  3542. $output .= '</td></tr></table>' . "\n";
  3543. $output .= $OUTPUT->box_end();
  3544. $output .= $OUTPUT->footer();
  3545. print $output;
  3546. } // function delete($return)
  3547. /// Function for confirm the delete of activity
  3548. // @param String $return Url of return
  3549. // @param Object $iassign Object content an activity
  3550. function deleteyes ($return, $iassign) {
  3551. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3552. $msg = '';
  3553. if (!empty($this->activity->id)) {
  3554. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3555. if ($iassign_submission_currents) {
  3556. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3557. foreach ($iassign_submission_currents as $iassign_submission)
  3558. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3559. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3560. } // if ($iassign_submission_currents)
  3561. }
  3562. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3563. // Remove all files associated to this activity:
  3564. $fs = get_file_storage();
  3565. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  3566. $this->delete_calendar($this->activity->id);
  3567. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3568. iassign::update_grade_iassign($this->activity->iassignid);
  3569. if ($delete_iassign_current) {
  3570. $iassign->return_home_course('confirm_delete_iassign');
  3571. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3572. } else {
  3573. $iassign->return_home_course('error_confirm_delete_iassign');
  3574. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3575. }
  3576. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3577. }
  3578. }
  3579. /// Changes position of activities (between those inside a group of interactive activities)
  3580. // @param $move_action = must be "up" or "down"
  3581. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3582. function move_iassign ($move_action, $target, $return) {
  3583. global $DB, $OUTPUT;
  3584. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3585. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3586. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3587. if ($move_action=="firstdown") {
  3588. $final_position_source = 2;
  3589. $final_position_target = 1;
  3590. }
  3591. else
  3592. if ($move_action=="down") {
  3593. $final_position_target = $this->activity->position;
  3594. $final_position_source = $final_position_target + 1;
  3595. }
  3596. else
  3597. if ($move_action=="up") {
  3598. $final_position_target = $this->activity->position;
  3599. $final_position_source = $final_position_target - 1;
  3600. }
  3601. else { // error:
  3602. print_error('error_update_move_iassign', 'iassign');
  3603. exit;
  3604. }
  3605. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3606. $newentry->id = $this->activity->id; // ID of the "source activity"
  3607. $newentry->position = $final_position_source;
  3608. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3609. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3610. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3611. print_error('error_update_move_iassign', 'iassign');
  3612. }
  3613. else { // first update performed successfully
  3614. $newentry->id = $iassign_target->id;
  3615. $newentry->position = $final_position_target;
  3616. if (!$DB->update_record('iassign_statement', $newentry))
  3617. print_error('error_update_move_iassign', 'iassign');
  3618. }
  3619. redirect($return);
  3620. }
  3621. /// Enable or disable the display of interactive activities
  3622. function visible_iassign ($return) {
  3623. global $DB;
  3624. $newentry = new stdClass();
  3625. $newentry->id = $this->activity->id;
  3626. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3627. if (!$DB->update_record('iassign_statement', $newentry))
  3628. print_error('error_update_visible_iassign', 'iassign');
  3629. redirect($return);
  3630. }
  3631. /// Add news interactive activities (register in table 'iassign_statement')
  3632. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3633. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3634. function new_iassign ($param) {
  3635. global $DB;
  3636. $newentry = new stdClass();
  3637. $newentry->iassignid = $param->iassignid;
  3638. $newentry->name = $param->name;
  3639. $newentry->type_iassign = $param->type_iassign;
  3640. $newentry->store_all_submissions = $param->store_all_submissions;
  3641. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3642. $proposition = $param->proposition;
  3643. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3644. else $proposition_text = $proposition;
  3645. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3646. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3647. //TODO Then get it directly from the form data $_POST!
  3648. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3649. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3650. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3651. $newentry->author_name = $param->author_name;
  3652. $newentry->author_modified_name = $param->author_modified_name;
  3653. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3654. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3655. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3656. $newentry->grade = $param->grade;
  3657. $newentry->timemodified = time();
  3658. $newentry->timecreated = time();
  3659. if ($param->type_iassign == 1) {
  3660. $newentry->timedue = 0;
  3661. $newentry->timeavailable = 0;
  3662. } // if ($param->type_iassign == 1)
  3663. else {
  3664. $newentry->timedue = $param->timedue;
  3665. $newentry->timeavailable = $param->timeavailable;
  3666. }
  3667. $newentry->preventlate = $param->preventlate;
  3668. $newentry->test = $param->test;
  3669. $newentry->special_param1 = $param->special_param1;
  3670. $newentry->visible = $param->visible;
  3671. $newentry->position = $param->position;
  3672. $newentry->max_experiment = $param->max_experiment;
  3673. $newentry->dependency = $param->dependency;
  3674. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3675. $newentry->show_answer = $param->show_answer;
  3676. $id = $DB->insert_record("iassign_statement", $newentry);
  3677. if ($id) {
  3678. $component = 'mod_iassign';
  3679. $filearea = 'exercise';
  3680. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3681. $file = $fs->get_file_by_id($param->file);
  3682. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3683. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  3684. //$itemid = $id;
  3685. // File already inserted in other context!
  3686. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3687. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3688. $updateentry = new stdClass();
  3689. $updateentry->id = $id;
  3690. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3691. $updateentry->file = $newfile->get_itemid();
  3692. if (!$DB->update_record("iassign_statement", $updateentry))
  3693. print_error('error_add', 'iassign');
  3694. if ($param->type_iassign == 3)
  3695. iassign::update_grade_iassign($param->iassignid);
  3696. //TODO iLM_HTML5 :: //MOOC2014
  3697. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3698. //D if ($iassign_ilm_configs) {
  3699. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3700. //D if ($iassign_ilm_config->param_type != 'static') {
  3701. //D $newentry = new stdClass();
  3702. //D $newentry->iassign_statementid = $id;
  3703. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3704. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3705. //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});
  3706. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3707. //D print_error('error_add_param', 'iassign');
  3708. //D }
  3709. //D }
  3710. //D }
  3711. // log event --------------------------------------------------------------------------------------
  3712. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3713. // log event --------------------------------------------------------------------------------------
  3714. return $id;
  3715. }
  3716. else
  3717. print_error('error_add', 'iassign');
  3718. } // function new_iassign($param)
  3719. /// Add the calendar entries for this iassign
  3720. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3721. // @return bool
  3722. static function add_calendar ($iassignid) {
  3723. global $DB, $CFG;
  3724. require_once($CFG->dirroot . '/calendar/lib.php');
  3725. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3726. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3727. $event = new stdClass();
  3728. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3729. $event->description = $iassign_statement_activity_item->name;
  3730. $event->courseid = $iassign->course;
  3731. $event->groupid = 0;
  3732. $event->userid = 0;
  3733. $event->modulename = 'iassign';
  3734. $event->instance = $iassign->id;
  3735. $event->eventtype = 'due';
  3736. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3737. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3738. calendar_event::create($event);
  3739. }
  3740. /// Update the calendar entries for this iassign
  3741. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3742. // @return bool
  3743. function update_calendar ($iassignid, $olddescription) {
  3744. global $DB, $CFG;
  3745. require_once($CFG->dirroot . '/calendar/lib.php');
  3746. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3747. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3748. $event = new stdClass();
  3749. $event->id = 0;
  3750. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3751. if ($events) {
  3752. foreach ($events as $value) {
  3753. if ($value->description == $olddescription) {
  3754. $event->id = $value->id;
  3755. }
  3756. }
  3757. }
  3758. if ($event->id != 0) {
  3759. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3760. $event->description = $iassign_statement_activity_item->name;
  3761. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3762. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3763. $calendarevent = calendar_event::load($event->id);
  3764. $calendarevent->update($event);
  3765. } else
  3766. $this->add_calendar($iassignid);
  3767. }
  3768. /// Update the calendar entries for this iassign
  3769. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3770. // @return bool
  3771. function delete_calendar ($iassignid) {
  3772. global $DB, $CFG;
  3773. require_once($CFG->dirroot . '/calendar/lib.php');
  3774. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3775. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3776. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3777. if ($events) {
  3778. foreach ($events as $value) {
  3779. if ($value->description == $iassign_statement_activity_item->name) {
  3780. $DB->delete_records('event', array('id' => $value->id));
  3781. }
  3782. }
  3783. }
  3784. }
  3785. /// Update interactive activities
  3786. function update_iassign ($param) {
  3787. global $DB;
  3788. $component = 'mod_iassign';
  3789. $filearea = 'exercise';
  3790. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3791. $file = $fs->get_file_by_id($param->file);
  3792. $fileold = $fs->get_file_by_id($param->fileold);
  3793. if ($param->file != $param->fileold) {
  3794. if ($fileold) {
  3795. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3796. foreach ($fileoldarea as $value) {
  3797. $value->delete();
  3798. }
  3799. }
  3800. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3801. $itemid = $file->get_itemid() + $param->iassign_id;
  3802. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3803. $param->file = $newfile->get_itemid();
  3804. } else
  3805. $param->file = $file->get_itemid();
  3806. } else {
  3807. $param->file = $file->get_itemid();
  3808. }
  3809. $newentry = new stdClass();
  3810. $newentry->id = $param->iassign_id;
  3811. $newentry->name = $param->name;
  3812. $newentry->type_iassign = $param->type_iassign;
  3813. $newentry->store_all_submissions = $param->store_all_submissions;
  3814. //2019 $newentry->proposition = $param->proposition;
  3815. $proposition = $param->proposition;
  3816. if (is_array($proposition))
  3817. $proposition_text = $proposition['text'];
  3818. else
  3819. $proposition_text = $proposition;
  3820. $newentry->proposition = $proposition_text;
  3821. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3822. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3823. $newentry->grade = $param->grade;
  3824. $newentry->author_modified_name = $param->author_modified_name;
  3825. $newentry->timemodified = time();
  3826. if ($param->type_iassign == 1) {
  3827. $newentry->timedue = 0;
  3828. $newentry->timeavailable = 0;
  3829. } // if ($param->type_iassign == 1)
  3830. else {
  3831. $newentry->timedue = $param->timedue;
  3832. $newentry->timeavailable = $param->timeavailable;
  3833. }
  3834. $newentry->preventlate = $param->preventlate;
  3835. $newentry->test = $param->test;
  3836. $newentry->special_param1 = $param->special_param1;
  3837. $newentry->visible = $param->visible;
  3838. $newentry->max_experiment = $param->max_experiment;
  3839. $newentry->dependency = $param->dependency;
  3840. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3841. $newentry->show_answer = $param->show_answer;
  3842. if (!$DB->update_record("iassign_statement", $newentry))
  3843. print_error('error_update', 'iassign');
  3844. if ($param->type_iassign == 3) {
  3845. iassign::update_grade_iassign($param->iassignid);
  3846. }
  3847. //$id = $newentry->id; // MOOC 2016 --- inicio
  3848. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3849. //if ($iassign_activity_item_configs) {
  3850. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3851. // $newentry = new stdClass();
  3852. // $newentry->id = $iassign_activity_item_config->id;
  3853. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3854. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3855. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3856. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3857. // print_error('error_edit_param', 'iassign');
  3858. // }
  3859. // } // MOOC 2016 --- final
  3860. // log event --------------------------------------------------------------------------------------
  3861. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3862. // log event --------------------------------------------------------------------------------------
  3863. return $newentry->id;
  3864. // if ($param->type_iassign==3)
  3865. // $this->update_grade_iassign($param->iassignid);
  3866. } // function update_iassign($param)
  3867. /// Show information of activity
  3868. function show_info_iassign () {
  3869. global $DB, $OUTPUT;
  3870. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3871. if ($this->activity->type_iassign == 3) {
  3872. if ($this->activity->dependency == 0) {
  3873. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3874. } else {
  3875. $dependencys = explode(';', $this->activity->dependency);
  3876. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3877. foreach ($dependencys as $dependency) {
  3878. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3879. if ($dependencyiassign)
  3880. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3881. } // foreach ($dependencys as $dependency)
  3882. } // if ($iassign_statement_activity_item->dependency == 0)
  3883. if ($this->activity->max_experiment == 0)
  3884. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3885. else
  3886. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3887. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3888. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3889. print $OUTPUT->box($output);
  3890. } // function show_info_iassign()
  3891. /// Shows date of opening and closing activities
  3892. function view_dates () {
  3893. global $USER, $CFG, $DB, $OUTPUT;
  3894. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3895. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3896. $status_iassign = "";
  3897. $status_iassign1 = "";
  3898. $status_iassign2 = "";
  3899. if ($this->activity->type_iassign == 1) // activity of type example
  3900. $type_iassign = get_string('example_iassign', 'iassign');
  3901. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3902. $type_iassign = get_string('test_iassign', 'iassign');
  3903. if ($this->activity->timeavailable > time()) {
  3904. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3905. } elseif ($this->activity->timedue < time()) {
  3906. $status_iassign = get_string('last_timedue', 'iassign');
  3907. }
  3908. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3909. $type_iassign = get_string('exercise_iassign', 'iassign');
  3910. if ($this->activity->timeavailable > time()) {
  3911. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3912. } elseif ($this->activity->timedue < time()) { // after delivery
  3913. $status_iassign = get_string('last_timedue', 'iassign');
  3914. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3915. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3916. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3917. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3918. if ($this->activity->test == 1) // allowed to test after of deadline
  3919. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3920. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3921. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3922. } // elseif ($iassign_statement_activity_item->test == 0)
  3923. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3924. } // elseif ($iassign_statement_activity_item->timedue < time())
  3925. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3926. $output = '<table width=100% >' . "\n";
  3927. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3928. $output .= '<tr>' . "\n";
  3929. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3930. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3931. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3932. // leo $output .= '<td width=80%>' . $type_iassign;
  3933. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3934. // $output .= '</td>' . "\n";
  3935. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3936. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3937. $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>";
  3938. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3939. } else {
  3940. $link_next = "";
  3941. $link_previous = "";
  3942. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3943. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3944. // previous_activity
  3945. if ($iassign_previous) {
  3946. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3947. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3948. } // next_activity
  3949. if ($iassign_next) {
  3950. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3951. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3952. }
  3953. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3954. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3955. $output .= '</tr></table>' . "\n";
  3956. $output .= '<table width=100% >' . "\n";
  3957. if ($this->activity->type_iassign > 1) {
  3958. if ($this->activity->timeavailable)
  3959. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3960. if ($this->activity->timedue)
  3961. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3962. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3963. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3964. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3965. $output .= '</table>' . "\n";
  3966. print $OUTPUT->box($output);
  3967. } // function view_dates()
  3968. } // class activity
  3969. /// Class to manage Interactive Learning Module (iLM)
  3970. class ilm {
  3971. var $ilm;
  3972. /// Constructor of class
  3973. // @param int $id Id of iLM
  3974. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3975. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3976. function __construct ($id) {
  3977. global $DB;
  3978. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3979. if (empty($this->ilm))
  3980. $this->ilm = null;
  3981. }
  3982. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  3983. // @calledby view_iassign_current()
  3984. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3985. global $USER, $CFG, $DB;
  3986. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3987. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3988. $typec = strtolower($iassign_ilm->type);
  3989. require_once 'ilm_handlers/' . $typec . '.php';
  3990. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  3991. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3992. return $retorno;
  3993. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3994. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3995. // @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);
  3996. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3997. // @param Object $file File in use in activity
  3998. // @return int Return the id of log
  3999. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4000. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4001. $newentry = new stdClass();
  4002. $newentry->iassign_statementid = $iassign_activity_itemid;
  4003. $newentry->userid = $USER->id;
  4004. $newentry->file = $content_or_id_from_ilm_security;
  4005. $newentry->timecreated = time();
  4006. $newentry->view = 1;
  4007. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4008. if (!$id_iLM_security) {
  4009. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4010. } // from (!$DB->insert_record("iassign_security", $newentry))
  4011. return $id_iLM_security;
  4012. }
  4013. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4014. // @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);
  4015. // @param int $userid
  4016. // @param int $iassign_activity_itemid Id of iassign statement
  4017. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4018. global $DB;
  4019. // 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")
  4020. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4021. }
  4022. } // class ilm
  4023. /// Class to manage settings of iLM.
  4024. class ilm_settings {
  4025. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4026. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4027. // @param int $ilm_id Id of iLM
  4028. // @param array $options An array with options for create dynamic tag html APPLET
  4029. // @return string Return with a tag html APPLET created
  4030. static function build_ilm_tags ($ilm_id, $options = array()) {
  4031. global $DB;
  4032. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4033. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4034. $typec = strtolower($iassign_ilm->type);
  4035. require_once 'ilm_handlers/' . $typec . '.php';
  4036. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4037. return $retorno;
  4038. } // static function build_ilm_tags($ilm_id, $options = array())
  4039. /// Function for get modified date of iLM file
  4040. // @param string $file_jar String with Ids of iLM files
  4041. // @return string Return with the filenames and modified date
  4042. static function applet_filetime ($file_jar) {
  4043. $filetime = "";
  4044. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4045. $files_jar = explode(",", $file_jar);
  4046. foreach ($files_jar as $one_file) {
  4047. $file = $fs->get_file_by_id($one_file);
  4048. if ($file)
  4049. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4050. }
  4051. return $filetime;
  4052. }
  4053. /// Function for verify an default applet
  4054. // @param String $file_jar String containing an list de ids of applet files
  4055. // @return boolean Return true or fale if applet is default
  4056. static function applet_default ($file_jar) {
  4057. $is_default = true;
  4058. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4059. $files_jar = explode(",", $file_jar);
  4060. foreach ($files_jar as $one_file) {
  4061. $file = $fs->get_file_by_id($one_file);
  4062. if ($file)
  4063. $is_default &= ($file->get_itemid() == 0);
  4064. }
  4065. return $is_default;
  4066. }
  4067. /// Function for get form variables for add, edit, or copy iLM
  4068. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4069. // @see settings_form.php
  4070. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4071. // @param int $ilm_id Id of iLM
  4072. // @param string $action String with the action
  4073. // @return object Return an object with forms variables
  4074. static function add_edit_copy_ilm ($ilm_id, $action) {
  4075. global $USER, $DB, $CFG;
  4076. require_once('settings_form.php'); // put the form
  4077. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4078. $param = new stdClass();
  4079. $param->action = $action;
  4080. $param->ilm_id = $ilm_id;
  4081. $CFG->action_ilm = $action;
  4082. $CFG->ilm_id = $ilm_id;
  4083. if ($action == 'add') {
  4084. $param->title = get_string('add_ilm', 'iassign');
  4085. $param->name = "";
  4086. $param->version = "";
  4087. $param->url = "";
  4088. $param->description = "";
  4089. $param->extension = "";
  4090. $param->author = $USER->id;
  4091. $param->file_jar = "";
  4092. $param->file_jar_static = "";
  4093. $param->file_class = "";
  4094. $param->width = 800;
  4095. $param->height = 600;
  4096. $param->enable = 0; // 0 - hide / 1 - show
  4097. $param->timecreated = time();
  4098. $param->timemodified = time();
  4099. $param->evaluate = 0;
  4100. $param->parent = 0;
  4101. }
  4102. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4103. if ($iassign_ilm) {
  4104. $description = json_decode($iassign_ilm->description);
  4105. $param->title = get_string('edit_ilm', 'iassign');
  4106. $param->id = $iassign_ilm->id;
  4107. $param->name_ilm = $iassign_ilm->name;
  4108. $param->name = $iassign_ilm->name;
  4109. $param->version = $iassign_ilm->version;
  4110. $param->ilm_type = $iassign_ilm->type;
  4111. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4112. $param->url = $iassign_ilm->url;
  4113. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4114. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4115. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4116. if (!isset($description->{current_language()})) {
  4117. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4118. else
  4119. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4120. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4121. }
  4122. else
  4123. $param->description = $description->{current_language()};
  4124. $param->description_lang = $iassign_ilm->description;
  4125. $param->extension = $iassign_ilm->extension;
  4126. $param->author = $iassign_ilm->author;
  4127. $param->file_jar = $iassign_ilm->file_jar;
  4128. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4129. $param->file_class = $iassign_ilm->file_class;
  4130. $param->width = $iassign_ilm->width;
  4131. $param->height = $iassign_ilm->height;
  4132. $param->enable = $iassign_ilm->enable;
  4133. $param->timecreated = $iassign_ilm->timecreated;
  4134. $param->timemodified = time();
  4135. $param->evaluate = $iassign_ilm->evaluate;
  4136. $param->parent = $iassign_ilm->parent;
  4137. }
  4138. }
  4139. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4140. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4141. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4142. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4143. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4144. // echo "Sem dados<br/>"; exit;
  4145. return;
  4146. }
  4147. $description = json_decode($iassign_ilm->description);
  4148. if ($iassign_ilm) {
  4149. if ($iassign_ilm->parent == 0)
  4150. $iassign_ilm->parent = $ilm_id;
  4151. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4152. $param->title = get_string('new_version_ilm', 'iassign');
  4153. $param->name_ilm = $iassign_ilm->name;
  4154. $param->name = $iassign_ilm->name;
  4155. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4156. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4157. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4158. $param->ilm_type = $iassign_ilm->type;
  4159. $param->url = $iassign_ilm->url;
  4160. $param->description = $description->{current_language()};
  4161. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4162. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4163. $param->extension = $iassign_ilm->extension;
  4164. $param->author = $USER->id;
  4165. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4166. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4167. $param->file_jar_static = '';
  4168. $param->file_class = $iassign_ilm->file_class;
  4169. $param->width = $iassign_ilm->width;
  4170. $param->height = $iassign_ilm->height;
  4171. $param->enable = 0;
  4172. $param->timecreated = time();
  4173. $param->timemodified = time();
  4174. $param->evaluate = $iassign_ilm->evaluate;
  4175. $param->parent = $iassign_ilm->parent;
  4176. }
  4177. }
  4178. elseif ($action == 'copy') {
  4179. $description = json_decode($iassign_ilm->description);
  4180. if ($iassign_ilm) {
  4181. if ($iassign_ilm->parent == 0)
  4182. $iassign_ilm->parent = $ilm_id;
  4183. $param->title = get_string('copy_ilm', 'iassign');
  4184. $param->id = $iassign_ilm->id;
  4185. $param->name_ilm = $iassign_ilm->name;
  4186. $param->name = $iassign_ilm->name;
  4187. $param->version = "";
  4188. $param->ilm_type = $iassign_ilm->type;
  4189. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4190. $param->url = $iassign_ilm->url;
  4191. $param->description = $description->{current_language()};
  4192. $param->description_lang = $iassign_ilm->description;
  4193. $param->extension = $iassign_ilm->extension;
  4194. $param->author = $USER->id;
  4195. $param->file_jar = '';
  4196. $param->file_jar_static = '';
  4197. $param->file_class = $iassign_ilm->file_class;
  4198. $param->width = $iassign_ilm->width;
  4199. $param->height = $iassign_ilm->height;
  4200. $param->enable = 0;
  4201. $param->timecreated = time();
  4202. $param->timemodified = time();
  4203. $param->evaluate = $iassign_ilm->evaluate;
  4204. $param->parent = $iassign_ilm->parent;
  4205. }
  4206. }
  4207. return $param;
  4208. } // static function add_edit_copy_ilm($ilm_id, $action)
  4209. /// Function for save iLM file in moodledata
  4210. // @param int $itemid Itemid of file save in draft (upload file)
  4211. // @param int $ilm_id Id of iLM
  4212. // @return string Return an string with ids of iLM files
  4213. static function new_file_ilm ($itemid, $iassign_ilm) {
  4214. global $CFG, $USER, $DB;
  4215. $return = null;
  4216. $file_jar = array();
  4217. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4218. $contextuser = context_user::instance($USER->id);
  4219. $contextsystem = context_system::instance();
  4220. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4221. if ($files_ilm) {
  4222. foreach ($files_ilm as $value) {
  4223. // CHECK IF file is HTML type
  4224. if ($iassign_ilm->type == 1) {
  4225. // Check if the file extension is ZIP
  4226. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4227. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4228. if ((strtolower($ext) == 'zip')) {
  4229. // Coping...:
  4230. $destination = 'ilm_debug/' . $value->get_filename();
  4231. $value->copy_content_to($destination);
  4232. // Extracting content...:
  4233. $zip = new ZipArchive();
  4234. $extracted = './ilm';
  4235. $dir = "";
  4236. if ($zip->open($destination) === TRUE) {
  4237. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4238. if (is_dir($dir)) {
  4239. $i = 1;
  4240. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4241. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4242. $i ++;
  4243. }
  4244. $name = $previous . "_" . $i;
  4245. $dir = './ilm/' . $name . "/";
  4246. $j = 0;
  4247. while ($item_name = $zip->getNameIndex($j)) {
  4248. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4249. $j++;
  4250. }
  4251. $zip->close();
  4252. }
  4253. $zip->open($destination);
  4254. $zip->extractTo($extracted);
  4255. $zip->close();
  4256. // After the extraction, remove it from DEBUG
  4257. unlink($destination);
  4258. } else { // Error trying to open destination...
  4259. // After the extraction error, also remove it from DEBUG
  4260. unlink($destination);
  4261. print_error('error_add_ilm_zip', 'iassign');
  4262. }
  4263. return $dir;
  4264. }
  4265. } // if ($iassign_ilm->type == 1)
  4266. if ($value->get_filename() != '.') {
  4267. $file_ilm = array(
  4268. 'userid' => $USER->id,
  4269. 'contextid' => $contextsystem->id,
  4270. 'component' => 'mod_iassign',
  4271. 'filearea' => 'ilm',
  4272. 'itemid' => rand(1, 999999999),
  4273. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4274. 'filename' => $value->get_filename());
  4275. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4276. array_push($file_jar, $file_ilm->get_id());
  4277. }
  4278. }
  4279. if (!empty($file_jar)) {
  4280. $return = implode(",", $file_jar);
  4281. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4282. foreach ($old_file_jar as $value) {
  4283. $file = $fs->get_file_by_id($value);
  4284. if ($file)
  4285. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4286. }
  4287. }
  4288. }
  4289. else // if ($files_ilm)
  4290. $return = $iassign_ilm->file_jar;
  4291. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4292. return $return;
  4293. } // static function new_file_ilm($itemid, $iassign_ilm)
  4294. /// Function for save in database an new iLM
  4295. // @param object $param An object with iLM params
  4296. static function new_ilm ($itemid) {
  4297. global $CFG, $USER, $OUTPUT;
  4298. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4299. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4300. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4301. }
  4302. $pathtemp = $CFG->dataroot . '/temp/';
  4303. $contextuser = context_user::instance($USER->id);
  4304. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4305. $zip = new zip_packer();
  4306. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4307. foreach ($files as $file) {
  4308. if (!$file->is_directory())
  4309. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4310. }
  4311. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4312. // Verifica se o pacote possui o XML
  4313. if (!$application_xml) {
  4314. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4315. return;
  4316. } else {
  4317. $missing = "";
  4318. if (!isset($application_xml->name)) {
  4319. $missing .= "name";
  4320. }
  4321. if (!isset($application_xml->version)) {
  4322. $missing .= ", version";
  4323. }
  4324. if (!isset($application_xml->type)) {
  4325. $missing .= ", type";
  4326. }
  4327. if (!isset($application_xml->extension)) {
  4328. $missing .= ", extension";
  4329. }
  4330. if (!isset($application_xml->file_jar)) {
  4331. $missing .= ", file_jar";
  4332. }
  4333. if (!isset($application_xml->file_class)) {
  4334. $missing .= ", file_class";
  4335. }
  4336. if (!isset($application_xml->width)) {
  4337. $missing .= ", width";
  4338. }
  4339. if (!isset($application_xml->height)) {
  4340. $missing .= ", height";
  4341. }
  4342. if (!isset($application_xml->evaluate)) {
  4343. $missing .= ", evaluate";
  4344. }
  4345. if (strlen($missing) > 2) {
  4346. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4347. return;
  4348. }
  4349. }
  4350. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4351. $typec = strtolower($application_xml->type);
  4352. require_once 'ilm_handlers/' . $typec . '.php';
  4353. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4354. return $retorno;
  4355. } // static function new_ilm($itemid)
  4356. /// Function for save in database an iLM edit
  4357. // @param object $param An object with iLM params
  4358. static function edit_ilm ($param, $itemid) {
  4359. // Descobrir o tipo de iLM:
  4360. global $DB, $USER, $CFG;
  4361. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4362. $pathtemp = $CFG->dataroot . '/temp/';
  4363. $contextuser = context_user::instance($USER->id);
  4364. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4365. $zip = new zip_packer();
  4366. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4367. $files_extract = null;
  4368. foreach ($files as $file) {
  4369. if (!$file->is_directory())
  4370. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4371. }
  4372. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4373. $typec = strtolower($iassign_t->type);
  4374. require_once 'ilm_handlers/' . $typec . '.php';
  4375. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4376. }
  4377. /// Function for register the new iLM (in database and in the directory)
  4378. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4379. // @param object $param An object with iLM params
  4380. static function copy_new_version_ilm ($param) {
  4381. global $DB, $CFG, $USER;
  4382. $itemid = $param->file;
  4383. $pathtemp = $CFG->dataroot . '/temp/';
  4384. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4385. //D echo "pathtemp=$pathtemp<br/>";
  4386. $contextuser = context_user::instance($USER->id);
  4387. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4388. $zip = new zip_packer();
  4389. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4390. $files_extract = null;
  4391. foreach ($files as $file) {
  4392. if (!$file->is_directory())
  4393. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4394. }
  4395. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4396. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4397. $typec = strtolower($iassign_t->type);
  4398. require_once 'ilm_handlers/' . $typec . '.php';
  4399. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4400. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4401. } // static function copy_new_version_ilm($param)
  4402. //VER::
  4403. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4404. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4405. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4406. /// Function for change visibility of iLM
  4407. // @param int $ilm_id Id of iLM
  4408. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4409. static function visible_ilm ($ilm_id, $status) {
  4410. global $DB;
  4411. if ($status == 0)
  4412. $visible = 1;
  4413. else
  4414. $visible = 0;
  4415. $newentry = new stdClass();
  4416. $newentry->id = $ilm_id;
  4417. $newentry->enable = $visible;
  4418. if (!$DB->update_record("iassign_ilm", $newentry))
  4419. error(get_string('error_edit_ilm', 'iassign'));
  4420. }
  4421. /// Function for confirm change default iLM
  4422. // @param int $ilm_id Id of iLM
  4423. // @param int $ilm_parent Id of parent iLM
  4424. // @return string Return with an string for create default page confirmation
  4425. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4426. global $OUTPUT, $DB;
  4427. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4428. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4429. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4430. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4431. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4432. return $return;
  4433. }
  4434. /// Function for change the default iLM
  4435. // @see settings_ilm.php
  4436. // @param int $ilm_id Id of iLM
  4437. // @return int Return Id of default iLM
  4438. static function default_ilm ($ilm_id) {
  4439. global $DB;
  4440. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4441. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4442. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4443. $iassign_ilm_default->id = $iassign_ilm->id;
  4444. $iassign_ilm_default->parent = 0;
  4445. $iassign_ilm->parent = $iassign_ilm_default->id;
  4446. $iassign_ilm->id = 0;
  4447. $iassign_ilm_default->enable = 1;
  4448. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4449. print_error('error_edit_ilm', 'iassign');
  4450. }
  4451. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4452. if (!$inserted) {
  4453. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4454. print_error($msg_error);
  4455. //xx print_error('error_add_ilm', 'iassign');
  4456. }
  4457. return $iassign_ilm_default->id;
  4458. } // static function default_ilm ($ilm_id)
  4459. /// Function for confirm delete iLM
  4460. // @param int $ilm_id Id of iLM
  4461. // @param int $ilm_parent Id of parent iLM
  4462. // @return string Return with an string for create delete page confirmation
  4463. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4464. global $OUTPUT, $DB;
  4465. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4466. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4467. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4468. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4469. }
  4470. /// Function for delete directory where the iLM is allocated.
  4471. // @param string $dirPath
  4472. // @throws InvalidArgumentException
  4473. public static function delete_dir ($dirPath) {
  4474. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4475. $dirPath .= '/';
  4476. }
  4477. $files = glob($dirPath . '*', GLOB_MARK);
  4478. foreach ($files as $file) {
  4479. if (is_dir($file)) {
  4480. ilm_settings::delete_dir($file);
  4481. } else {
  4482. unlink($file);
  4483. }
  4484. }
  4485. rmdir($dirPath);
  4486. }
  4487. /// Function for delete iLM
  4488. // @param int $ilm_id Id of iLM
  4489. // @return int Return Id of parent iLM
  4490. static function delete_ilm ($ilm_id) {
  4491. global $DB;
  4492. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4493. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4494. $typec = strtolower($iassign_ilm->type);
  4495. require_once 'ilm_handlers/' . $typec . '.php';
  4496. $retorno = $typec::delete_ilm($ilm_id);
  4497. return $retorno;
  4498. }
  4499. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4500. // @param int $ilm_id Id of iLM
  4501. static function export_ilm ($ilm_id) {
  4502. global $DB;
  4503. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4504. if (!$iassign_ilm) return; // security debug...
  4505. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4506. $typec = strtolower($iassign_ilm->type);
  4507. if (!$typec) $typec = "html5"; // security debug...
  4508. require_once 'ilm_handlers/' . $typec . '.php';
  4509. $typec::export_ilm($ilm_id);
  4510. } // static function export_ilm($ilm_id)
  4511. //TODO iLM_HTML5 :: //MOOC 2016
  4512. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4513. // @param int $ilm_id Id of iLM
  4514. static function export_update_ilm ($ilm_id) {
  4515. global $DB, $CFG;
  4516. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4517. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4518. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4519. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4520. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4521. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4522. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4523. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4524. $upgrade_descriptor .= '</upgrade>' . "\n";
  4525. file_put_contents($xml_filename, $upgrade_descriptor);
  4526. header("Pragma: public");
  4527. header("Expires: 0");
  4528. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4529. header("Cache-Control: private", false);
  4530. header('Content-Type: application/xml; charset=utf-8');
  4531. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4532. header("Content-Length: " . @filesize($xml_filename));
  4533. set_time_limit(0);
  4534. @readfile("$xml_filename") || die("File not found.");
  4535. unlink($xml_filename);
  4536. exit;
  4537. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4538. /// Function for save iLM from XML descriptor
  4539. // @param array $application_xml Data of XML descriptor
  4540. // @param array $files_extract Filenames of extract files
  4541. // @return array Return an array content id of JAR files
  4542. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4543. global $CFG, $USER;
  4544. // Tratamento diferenciado se for do tipo HTML5:
  4545. $source = "";
  4546. $diretorio = "";
  4547. if (strtolower($application_xml->type) == 'html5') {
  4548. $i = 0;
  4549. foreach ($files_extract as $key => $value) {
  4550. $file = $CFG->dataroot . '/temp/' . $key;
  4551. // Verifica se já existe a pasta no diretório dos iLM:
  4552. if ($i == 0) {
  4553. $source = $file;
  4554. if (file_exists("ilm/" . basename($file))) {
  4555. $j = 1;
  4556. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4557. $j ++;
  4558. }
  4559. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4560. // mkdir($diretorio, 0777, true);
  4561. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4562. }
  4563. else {
  4564. $diretorio = 'ilm/' . basename($file);
  4565. // mkdir($diretorio, 0777, true);
  4566. mkdir($diretorio, 0755, true);
  4567. }
  4568. break;
  4569. }
  4570. $i ++;
  4571. }
  4572. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4573. if ($item->isDir()) {
  4574. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4575. }
  4576. else {
  4577. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4578. }
  4579. }
  4580. ilm_settings::delete_dir($source);
  4581. return "./" . $diretorio;
  4582. }
  4583. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4584. $file_jar = array();
  4585. $files_ilm = explode(",", $application_xml->file_jar);
  4586. $contextsystem = context_system::instance();
  4587. foreach ($files_ilm as $value) {
  4588. $file_ilm = array(
  4589. 'userid' => $USER->id,
  4590. 'contextid' => $contextsystem->id,
  4591. 'component' => 'mod_iassign',
  4592. 'filearea' => 'ilm',
  4593. 'itemid' => rand(1, 999999999),
  4594. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4595. 'filename' => $value);
  4596. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4597. array_push($file_jar, $file_ilm->get_id());
  4598. }
  4599. foreach ($files_extract as $key => $value) {
  4600. $file = $CFG->dataroot . '/temp/' . $key;
  4601. if (file_exists($file))
  4602. unlink($file);
  4603. }
  4604. return $file_jar;
  4605. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4606. /// Function for import the iLM from an package
  4607. // @param int $itemid Itemid of zip file
  4608. static function import_ilm ($itemid) {
  4609. global $CFG, $USER, $OUTPUT;
  4610. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4611. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4612. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4613. }
  4614. $pathtemp = $CFG->dataroot . '/temp/';
  4615. $contextuser = context_user::instance($USER->id);
  4616. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4617. $zip = new zip_packer();
  4618. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4619. foreach ($files as $file) {
  4620. if (!$file->is_directory())
  4621. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4622. }
  4623. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4624. // Verifica se o pacote possui o XML
  4625. if (!$application_xml) {
  4626. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4627. return;
  4628. } else {
  4629. $missing = "";
  4630. if (!isset($application_xml->name)) {
  4631. $missing .= "name";
  4632. }
  4633. if (!isset($application_xml->version)) {
  4634. $missing .= ", version";
  4635. }
  4636. if (!isset($application_xml->type)) {
  4637. $missing .= ", type";
  4638. }
  4639. if (!isset($application_xml->extension)) {
  4640. $missing .= ", extension";
  4641. }
  4642. if (!isset($application_xml->file_jar)) {
  4643. $missing .= ", file_jar";
  4644. }
  4645. if (!isset($application_xml->file_class)) {
  4646. $missing .= ", file_class";
  4647. }
  4648. if (!isset($application_xml->width)) {
  4649. $missing .= ", width";
  4650. }
  4651. if (!isset($application_xml->height)) {
  4652. $missing .= ", height";
  4653. }
  4654. if (!isset($application_xml->evaluate)) {
  4655. $missing .= ", evaluate";
  4656. }
  4657. if (strlen($missing) > 2) {
  4658. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4659. return;
  4660. }
  4661. }
  4662. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4663. $typec = strtolower($application_xml->type);
  4664. require_once 'ilm_handlers/' . $typec . '.php';
  4665. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4666. } // static function import_ilm($itemid)
  4667. /// Function for list iLM defaults
  4668. // @return string Return an string with a table of iLM
  4669. static function list_ilm () {
  4670. global $DB, $OUTPUT;
  4671. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4672. $str = '';
  4673. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4674. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4675. if ($iassign_ilm) {
  4676. foreach ($iassign_ilm as $ilm) {
  4677. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4678. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4679. $str .= '<tr><td>';
  4680. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4681. $str .= '<tr>';
  4682. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4683. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4684. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4685. $str .= '</tr>';
  4686. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4687. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4688. $str .= '</table>';
  4689. $str .= '</td></tr>';
  4690. }
  4691. }
  4692. $str .= '</table>';
  4693. return $str;
  4694. }
  4695. /// Function for download and install an upgrade of an iLM
  4696. // @param int $ilm_id Id of iLM
  4697. static function upgrade_ilm ($ilm_id) {
  4698. global $DB, $CFG, $USER;
  4699. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4700. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4701. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4702. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4703. if (!$result)
  4704. print_error('error_upgrade_ilm', 'iassign');
  4705. else {
  4706. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4707. $extension = explode(".", $zip_filename);
  4708. if ($extension[count($extension) - 1] != 'ipz') {
  4709. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4710. die;
  4711. }
  4712. $zip = new zip_packer();
  4713. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4714. $contextuser = context_user::instance($USER->id);
  4715. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4716. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4717. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4718. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4719. if (file_exists($zip_filename))
  4720. unlink($zip_filename);
  4721. if (empty($file_jar)) {
  4722. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4723. print_error($msg_error);
  4724. //xx print_error('error_add_ilm', 'iassign');
  4725. }
  4726. else {
  4727. $newentry = new stdClass();
  4728. $newentry->name = (String) $application_xml->name;
  4729. $newentry->version = (String) $application_xml->version;
  4730. $newentry->url = (String) $application_xml->url;
  4731. $newentry->description = $description_str;
  4732. $newentry->extension = strtolower((String) $application_xml->extension);
  4733. $newentry->file_jar = implode(",", $file_jar);
  4734. $newentry->file_class = (String) $application_xml->file_class;
  4735. $newentry->width = (String) $application_xml->width;
  4736. $newentry->height = (String) $application_xml->height;
  4737. $newentry->enable = 0;
  4738. $newentry->timemodified = time();
  4739. $newentry->author = $USER->id;
  4740. $newentry->timecreated = time();
  4741. $newentry->evaluate = (String) $application_xml->evaluate;
  4742. $newentry->parent = $ilm_id;
  4743. }
  4744. }
  4745. return $iassign_ilm->id;
  4746. } // static function upgrade_ilm($ilm_id)
  4747. //MOOC2014 -- inicio
  4748. //TODO: REVIEW
  4749. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4750. // static function move_iassign($ilm_id)
  4751. //MOOC2014 -- final
  4752. /// Function for list iLM versions with all informations
  4753. // @return string Return an string with a table of iLM
  4754. static function view_ilm ($ilmid, $from) {
  4755. global $DB;
  4756. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4757. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4758. $typec = strtolower($iassign_ilm->type);
  4759. require_once 'ilm_handlers/' . $typec . '.php';
  4760. $retorno = $typec::view_ilm($ilmid, $from);
  4761. return $retorno;
  4762. }
  4763. /// Function for get form variables for add, edit, or copy iLM params
  4764. // @param int $ilm_param_id Id of iLM param
  4765. // @param string $action String with the action
  4766. // @return object Return an object with forms variables
  4767. static function add_edit_copy_param ($ilm_param_id, $action) {
  4768. global $DB;
  4769. require_once('params_form.php');
  4770. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4771. $param = new stdClass();
  4772. $param->action = $action;
  4773. $param->ilm_param_id = $ilm_param_id;
  4774. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4775. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4776. $type = $iassign_ilm_config->param_type;
  4777. if ($action == 'add') {
  4778. $param->title = get_string('add_ilm', 'iassign');
  4779. $param->iassign_ilmid = $ilm_param_id;
  4780. $param->param_name = "";
  4781. $param->param_value = "";
  4782. $param->description = "";
  4783. $param->visible = 1;
  4784. }
  4785. elseif ($action == 'edit') {
  4786. if ($iassign_ilm_config) {
  4787. $param->title = get_string('edit_ilm', 'iassign');
  4788. $param->id = $iassign_ilm_config->id;
  4789. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4790. $param->param_type = $type; //MOOC2014
  4791. $param->param_name = $iassign_ilm_config->param_name;
  4792. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4793. $param->param_value = $iassign_ilm_config->param_value;
  4794. else //MOOC2014
  4795. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4796. $param->param_value = $iassign_ilm_config->param_value;
  4797. $param->description = $iassign_ilm_config->description;
  4798. $param->visible = $iassign_ilm_config->visible;
  4799. }
  4800. }
  4801. elseif ($action == 'copy') {
  4802. if ($iassign_ilm_config) {
  4803. $param->title = get_string('copy_ilm', 'iassign');
  4804. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4805. $param->param_type = $type; //MOOC2014
  4806. $param->param_name = $iassign_ilm_config->param_name;
  4807. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4808. $param->param_value = $iassign_ilm_config->param_value;
  4809. else //MOOC2014
  4810. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4811. $param->description = $iassign_ilm_config->description;
  4812. $param->visible = $iassign_ilm_config->visible;
  4813. }
  4814. }
  4815. return $param;
  4816. } // static function add_edit_copy_param($ilm_param_id, $action)
  4817. /// Function for change visibility of iLM param
  4818. // @param int $ilm_param_id Id of iLM param
  4819. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4820. static function visible_param ($ilm_param_id, $status) {
  4821. global $DB, $CFG;
  4822. if ($status == 0)
  4823. $visible = 1;
  4824. else
  4825. $visible = 0;
  4826. $newentry = new stdClass();
  4827. $newentry->id = $ilm_param_id;
  4828. $newentry->visible = $visible;
  4829. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4830. error(get_string('error_edit_param', 'iassign'));
  4831. }
  4832. /// Function for save in database an new iLM param
  4833. // @param object $param An object with iLM params
  4834. static function add_param ($param) {
  4835. global $DB;
  4836. $newentry = new stdClass();
  4837. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4838. //MOOC2014 $newentry->param_name = $param->param_name;
  4839. $newentry->param_type = $param->param_type; //MOOC2014
  4840. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4841. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4842. $newentry->param_value = $param->param_value;
  4843. else //MOOC2014
  4844. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4845. $newentry->description = $param->description;
  4846. $newentry->visible = $param->visible;
  4847. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4848. if (!$newentry->id) {
  4849. print_error('error_add_param', 'iassign');
  4850. }
  4851. }
  4852. /// Function for save in database a iLM param edit
  4853. // @param object $param An object with iLM params
  4854. static function edit_param ($param) {
  4855. global $DB;
  4856. $updentry = new stdClass();
  4857. $updentry->id = $param->id;
  4858. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4859. $updentry->param_type = $param->param_type; //MOOC2014
  4860. // $updentry->param_name = $param->param_name;
  4861. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4862. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4863. $updentry->param_value = $param->param_value;
  4864. else //MOOC2014
  4865. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4866. $updentry->description = $param->description;
  4867. $updentry->visible = $param->visible;
  4868. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4869. error(get_string('error_edit_param', 'iassign'));
  4870. }
  4871. }
  4872. /// Function for save in database a iLM param copy
  4873. // @param object $param An object with iLM params
  4874. static function copy_param ($param) {
  4875. global $DB;
  4876. $newentry = new stdClass();
  4877. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4878. //$newentry->param_name = $param->param_name;
  4879. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4880. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4881. $newentry->param_value = $param->param_value;
  4882. else //MOOC2014
  4883. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4884. $newentry->description = $param->description;
  4885. $newentry->visible = $param->visible;
  4886. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4887. if (!$newentry->id) {
  4888. print_error('error_add_param', 'iassign');
  4889. }
  4890. }
  4891. /// Function for delete iLM param of database
  4892. // @param int $param_id Id of iLM param
  4893. static function delete_param ($param_id) {
  4894. global $DB;
  4895. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4896. print_error('error_delete_param', 'iassign');
  4897. }
  4898. }
  4899. } // class ilm_settings
  4900. /// Class for manage iLM files (editor).
  4901. class ilm_manager {
  4902. var $id; // course id
  4903. var $url;
  4904. var $from;
  4905. /// Constructor for the base ilm_manager class
  4906. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4907. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4908. function __construct ($id, $url, $from) {
  4909. $this->id = $id; // course id
  4910. $this->url = $url;
  4911. $this->from = $from;
  4912. }
  4913. /// Function to get iAssign content file in Moodle data (exercise)
  4914. // @calledby x function preview_ilm($iassign_ilm) :
  4915. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4916. function get_file_ilm () {
  4917. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4918. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4919. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4920. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4921. $md_file = $fs->get_file_by_id($fileid);
  4922. $ilm_content_file = $md_file->get_content();
  4923. return $ilm_content_file;
  4924. }
  4925. /// Function for creating a new file from the iLM online editor
  4926. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4927. function ilm_editor_new () {
  4928. global $CFG, $DB, $OUTPUT, $PAGE;
  4929. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4930. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4931. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4932. $context = context_course::instance($this->id);
  4933. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4934. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4935. if (!$iassign) {
  4936. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4937. die();
  4938. }
  4939. $temp = explode(",", $iassign->extension);
  4940. $extension = $temp[0]; // default extension for this iLM
  4941. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4942. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4943. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4944. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4945. if ($stringArchiveContent != NULL) {
  4946. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4947. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4948. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4949. $filename = optional_param('filename', NULL, PARAM_RAW);
  4950. //Leo $filename = iassign_utils::format_filename($filename); //
  4951. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4952. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4953. //2019/02 $arrayfilename = explode(".", $filename);
  4954. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4955. //2019/02 $count_dots = count($arrayfilename);
  4956. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4957. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4958. //2019/02 if ($last_name != $extension)
  4959. //2019/02 $filename = $filename . '.' . $extension;
  4960. //2019/02 }
  4961. //2019/02 else { // no extension...
  4962. //2019/02 $filename = $filename . '.' . $extension;
  4963. //2019/02 }
  4964. // Store the name of recent created file
  4965. $_SESSION['file_name'] = $filename;
  4966. //$this->write_file_iassign($string, $filename);
  4967. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4968. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4969. die();
  4970. }
  4971. else { // if ($stringArchiveContent != NULL)
  4972. // iLM On-line editor
  4973. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4974. $str_get_iLM = "window.frames.iLM";
  4975. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4976. }
  4977. else { // otherwise it is JAR named 'iLM'
  4978. $str_get_iLM = "document.iLM";
  4979. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4980. }
  4981. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4982. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4983. $files_array = '';
  4984. foreach ($files as $value) {
  4985. if ($value->get_filename() != ".")
  4986. $files_array .= "'" . $value->get_filename() . "',";
  4987. }
  4988. $files_array .= "''";
  4989. $file = null;
  4990. $ia_content = "";
  4991. $filename = "";
  4992. $error_files_exists = get_string('error_file_exists', 'iassign');
  4993. $output = "<script type='text/javascript'>
  4994. //<![CDATA[
  4995. //D alert('locallib.php: ilm_editor_new');
  4996. function submit_iLM_Answer () {
  4997. var docFormOnLineEditor = document.formEnvio;
  4998. var resposta_exerc = new Array(3);
  4999. var valor_resposta = new Array(3);
  5000. var sessao = new Array(3);
  5001. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5002. resposta_exerc[0] = doc_iLM.getAnswer();
  5003. valor_resposta[0] = doc_iLM.getEvaluation();
  5004. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5005. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5006. var files = new Array(" . $files_array . ");
  5007. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5008. if (docFormOnLineEditor.filename.value=='') {
  5009. // ERROR: the file name is empty
  5010. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5011. return false;
  5012. }
  5013. // }
  5014. for (i=0; i<files.length; i++) {
  5015. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5016. alert('" . $error_files_exists . "');
  5017. return false;
  5018. }
  5019. }
  5020. docFormOnLineEditor.submit();
  5021. return true;
  5022. }
  5023. //]]>
  5024. </script>\n";
  5025. $output .= "
  5026. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5027. $output .= $OUTPUT->box_start();
  5028. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5029. $output .= "
  5030. <table width='100%' cellpadding='20'>
  5031. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5032. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5033. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5034. </tr>
  5035. </table>\n";
  5036. $output .= $OUTPUT->box_end();
  5037. $output .= "<center>\n";
  5038. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5039. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5040. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5041. $output .= $output_ilm;
  5042. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5043. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5044. </center>
  5045. </form>\n";
  5046. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5047. $PAGE->navbar->add($title);
  5048. $PAGE->set_title($title);
  5049. $PAGE->set_heading($title); // insert title above the navigation bar
  5050. print $OUTPUT->header();
  5051. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5052. print $output;
  5053. print $OUTPUT->footer();
  5054. }
  5055. die();
  5056. } // function ilm_editor_new()
  5057. /// Function for editing an file in online editor
  5058. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5059. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5060. global $CFG, $DB, $OUTPUT, $PAGE;
  5061. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5062. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5063. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5064. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5065. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5066. // If iLM is not registered, error!
  5067. if (!$iassign) {
  5068. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5069. die;
  5070. }
  5071. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5072. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5073. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5074. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5075. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5076. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5077. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5078. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5079. if ($stringArchiveContent != NULL) {
  5080. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5081. die();
  5082. } else { // if ($stringArchiveContent != NULL)
  5083. $end_file = '';
  5084. if ($content_file) {
  5085. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5086. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5087. }
  5088. $temp = explode(",", $iassign->extension);
  5089. $extension = $temp[0]; // default extension for this iLM
  5090. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5091. $str_get_iLM = "window.frames.iLM";
  5092. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5093. } else { // otherwise it is JAR named 'iLM'
  5094. $str_get_iLM = "document.iLM";
  5095. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5096. }
  5097. $output = "<script type='text/javascript'>
  5098. //<![CDATA[
  5099. function submit_iLM_Answer () {
  5100. var docFormEditor = document.formEnvio;
  5101. var activityAnswer; // to get activity answer (text)
  5102. var activityValue; // to get activity answer value (float)
  5103. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5104. //activityAnswer = doc_iLM.getAnswer();
  5105. //activityValue = doc_iLM.getEvaluation();
  5106. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5107. activityValue = " . $str_get_iLM . ".getEvaluation();
  5108. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5109. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5110. docFormEditor.submit();
  5111. return true;
  5112. }
  5113. //]]>
  5114. </script>\n";
  5115. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5116. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5117. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5118. // return true;
  5119. // }
  5120. $output .= "
  5121. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5122. $output .= $OUTPUT->box_start();
  5123. $output .= "
  5124. <table width='100%' cellpadding='20'>
  5125. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5126. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5127. <input type='hidden' name='filename' value='$filename'/></td>
  5128. <td>
  5129. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5130. </tr>
  5131. </table>\n";
  5132. $output .= $OUTPUT->box_end();
  5133. $output .= " <center>\n";
  5134. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5135. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5136. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5137. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5138. </center>
  5139. </form>\n";
  5140. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5141. $PAGE->navbar->add($title);
  5142. $PAGE->set_title($title);
  5143. $PAGE->set_heading($title); // insert title above the navigation bar
  5144. print $OUTPUT->header();
  5145. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5146. print $output;
  5147. print $OUTPUT->footer();
  5148. } // else if ($stringArchiveContent != NULL)
  5149. die();
  5150. } // function ilm_editor_update()
  5151. /// Function for write iAssign file in Moodle data (exercise)
  5152. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5153. // @param string $stringArchiveContent Content of iassign file
  5154. // @param string $filename Filename of iassign file
  5155. function write_file_iassign ($stringArchiveContent, $filename) {
  5156. global $USER;
  5157. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5158. $context = context_course::instance($this->id);
  5159. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5160. $dirid = $this->get_dir_ilm('dirid');
  5161. $dir = $fs->get_file_by_id($dirid);
  5162. $fileinfo = array('contextid' => $context->id, // ID of course
  5163. 'component' => 'mod_iassign', // usually = table name
  5164. 'filearea' => 'activity', // usually = table name
  5165. 'itemid' => 0, // usually = ID of row in table
  5166. 'filepath' => '/', // any path beginning and ending whith '/'
  5167. 'userid' => $USER->id,
  5168. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5169. 'filename' => $filename); // any filename
  5170. // Create file containing text. '$stringArchiveContent'
  5171. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5172. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5173. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5174. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5175. // 'Activité interactive enregistrée avec succès sous le nom:';
  5176. // 'Atividade interativa gravada com sucesso sob o nome:'
  5177. $output = "
  5178. <script type='text/javascript'>
  5179. //<![CDATA[
  5180. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5181. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5182. //]]>
  5183. </script>";
  5184. print $output;
  5185. die();
  5186. }
  5187. /// Function for write iAssign file in Moodle data (exercise)
  5188. // @param string $stringArchiveContent Content of iassign file
  5189. // @param string $filename Filename of iassign file
  5190. // @param int $itemid Itemid of iassign file
  5191. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5192. global $OUTPUT, $USER;
  5193. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5194. $context = context_course::instance($this->id);
  5195. $dirid = $this->get_dir_ilm('dirid');
  5196. if ($stringArchiveContent != (-1)) {
  5197. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5198. $file = $fs->get_file_by_id($fileid);
  5199. if (!$file) {
  5200. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5201. die;
  5202. }
  5203. $fileinfo = array('contextid' => $context->id, // ID of context
  5204. 'component' => 'mod_iassign', // usually = table name
  5205. 'filearea' => 'activity', // usually = table name
  5206. 'itemid' => 0, // usually = ID of row in table
  5207. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5208. 'userid' => $USER->id,
  5209. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5210. 'license' => 'allrightsreserved', // allrightsreserved
  5211. 'timecreated' => $file->get_timecreated(),
  5212. 'filename' => $file->get_filename()); // any filename
  5213. $file->delete();
  5214. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5215. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5216. }
  5217. $output = "<script type='text/javascript'>
  5218. //<![CDATA[
  5219. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5220. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5221. //]]>
  5222. </script>";
  5223. print $output;
  5224. die();
  5225. }
  5226. /// Function for create an tag for iAssign filter
  5227. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5228. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5229. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5230. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5231. // @param int $fileid Id of file
  5232. // @return string Return an string with an tag of iassign filter
  5233. function tag_ilm ($fileid) {
  5234. global $DB;
  5235. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5236. $width = '600';
  5237. $height = '400';
  5238. $file = $fs->get_file_by_id($fileid);
  5239. $filetype = explode(".", $file->get_filename());
  5240. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5241. foreach ($iassign_ilm as $value) {
  5242. $extensions = explode(",", $value->extension);
  5243. if (in_array($filetype[1], $extensions)) {
  5244. $width = $value->width;
  5245. $height = $value->height;
  5246. }
  5247. }
  5248. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5249. }
  5250. /// Function for delete iAssign file in Moodle data (exercise)
  5251. function delete_file_ilm () {
  5252. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5253. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5254. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5255. $file = $fs->get_file_by_id($fileid);
  5256. if ($file)
  5257. $file->delete();
  5258. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5259. die();
  5260. }
  5261. /// Function for delete selected iAssign file in Moodle data (exercise)
  5262. function delete_selected_ilm () {
  5263. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5264. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5265. $context = context_course::instance($this->id);
  5266. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5267. $dirid = $this->get_dir_ilm('dirid');
  5268. foreach ($files_id as $file_id) {
  5269. $file = $fs->get_file_by_id($file_id);
  5270. if ($file) {
  5271. if (!$file->is_directory())
  5272. $file->delete();
  5273. else {
  5274. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5275. foreach ($files_delete as $value)
  5276. $value->delete();
  5277. $file->delete();
  5278. }
  5279. }
  5280. }
  5281. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5282. die();
  5283. }
  5284. /// Function for duplicate iAssign file from "online" edition
  5285. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5286. function duplicate_file_ilm () {
  5287. global $USER, $COURSE;
  5288. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5289. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5290. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5291. $filename = optional_param('filename', NULL, PARAM_RAW);
  5292. $file = $fs->get_file_by_id($fileid);
  5293. $context = context_course::instance($this->id);
  5294. $fileinfo = array(
  5295. 'contextid' => $context->id, // ID of context
  5296. 'component' => 'mod_iassign', // usually = table name
  5297. 'filearea' => 'activity', // usually = table name
  5298. 'itemid' => 0, // usually = ID of row in table
  5299. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5300. 'userid' => $USER->id,
  5301. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5302. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5303. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5304. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5305. die();
  5306. }
  5307. /// Function for rename iAssign file
  5308. function rename_file_ilm () {
  5309. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5310. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5311. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5312. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5313. $file = $fs->get_file_by_id($fileid);
  5314. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5315. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5316. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5317. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5318. die();
  5319. }
  5320. /// Function for get iassign file for iassign form
  5321. function add_ilm () {
  5322. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5323. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5324. $output = "
  5325. <script type='text/javascript'>
  5326. //<![CDATA[
  5327. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5328. iassign_file_link.innerHTML = '$filename';
  5329. window.opener.document.forms['mform1'].file.value='$fileid';
  5330. window.opener.document.forms['mform1'].filename.value='$filename';
  5331. window.close();
  5332. //]]>
  5333. </script>";
  5334. print $output;
  5335. die();
  5336. }
  5337. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5338. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5339. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5340. function preview_ilm ($courseid, $iassign_ilm) {
  5341. global $OUTPUT, $CFG, $USER;
  5342. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5343. $title = get_string('modulename', 'iassign'); // iAssign
  5344. print $OUTPUT->header();
  5345. print $OUTPUT->box_start();
  5346. $javascript = "
  5347. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5348. <script type='text/javascript'>
  5349. //<![CDATA[
  5350. function submit_close () {
  5351. window.opener.location.reload();
  5352. window.close();
  5353. }
  5354. //]]>
  5355. </script>\n";
  5356. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5357. // to the complete "applet" tag
  5358. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5359. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5360. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5361. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5362. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5363. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5364. if ($ilm_name != "ivprog") {
  5365. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5366. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5367. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5368. } else {
  5369. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5370. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5371. $timecreated = time();
  5372. $token = md5($timecreated);
  5373. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5374. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5375. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5376. $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)
  5377. }
  5378. $html = "
  5379. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5380. <table border='1'>
  5381. <tr><td>
  5382. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5383. <!-- iLM calls : end -->
  5384. </td></tr>
  5385. </table>
  5386. <table>
  5387. <tr>
  5388. <td align='center'>
  5389. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5390. </td></tr>
  5391. </table>
  5392. </form>\n";
  5393. print $javascript . $html;
  5394. print $OUTPUT->box_end();
  5395. //NAO echo format_string($html); // Moodle 3.X
  5396. die();
  5397. } // function preview_ilm($courseid, $iassign_ilm)
  5398. //r_ function preview_ilm ($iassign_ilm)
  5399. //r_ /// Function for preview iassign file from iassign filter.
  5400. //r_ function preview_ilm() {
  5401. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5402. //r_ $tag_filter = $this->tag_ilm($fileid);
  5403. //r_ $javascript = "<script type='text/javascript'>
  5404. //r_ //<![CDATA[
  5405. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5406. //r_ //]]>
  5407. //r_ </script>";
  5408. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5409. //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>
  5410. //r_ </table></form></body></html>";
  5411. //r_ echo $javascript . format_text($html);
  5412. //r_ die;
  5413. //r_ }
  5414. /// Function for export an package (zip) of iassign files
  5415. function export_files_ilm () {
  5416. global $CFG;
  5417. $context = context_course::instance($this->id);
  5418. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5419. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5420. $zip = new zip_archive();
  5421. $zip->open($zip_filename);
  5422. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5423. foreach ($files_id as $file_id) {
  5424. $file = $fs->get_file_by_id($file_id);
  5425. if (!$file->is_directory())
  5426. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5427. else {
  5428. $zip->add_directory($file->get_filepath());
  5429. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5430. foreach ($files_zip as $value) {
  5431. if (!$value->is_directory())
  5432. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5433. else
  5434. $zip->add_directory($value->get_filepath());
  5435. }
  5436. }
  5437. }
  5438. $zip->close();
  5439. header("Pragma: public");
  5440. header("Expires: 0");
  5441. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5442. header("Cache-Control: private", false);
  5443. header("Content-Type: application/zip");
  5444. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5445. header("Content-Transfer-Encoding: binary");
  5446. header("Content-Length: " . @filesize($zip_filename));
  5447. set_time_limit(0);
  5448. @readfile("$zip_filename") || die("File not found.");
  5449. unlink($zip_filename);
  5450. exit;
  5451. }
  5452. /// Function of execute a command in button editor tinymce
  5453. // @param int $fileid Id of file
  5454. function tinymce_ilm ($fileid) {
  5455. $tag_filter = $this->tag_ilm($fileid);
  5456. $output = "<script type='text/javascript'>
  5457. //<![CDATA[
  5458. var tag_filter = '$tag_filter';
  5459. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5460. // all right, insert it
  5461. } else {
  5462. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5463. }
  5464. // window.close();
  5465. //]]>
  5466. </script>\n";
  5467. print $output;
  5468. die();
  5469. }
  5470. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5471. /// Function to add content to the Editor Window
  5472. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5473. // @param int $fileid Id of file
  5474. function editor_ilm ($fileid, $editor) {
  5475. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5476. $output1 = "<script type='text/javascript'>
  5477. //<![CDATA[
  5478. var tag_filter = '$tag_filter';\n";
  5479. if ($editor == 'atto') {
  5480. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5481. } elseif ($editor == 'tinyMCE') {
  5482. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5483. } else
  5484. $output2 = "";
  5485. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5486. window.close();
  5487. //]]>
  5488. </script>\n";
  5489. //D var_dump($output);
  5490. print $output1 . $output2 . $output3;
  5491. die();
  5492. }
  5493. /// Function to add content to the Atto Editor Window
  5494. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5495. // @param int $fileid Id of file
  5496. function atto_ilm ($fileid) {
  5497. global $CFG, $DB;
  5498. $tag_filter = $this->tag_ilm($fileid);
  5499. $output = "<script type='text/javascript'>
  5500. //<![CDATA[
  5501. var tag_filter = '$tag_filter';
  5502. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5503. // all right, insert iLM tag to this editor
  5504. } else {
  5505. // error trying to insert
  5506. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5507. }
  5508. //window.close();
  5509. //]]>
  5510. </script>\n";
  5511. print $output;
  5512. die();
  5513. }
  5514. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5515. // @param string $key Key for return information
  5516. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5517. function get_dir_ilm ($key) {
  5518. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5519. $context = context_course::instance($this->id);
  5520. $dirid = optional_param('dirid', 0, PARAM_INT);
  5521. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5522. if ($dirid == 0) {
  5523. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5524. $dirid = $dir->get_id();
  5525. }
  5526. else {
  5527. $dir = $fs->get_file_by_id($dirid);
  5528. $dir_base = $dir->get_filepath();
  5529. }
  5530. $dir_parent = $dir->get_parent_directory();
  5531. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5532. return $data[$key];
  5533. }
  5534. /// Function for create an new dir
  5535. function new_dir_ilm () {
  5536. global $USER;
  5537. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5538. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5539. $dir_base = $this->get_dir_ilm('dir_base');
  5540. $context = context_course::instance($this->id);
  5541. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5542. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5543. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5544. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5545. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5546. }
  5547. /// Function for delete an dir
  5548. function delete_dir_ilm () { //
  5549. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5550. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5551. $context = context_course::instance($this->id);
  5552. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5553. $dir_parent = $this->get_dir_ilm('dir_parent');
  5554. if ($dir) {
  5555. if ($dir->is_directory()) {
  5556. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5557. foreach ($files_delete as $value)
  5558. $value->delete();
  5559. $dir->delete();
  5560. }
  5561. }
  5562. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5563. die();
  5564. }
  5565. /// Function for rename an dir
  5566. function rename_dir_ilm () {
  5567. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5568. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5569. $context = context_course::instance($this->id);
  5570. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5571. $dir_parent = $this->get_dir_ilm('dir_parent');
  5572. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5573. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5574. if ($dir->is_directory()) {
  5575. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5576. foreach ($files_rename_path as $value)
  5577. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5578. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5579. }
  5580. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5581. die();
  5582. }
  5583. /// Function for move an dir and your content for other dir
  5584. function selected_move_ilm () {
  5585. global $PAGE, $OUTPUT, $CFG;
  5586. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5587. $context = context_course::instance($this->id);
  5588. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5589. $dirid = $this->get_dir_ilm('dirid');
  5590. $dir_base = $this->get_dir_ilm('dir_base');
  5591. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5592. $code_javascript_ilm = "
  5593. <script type='text/javascript'>
  5594. //<![CDATA[
  5595. function getRadiobutton () {
  5596. var radioButtons = document.getElementsByTagName('input');
  5597. var param = '';
  5598. for (var counter=0; counter < radioButtons.length; counter++) {
  5599. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5600. param = radioButtons[counter].value;
  5601. }
  5602. return param;
  5603. }
  5604. function move_selected_ilm () {
  5605. var msgAnswer;
  5606. if (getRadiobutton() != '') {
  5607. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5608. if (msgAnswer)
  5609. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5610. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5611. }
  5612. else
  5613. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5614. }
  5615. function cancel_selected_ilm () {
  5616. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5617. }
  5618. //]]>
  5619. </script>\n";
  5620. $title = get_string('move_files', 'iassign');
  5621. $PAGE->set_title($title);
  5622. $PAGE->set_pagelayout('base');
  5623. print $OUTPUT->header();
  5624. print $OUTPUT->heading($title);
  5625. $dir_paths = array();
  5626. print $OUTPUT->box_start();
  5627. print "<center>";
  5628. foreach ($files_id as $file_id) {
  5629. $file = $fs->get_file_by_id($file_id);
  5630. if ($file) {
  5631. if (!$file->is_directory())
  5632. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5633. else {
  5634. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5635. array_push($dir_paths, $file->get_filepath());
  5636. }
  5637. }
  5638. }
  5639. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5640. if ($dir_base != '/') {
  5641. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5642. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5643. }
  5644. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5645. foreach ($files_tree as $file) {
  5646. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5647. $is_parent = false;
  5648. foreach ($dir_paths as $dir) {
  5649. $path = explode("/", $dir);
  5650. array_pop($path);
  5651. $path[count($path) - 1] = '';
  5652. $path = implode("/", $path);
  5653. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5654. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5655. }
  5656. if ($is_parent == false) {
  5657. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5658. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5659. }
  5660. }
  5661. }
  5662. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5663. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5664. print "</center>";
  5665. print $OUTPUT->box_end();
  5666. print $OUTPUT->footer();
  5667. print $code_javascript_ilm;
  5668. die;
  5669. }
  5670. /// Function for move files for an dir
  5671. function move_files_ilm () {
  5672. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5673. $context = context_course::instance($this->id);
  5674. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5675. $dirid = $this->get_dir_ilm('dirid');
  5676. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5677. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5678. foreach ($files_id as $file_id) {
  5679. $file = $fs->get_file_by_id($file_id);
  5680. if ($file) {
  5681. if ($file->is_directory()) {
  5682. $pathname = explode("/", $file->get_filepath());
  5683. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5684. foreach ($files_move_path as $value) {
  5685. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5686. $value->rename($path_move, $value->get_filename());
  5687. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5688. }
  5689. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5690. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5691. $file->rename($path_move, $file->get_filename());
  5692. } else {
  5693. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5694. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5695. }
  5696. }
  5697. }
  5698. //die;
  5699. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5700. die();
  5701. } // function move_files_ilm()
  5702. /// Function for recover files in use on all activities of a course
  5703. function recover_files_ilm () {
  5704. global $DB, $USER;
  5705. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5706. $courseid = optional_param('id', NULL, PARAM_INT);
  5707. $dirid = $this->get_dir_ilm('dirid');
  5708. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5709. $contextfile = context_course::instance($this->id);
  5710. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5711. foreach ($iassigns as $iassign) {
  5712. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5713. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5714. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5715. $context = context_module::instance($cm->id);
  5716. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5717. if ($files) {
  5718. foreach ($files as $value) {
  5719. $extension = explode(".", $value->get_filename());
  5720. if (!$value->is_directory()) {
  5721. $fileinfo = array('contextid' => $contextfile->id,
  5722. 'component' => 'mod_iassign',
  5723. 'filearea' => 'activity',
  5724. 'itemid' => 0,
  5725. 'filepath' => $this->get_dir_ilm('dir_base'),
  5726. 'userid' => $USER->id,
  5727. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5728. 'license' => 'allrightsreserved',
  5729. 'timecreated' => time(),
  5730. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5731. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5732. }
  5733. }
  5734. } // if ($files)
  5735. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5736. } // foreach ($iassigns as $iassign)
  5737. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5738. die();
  5739. } // function recover_files_ilm()
  5740. /// Auxiliary function the get all files in a given context
  5741. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5742. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5743. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5744. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5745. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5746. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5747. // (NAO s_iassign_statement.file = s_files.id)
  5748. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5749. $dir_base = $this->get_dir_ilm('dir_base');
  5750. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5751. $countf = 0;
  5752. $array_files_id = array(); // all files from this context
  5753. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5754. //$filename = $item_fc->get_filename();
  5755. //$filepath = $item_fc->get_filepath();
  5756. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5757. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5758. // $array_files_aux[] = $item_fc;
  5759. $itemid = $item_fc->get_id();
  5760. if (!in_array($itemid, $array_files_id)) {
  5761. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5762. if ($fileuserid == $userid)
  5763. $filesfrommine[] = $item_fc;
  5764. else
  5765. $filesfromothers[] = $item_fc;
  5766. $array_files_id[] = $itemid;
  5767. $countf++;
  5768. }
  5769. }
  5770. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5771. return $countf;
  5772. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5773. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5774. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5775. function get_all_ilm_files_by_fileid ($fileid) {
  5776. global $DB, $USER;
  5777. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5778. //TODO Criar coluna 'authorid'
  5779. $str_query = "SELECT * FROM {iassign_statement} " .
  5780. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5781. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5782. return $array_iassign_ilm;
  5783. }
  5784. //NN
  5785. //NN
  5786. // Build string with JavaScript code with function to edit/remove/double iLM files
  5787. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5788. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5789. global $CFG;
  5790. $error_files_exists = get_string('error_file_exists', 'iassign');
  5791. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5792. $code_javascript_ilm = "
  5793. <script type='text/javascript'>
  5794. //<![CDATA[
  5795. function preview_ilm (fileid, ilmid) { //JavaScript function
  5796. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5797. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5798. }
  5799. function update_ilm (ilmid, fileid) { //JavaScript function
  5800. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5801. }
  5802. function delete_ilm (ilmid, fileid) { //JavaScript function
  5803. var msgAnswer;
  5804. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5805. if (msgAnswer) {
  5806. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5807. }
  5808. }
  5809. function delete_selected_ilm () { //JavaScript function
  5810. var msgAnswer;
  5811. var param = getCheckbox();
  5812. if (param.join() != '') {
  5813. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5814. if (msgAnswer)
  5815. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5816. }
  5817. else
  5818. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5819. }
  5820. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5821. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5822. }
  5823. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5824. var filenamecopy;
  5825. var i;
  5826. var files = new Array(" . $files_array . ");
  5827. do {
  5828. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5829. } while (filenamecopy == '');
  5830. if (filenamecopy == null)
  5831. return false;\n
  5832. else {
  5833. for (i=0;i<files.length;i++) {
  5834. if (files[i]==filenamecopy) {
  5835. alert('" . $error_files_exists . "');
  5836. return false;\n
  5837. }
  5838. }\n" .
  5839. // @see: function 'duplicate_file_ilm()' above
  5840. "
  5841. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5842. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5843. } // else
  5844. }
  5845. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5846. var filenamecopy;
  5847. var i;
  5848. var files = new Array($files_array);
  5849. do {
  5850. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5851. } while (filenamecopy == '');
  5852. if (filenamecopy == null)
  5853. return false;
  5854. else {
  5855. for (i=0;i<files.length;i++) {
  5856. if (files[i]==filenamecopy) {
  5857. alert('" . $error_files_exists . "');
  5858. return false;
  5859. }
  5860. }
  5861. 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;
  5862. }
  5863. }
  5864. function export_files_ilm () { //JavaScript function
  5865. var param = getCheckbox();
  5866. if (param.join() != '')
  5867. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5868. else
  5869. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5870. }
  5871. function select_all_ilm () { //JavaScript function
  5872. var checkBoxes = document.getElementsByTagName('input');
  5873. var selectAll = document.getElementById('select_all');
  5874. for (var counter=0; counter < checkBoxes.length; counter++) {
  5875. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5876. checkBoxes[counter].checked = selectAll.checked;
  5877. }
  5878. }
  5879. function getCheckbox () { //JavaScript function
  5880. var checkBoxes = document.getElementsByTagName('input');
  5881. var param = new Array();
  5882. for (var counter=0; counter < checkBoxes.length; counter++) {
  5883. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5884. param.push(checkBoxes[counter].value);
  5885. }
  5886. return param;
  5887. }
  5888. function new_dir_ilm () { //JavaScript function
  5889. var dirname = '';
  5890. var i;
  5891. var dirs = new Array(" . $dirs_array . ");
  5892. do {
  5893. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5894. } while (dirname == '');
  5895. if (dirname == null)
  5896. return false;\n
  5897. else {
  5898. for (i=0;i<dirs.length;i++) {
  5899. if (dirs[i]==dirname) {
  5900. alert('" . $error_dir_exists . "');
  5901. return false;\n
  5902. }
  5903. }
  5904. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5905. }
  5906. }
  5907. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5908. var msgAnswer;
  5909. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5910. if (msgAnswer) {
  5911. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5912. }
  5913. }
  5914. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5915. var dirnamecopy;
  5916. var i;
  5917. var dirs = new Array($dirs_array);
  5918. do {
  5919. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5920. } while (dirnamecopy == '');
  5921. if (dirnamecopy == null)
  5922. return false;\n
  5923. else {
  5924. for (i=0;i<dirs.length;i++) {
  5925. if (dirs[i]==dirnamecopy) {
  5926. alert('" . $error_dir_exists . "');
  5927. return false;\n
  5928. }
  5929. }
  5930. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5931. }
  5932. }
  5933. function move_selected_ilm (ilmid) { //JavaScript function
  5934. var param = getCheckbox();
  5935. if (param.join() != '')
  5936. 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();
  5937. else
  5938. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5939. }
  5940. function recover_files_ilm () { //JavaScript function
  5941. var msgAnswer;
  5942. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5943. if (msgAnswer) {
  5944. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5945. }
  5946. }
  5947. window.onload = function() { //JavaScript function
  5948. var xPosition = 0;
  5949. var yPosition = 0;
  5950. element=document.getElementById('new_file');
  5951. while(element) {
  5952. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5953. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5954. element = element.offsetParent;
  5955. }
  5956. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5957. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5958. location.hash = '#new_file';
  5959. };
  5960. //]]>
  5961. </script>\n"; // end of $code_javascript_ilm
  5962. return $code_javascript_ilm;
  5963. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5964. /// List iassign files from course directory
  5965. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5966. function view_files_ilm ($iassign_ilm_class, $extension) {
  5967. global $CFG, $DB, $USER, $OUTPUT;
  5968. $fs = get_file_storage();
  5969. $context = context_course::instance($this->id);
  5970. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5971. $dirid = $this->get_dir_ilm('dirid');
  5972. $dir_base = $this->get_dir_ilm('dir_base');
  5973. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5974. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  5975. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  5976. $files_array = '';
  5977. foreach ($files_course as $value) {
  5978. if (!$value->is_directory())
  5979. $files_array .= "'" . $value->get_filename() . "',";
  5980. }
  5981. $files_array .= "''";
  5982. $error_files_exists = get_string('error_file_exists', 'iassign');
  5983. $dirs_array = '';
  5984. foreach ($files_course as $value) {
  5985. if ($value->is_directory()) {
  5986. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  5987. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5988. }
  5989. }
  5990. $dirs_array .= "''";
  5991. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5992. // TODO Rever o preview pois só deixar ver uma vez.
  5993. $code_javascript_ilm = "
  5994. <script type='text/javascript'>
  5995. //<![CDATA[
  5996. function preview_ilm (fileid, ilmid) {
  5997. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5998. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5999. }
  6000. function update_ilm (ilmid, fileid) {
  6001. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6002. }
  6003. function delete_ilm (ilmid, fileid) {
  6004. var msgAnswer;
  6005. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6006. if (msgAnswer) {
  6007. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6008. }
  6009. }
  6010. function delete_selected_ilm () {
  6011. var msgAnswer;
  6012. var param = getCheckbox();
  6013. if (param.join() != '') {
  6014. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6015. if (msgAnswer)
  6016. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6017. }
  6018. else
  6019. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6020. }
  6021. function add_ilm_iassign (ilmid, filename, fileid) {
  6022. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6023. }
  6024. function duplicate_ilm (ilmid, filename, fileid) {
  6025. var filenamecopy;
  6026. var i;
  6027. var files = new Array($files_array);
  6028. do {
  6029. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6030. } while (filenamecopy == '');
  6031. if (filenamecopy == null)
  6032. return false;\n
  6033. else {
  6034. for (i=0;i<files.length;i++) {
  6035. if (files[i]==filenamecopy) {
  6036. alert('$error_files_exists');
  6037. return false;\n
  6038. }
  6039. }\n" .
  6040. // @see: function 'duplicate_file_ilm()' above
  6041. "
  6042. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6043. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6044. } // else
  6045. }
  6046. function rename_ilm (ilmid, filename, fileid) {
  6047. var filenamecopy;
  6048. var i;
  6049. var files = new Array($files_array);
  6050. do {
  6051. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6052. } while (filenamecopy == '');
  6053. if (filenamecopy == null)
  6054. return false;
  6055. else {
  6056. for (i=0;i<files.length;i++) {
  6057. if (files[i]==filenamecopy) {
  6058. alert('$error_files_exists');
  6059. return false;
  6060. }
  6061. }
  6062. 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;
  6063. }
  6064. }
  6065. function export_files_ilm () {
  6066. var param = getCheckbox();
  6067. if (param.join() != '')
  6068. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6069. else
  6070. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6071. }
  6072. function select_all_ilm () {
  6073. var checkBoxes = document.getElementsByTagName('input');
  6074. var selectAll = document.getElementById('select_all');
  6075. for (var counter=0; counter < checkBoxes.length; counter++) {
  6076. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6077. checkBoxes[counter].checked = selectAll.checked;
  6078. }
  6079. }
  6080. function getCheckbox () {
  6081. var checkBoxes = document.getElementsByTagName('input');
  6082. var param = new Array();
  6083. for (var counter=0; counter < checkBoxes.length; counter++) {
  6084. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6085. param.push(checkBoxes[counter].value);
  6086. }
  6087. return param;
  6088. }
  6089. function new_dir_ilm () {
  6090. var dirname = '';
  6091. var i;
  6092. var dirs = new Array($dirs_array);
  6093. do {
  6094. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6095. } while (dirname == '');
  6096. if (dirname == null)
  6097. return false;\n
  6098. else {
  6099. for (i=0;i<dirs.length;i++) {
  6100. if (dirs[i]==dirname) {
  6101. alert('$error_dir_exists');
  6102. return false;\n
  6103. }
  6104. }
  6105. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6106. }
  6107. }
  6108. function delete_dir_ilm (ilmid, dirid) {
  6109. var msgAnswer;
  6110. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6111. if (msgAnswer) {
  6112. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6113. }
  6114. }
  6115. function rename_dir_ilm (ilmid, dirname, dirid) {
  6116. var dirnamecopy;
  6117. var i;
  6118. var dirs = new Array($dirs_array);
  6119. do {
  6120. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6121. } while (dirnamecopy == '');
  6122. if (dirnamecopy == null)
  6123. return false;\n
  6124. else {
  6125. for (i=0;i<dirs.length;i++) {
  6126. if (dirs[i]==dirnamecopy) {
  6127. alert('$error_dir_exists');
  6128. return false;\n
  6129. }
  6130. }
  6131. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6132. }
  6133. }
  6134. function move_selected_ilm (ilmid) {
  6135. var param = getCheckbox();
  6136. if (param.join() != '')
  6137. 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();
  6138. else
  6139. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6140. }
  6141. function recover_files_ilm () {
  6142. var msgAnswer;
  6143. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6144. if (msgAnswer) {
  6145. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6146. }
  6147. }
  6148. window.onload = function() {
  6149. var xPosition = 0;
  6150. var yPosition = 0;
  6151. element=document.getElementById('new_file');
  6152. while(element) {
  6153. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6154. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6155. element = element.offsetParent;
  6156. }
  6157. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6158. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6159. location.hash = '#new_file';
  6160. };
  6161. //]]>
  6162. </script>\n";
  6163. $output = "";
  6164. $select_all = "";
  6165. $count_files = 0;
  6166. $extensions_allow = array();
  6167. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6168. foreach ($iassign_ilm as $item_iassign_ilm)
  6169. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6170. foreach ($files_course as $value) {
  6171. $filename = $value->get_filename();
  6172. $filepath = $value->get_filepath();
  6173. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6174. $pathname = $pathname[count($pathname) - 1];
  6175. $fileid = $value->get_id();
  6176. $tmp = explode(".", $filename);
  6177. if (count($tmp)>1) // avoid error if the file has no extension
  6178. $filetype = $tmp[1];
  6179. else // probably error...
  6180. $filetype = '';
  6181. $author = $value->get_author();
  6182. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6183. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6184. $extensions = explode(",", $extension);
  6185. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6186. $count_files ++;
  6187. // buscar fileid nas tabelas do iassign
  6188. $list_filein_use = "";
  6189. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6190. if ($iassign_statement_activity_list) {
  6191. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6192. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6193. }
  6194. }
  6195. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6196. if (!$iassign_ilm) {
  6197. $iassign_ilm = new stdClass();
  6198. $iassign_ilm->id = $ilmid;
  6199. }
  6200. // Do not use $var inside "..." - problem with some "unusual" operational system
  6201. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6202. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6203. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6204. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6205. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6206. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6207. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6208. $check_select = "";
  6209. $link_rename = "";
  6210. $link_delete = "";
  6211. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6212. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6213. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6214. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6215. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6216. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6217. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6218. if ($value->get_userid() == $USER->id) {
  6219. if ($iassign_statement_activity_list) {
  6220. $check_select = "";
  6221. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6222. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6223. $link_rename = "";
  6224. } else {
  6225. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6226. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6227. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6228. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6229. }
  6230. }
  6231. if (!in_array($filetype, $extensions_allow)) {
  6232. $link_edit = "";
  6233. $link_add_ilm_iassign = "";
  6234. $link_add_ilm_tinymce = "";
  6235. $link_add_ilm_atto = "";
  6236. $link_filter = "";
  6237. }
  6238. if ($value->is_directory()) {
  6239. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6240. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6241. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6242. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6243. <td><center>$author</center></td>
  6244. <td><center>$timecreated</center></td>
  6245. <td><center>$timemodified</center></td></tr>\n";
  6246. }
  6247. else if ($this->from == 'iassign') {
  6248. $new_id = "";
  6249. $new_class = "";
  6250. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6251. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6252. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6253. }
  6254. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6255. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6256. <td><center>$author</center></td>
  6257. <td><center>$timecreated</center></td>
  6258. <td><center>$timemodified</center></td></tr>\n";
  6259. }
  6260. else if ($this->from == 'block') {
  6261. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6262. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6263. <td><center>$author</center></td>
  6264. <td><center>$timecreated</center></td>
  6265. <td><center>$timemodified</center></td></tr>\n";
  6266. }
  6267. else if ($this->from == 'tinymce') {
  6268. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6269. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6270. <td><center>$author</center></td>
  6271. <td><center>$timecreated</center></td>
  6272. <td><center>$timemodified</center></td></tr>\n";
  6273. }
  6274. else if ($this->from == 'atto') {
  6275. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6276. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6277. <td><center>$author</center></td>
  6278. <td><center>$timecreated</center></td>
  6279. <td><center>$timemodified</center></td></tr>\n";
  6280. }
  6281. }
  6282. }
  6283. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6284. $dir_base = "";
  6285. $header = "";
  6286. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6287. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6288. foreach ($basename as $value) {
  6289. $dir_base .= $value . "/";
  6290. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6291. if ($dir_id) {
  6292. if ($value == "") {
  6293. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6294. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6295. } else {
  6296. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6297. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6298. }
  6299. }
  6300. } // foreach ($basename as $value)
  6301. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6302. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6303. $html .= "
  6304. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6305. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6306. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6307. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6308. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6309. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6310. </table>\n";
  6311. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6312. $html .= "<table width='100%'><tr>\n";
  6313. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6314. if ($count_files != 0) {
  6315. $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";
  6316. $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";
  6317. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6318. }
  6319. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6320. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6321. $html .= "</form>\n";
  6322. print $code_javascript_ilm;
  6323. print $html;
  6324. } // function view_files_ilm($extension)
  6325. } // class ilm_manager
  6326. /// Class to insert of icons
  6327. class iassign_icons {
  6328. static function insert ($icon) {
  6329. global $CFG;
  6330. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6331. return $string;
  6332. }
  6333. }
  6334. /// Class with util functions for plugin manage
  6335. class iassign_utils {
  6336. /// Function to return the filename extension
  6337. // @param string The $filename as an string
  6338. // @return string Return an string (last group after '.')
  6339. static function filename_extension ($filename) {
  6340. if ($filename == null || $filename == '') {
  6341. return null;
  6342. }
  6343. $itens = explode('.', $filename);
  6344. $num = count($itens);
  6345. if ($num < 2) {
  6346. return null;
  6347. }
  6348. return $itens[$num - 1];
  6349. }
  6350. /// Use the PHP class/package ZipArchive to create a Zip file
  6351. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6352. // 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
  6353. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6354. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6355. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6356. $zip = new zip_archive(); //2
  6357. $res = $zip->open($full_path_zip_filename);
  6358. $total_vet = count($vet_student_filename);
  6359. for ($ii=0; $ii<$total_vet; $ii++) {
  6360. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6361. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6362. }
  6363. $ret = $zip->close();
  6364. iassign_utils::download_file($full_path_zip_filename);
  6365. $filenameZip = $zip->filename;
  6366. return array($ret, $zip);
  6367. }
  6368. static function download_file ($zip_filename) {
  6369. header("Pragma: public");
  6370. header("Expires: 0");
  6371. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6372. header("Cache-Control: private", false);
  6373. header("Content-Type: application/zip");
  6374. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6375. header("Content-Transfer-Encoding: binary");
  6376. header("Content-Length: " . @filesize($zip_filename));
  6377. set_time_limit(0);
  6378. @readfile("$zip_filename") || die("File not found.");
  6379. unlink($zip_filename);
  6380. }
  6381. /// Function for format filename remove special caracters
  6382. // @param string $text String for clean
  6383. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6384. // @return string Return an string in clean format
  6385. static function format_filename ($text) {
  6386. if ($text != '.') {
  6387. //D $text = htmlspecialchars(urldecode($text));
  6388. //D echo "locallib.php: format_filename: $text<br/>";
  6389. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6390. $text = json_decode($text)->{current_language()};
  6391. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6392. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6393. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6394. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6395. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6396. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6397. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6398. // E.g. text = "exerc_midpoint.course.geo"
  6399. // 0123456789012345678901234
  6400. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6401. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6402. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6403. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6404. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6405. //$ext = strrpos($text, ".");
  6406. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6407. //$text = str_replace($array1, $array2, $text);
  6408. }
  6409. return $text;
  6410. }
  6411. /// Function to filter characters to the file name to iLM content
  6412. // @param string $text String for clean
  6413. // @param string $ext String ot the extension of the iLM
  6414. // @return string Return an string in clean format
  6415. static function filter_filename_extension ($filename, $ext) {
  6416. if ($filename != '.') {
  6417. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6418. $arrTo = array("_","","","","","","","","","","","","");
  6419. $filename = str_replace($arrFrom, $arrTo, $filename);
  6420. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6421. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6422. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6423. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6424. $index_lastposition = strlen($filenameF);
  6425. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6426. $text = str_replace(".", "_", $text); // erase all other "."
  6427. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6428. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6429. }
  6430. else
  6431. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6432. return $filenameF;
  6433. }
  6434. /// Function for format pathname remove special caracters
  6435. // @param string $text String for clean
  6436. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6437. // @return string Return an string in clean format
  6438. static function format_pathname ($text, $is_lowercase = true) {
  6439. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6440. $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", "-", "_", "", "", "");
  6441. $text = str_replace($array1, $array2, $text);
  6442. if ($is_lowercase)
  6443. $text = strtolower($text);
  6444. return $text;
  6445. }
  6446. /// Function for format file name from iLM original name
  6447. // @param string $text String to build the file neam
  6448. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6449. // @return string Return an string in clean format
  6450. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6451. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6452. $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", "-", "_", "", "", "");
  6453. $index_firstposition_blank = strpos($ilm_name, " ");
  6454. if ($index_firstposition_blank) { // truncate the name!
  6455. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6456. }
  6457. $index_firstposition_dots = strpos($ilm_name, ":");
  6458. if ($index_firstposition_dots) { // truncate the name!
  6459. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6460. }
  6461. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6462. if ($is_lowercase)
  6463. $namefiltered = strtolower($namefiltered);
  6464. return $namefiltered;
  6465. }
  6466. /// Function for insert version in the filename
  6467. // @param string $filename Name of file
  6468. // @return string Return the filename with version
  6469. static function version_filename ($filename) {
  6470. $array_filename = explode('.', $filename);
  6471. if (count($array_filename) > 1)
  6472. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6473. else
  6474. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6475. return $filename;
  6476. }
  6477. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6478. static function remove_code_message ($string) {
  6479. $array = explode("&lt;ia_uc&gt;", $string);
  6480. return $array[0];
  6481. }
  6482. }
  6483. // class iassign_utils
  6484. /// Class with language functions for plugin manage
  6485. class iassign_language {
  6486. /// Function for return text in language or get default language (en)
  6487. // @param string $lang Code of language
  6488. // @param string $description JSON text content all languages
  6489. // @return string Return an string in the language selected
  6490. static function get_description_lang ($lang, $descriptions) {
  6491. $description_lang = "";
  6492. $description = json_decode($descriptions);
  6493. if ($description == null) {
  6494. $description_lang = $descriptions;
  6495. }
  6496. else {
  6497. if (isset($description->{$lang}))
  6498. $description_lang = $description->{$lang};
  6499. else
  6500. if (isset($description->en)) //MOOC2014
  6501. $description_lang = $description->en;
  6502. else //MOOC2014
  6503. $description_lang = "en"; //MOOC2014
  6504. }
  6505. return $description_lang;
  6506. }
  6507. /// Function for return all language supported by iLM
  6508. // @param string $descriptions JSON text content all languages
  6509. // @return string Return as string with all languages
  6510. static function get_all_lang ($descriptions) {
  6511. $langs = "";
  6512. $description = json_decode($descriptions);
  6513. if ($description) {
  6514. foreach ($description as $key => $value) {
  6515. $langs .= $key . " ; ";
  6516. }
  6517. $langs = substr($langs, 0, strlen($langs) - 3);
  6518. }
  6519. return $langs;
  6520. }
  6521. /// Function for convert json in xml //MOOC2014
  6522. // @param string $json JSON text
  6523. // @return string Return as string with xml tags
  6524. static function json_to_xml ($json) {
  6525. $xml = "";
  6526. $json = json_decode($json);
  6527. foreach ($json as $key => $value) {
  6528. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6529. }
  6530. return $xml;
  6531. }
  6532. }
  6533. // class iassign_language
  6534. /// Class with log functions for plugin manage.
  6535. class iassign_log {
  6536. /// Function for insert log event
  6537. // @param string $action Code action of event
  6538. // @param string $information Text for describe action of event
  6539. // @param int $cmid Id of context module
  6540. // @param int $ilmid Id of iLM
  6541. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6542. global $COURSE, $CFG, $USER, $DB;
  6543. $newentry = new stdClass();
  6544. $newentry->time = time();
  6545. $newentry->userid = $USER->id;
  6546. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6547. $newentry->course = $COURSE->id;
  6548. $newentry->cmid = $cmid;
  6549. $newentry->ilmid = $ilmid;
  6550. $newentry->action = $action;
  6551. $newentry->info = $information;
  6552. $newentry->language = current_language();
  6553. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6554. if (ini_get("browscap") && function_exists('get_browse')) {
  6555. $browser = get_browse(null, true);
  6556. $newentry->javascript = $browser['javascript'];
  6557. $newentry->java = $browser['javaapplets'];
  6558. }
  6559. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6560. print_error('error_add_log', 'iassign');
  6561. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6562. } // class iassign_log