locallib.php 337 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.3 2020/01/16
  7. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  8. *
  9. * - v 4.9.2 2019/03/13
  10. * + Several fixes to allow iLM under HTML stack
  11. *
  12. * - v 4.9.1 2017/11/02
  13. * + 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")
  14. * + 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)'
  15. *
  16. * - v 4.9 2017/03/13
  17. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  18. *
  19. * - v 4.8 2016/05/12
  20. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  21. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  22. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  23. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  24. * replaced by
  25. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  26. * - v 4.7 2016/02/17
  27. * + 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(...)')
  28. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  29. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  30. * + 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)
  31. * + 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'
  32. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  33. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  34. *
  35. * --------------- (code bellow was used at our MOOC 2014)
  36. * - v 4.6 2014/02/25
  37. * + Fix bugs in filter function for open applets.
  38. * - v 4.5 2014/02/24
  39. * + Fix bugs in params.
  40. * + Insert new param type.
  41. * - v 4.4 2014/01/24
  42. * + Allow select type of params.
  43. * + Insert the use of applet params specific for activities.
  44. * - v 4.3 2014/01/23
  45. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  46. * - v 4.2 2016/02/13
  47. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  48. * --------------- (above code used at our MOOC 2014)
  49. *
  50. * - v 4.1 2013/12/13
  51. * + Insert log in iAssign actions.
  52. * + 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).
  53. * + Insert class for Log actions in system.
  54. * - v 4.0 2013/10/31
  55. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  56. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  57. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  58. * - v 3.9 2013/10/25
  59. * + Insert support of upgrade iLM.
  60. * + Insert support for more than one extension in iLM.
  61. * + Fix bugs in verion control.
  62. * - v 3.8 2013/09/19
  63. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  64. * - v 3.7 2013/09/12
  65. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  66. * + 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).
  67. * - v 3.6 2013/09/05
  68. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  69. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  70. * + Change tag APPLET in function ilm_settings::view_ilm.
  71. * - v 3.5 2013/08/26
  72. * + Fix bug in download package iassign without answers (iassign::report).
  73. * - v 3.4 2013/08/23
  74. * + Fix bug in export package iassign.
  75. * - v 3.3 2013/08/22
  76. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  77. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  78. * - v 3.2 2013/08/21
  79. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  80. * + Change functions for import files for ilm_manager.php.
  81. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  82. * - v 3.1 2013/08/15
  83. * + Change return file selected (ilm_manager::add_ilm).
  84. * + 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).
  85. * - v 3.0 2013/08/02
  86. * + 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).
  87. * - v 2.9 2013/08/01
  88. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  89. * - v 2.8 2013/07/25
  90. * + Insert the activity name in header of view (activity::view_dates).
  91. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  92. * - v 2.7 2013/07/24
  93. * + Create link previous and next for student view in one activity (activity::view_dates).
  94. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  95. * - v 2.6 2013/07/23
  96. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  97. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  98. * - v 2.5 2013/07/12
  99. * + 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).
  100. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  101. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  102. *
  103. * @author Patricia Alves Rodrigues
  104. * @author Leônidas O. Brandão
  105. * @contributor Igor Moreira Félix (2018-)
  106. * @contributor Márcio de Lima Passos (2014)
  107. * @version v 4.9.2 2019/03/13
  108. * @version v 4.8 2016/05/12
  109. * @package mod_iassign_lib
  110. * @since 2010/09/27
  111. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  112. *
  113. * <b>License</b>
  114. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  115. */
  116. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  117. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  118. //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"'
  119. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  120. /**
  121. * Standard base class for all iAssign
  122. */
  123. class iassign {
  124. var $cm;
  125. var $course;
  126. var $iassign;
  127. var $striassign;
  128. var $striassigns;
  129. var $context;
  130. var $activity;
  131. var $iassign_up;
  132. var $iassign_down;
  133. var $action;
  134. var $iassign_submission_current;
  135. var $userid_iassign;
  136. var $bottonPost;
  137. var $write_solution;
  138. var $view_iassign;
  139. // 3.1 update PHP 7.0 compatibility for all moodle versions
  140. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  141. /// Constructor for the base iassign class
  142. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  143. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  144. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  145. function __construct ($iassign, $cm, $course) {
  146. global $COURSE, $CFG, $USER, $DB;
  147. $botton = optional_param('botton', NULL, PARAM_TEXT);
  148. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  149. if (!is_null($botton))
  150. $USER->iassignEdit = $botton;
  151. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  152. // 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'
  153. $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"
  154. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  155. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  156. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  157. $this->action = optional_param('action', NULL, PARAM_TEXT);
  158. $this->cm = $cm;
  159. $this->context = context_module::instance($this->cm->id);
  160. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  161. $this->userid_iassign = $USER->id;
  162. if ($course) {
  163. $this->course = $course;
  164. }
  165. else if ($this->cm->course == $COURSE->id) {
  166. $this->course = $COURSE;
  167. }
  168. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  169. print_error('invalidid', 'iassign');
  170. }
  171. $this->coursecontext = context_course::instance($this->course->id);
  172. if ($iassign) {
  173. $this->iassign = $iassign;
  174. }
  175. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  176. print_error('invalidid', 'iassign');
  177. }
  178. $USER->context = context_module::instance($this->cm->id);
  179. $USER->cm = $this->cm->id;
  180. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  181. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  182. $this->context = context_module::instance($this->cm->id);
  183. $this->striassign = get_string('modulename', 'iassign');
  184. $this->striassigns = get_string('modulenameplural', 'iassign');
  185. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  186. $this->bottonPost = 0;
  187. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  188. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  189. $this->view();
  190. } // function __construct($iassign, $cm, $course)
  191. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  192. // This method provides the page to view each iLM with any interactive activity
  193. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  194. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  195. global $USER, $DB, $OUTPUT;
  196. // $iassign_statementid = $this->iassign->iassign_statementid;
  197. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  198. $iassign_statementid = $this->activity->get_activity()->id;
  199. else
  200. $iassign_statementid = "";
  201. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  202. // If this user has no capability to View 'iassign': stop here
  203. require_capability('mod/iassign:view', $this->context);
  204. // Trigger module view event
  205. $event = \mod_iassign\event\course_module_viewed::create(array(
  206. 'objectid' => $this->iassign->id,
  207. 'context' => $this->context
  208. ));
  209. $event->add_record_snapshot('course', $this->course);
  210. $event->trigger();
  211. if ($this->action) { // when student do/redo activity or teacher see student solution
  212. $this->action(); // calls '$this->view_iLM();'
  213. }
  214. else {
  215. print $OUTPUT->header();
  216. $this->view_iassigns(); // show the iLM with the content
  217. print $OUTPUT->footer();
  218. }
  219. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  220. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  221. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  222. //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" }
  223. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //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" }
  226. //D else echo "Apagou!<br/>";
  227. die();
  228. } // function view()
  229. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  230. function action () {
  231. global $USER;
  232. // action:
  233. // up - move up activity (mover atividade para cima)
  234. // down - move down activity (mover atividade para baixo)
  235. // visible - view/hide activity (exibir/ocultar atividade)
  236. // delete - delete activity (excluir atividade)
  237. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  238. // deleteno - does not erase activity (não apaga atividade)
  239. // add - add activity (adicionar atividade)
  240. // edit - edit activity (modificar atividade)
  241. $action_iassign = array(
  242. 'newcomment' => '$this->get_answer();',
  243. 'view' => '$this->view_iassign_current();',
  244. 'get_answer' => '$this->get_answer();',
  245. 'repeat' => '$this->view_iassign_current();',
  246. 'overwrite' => '$this->get_answer();',
  247. 'stats_student' => '$this->stats_students();',
  248. 'download_answer' => '$this->export_file_answer();',
  249. 'download_all_answer' => '$this->export_package_answer();');
  250. $action_iassign_limit = array(
  251. 'view' => '$this->view_iassign_current();',
  252. 'newcomment' => '$this->get_answer();',
  253. 'viewsubmission' => '$this->view_iassign_current();',
  254. 'edit_status' => '$this->edit_status();',
  255. 'edit_grade' => '$this->edit_grade();',
  256. 'export_csv' => '$this->export_csv();',
  257. 'report' => '$this->report();',
  258. 'print' => '$this->report();',
  259. 'stats' => '$this->stats();',
  260. 'printstats' => '$this->stats();');
  261. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  262. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  263. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  264. 'visible' => '$this->activity->visible_iassign($this->return);',
  265. 'delete' => '$this->activity->delete($this->return);',
  266. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  267. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  268. 'add' => '$this->add_edit_iassign();',
  269. 'edit' => '$this->add_edit_iassign();',
  270. 'get_answer' => '$this->get_answer();',
  271. 'duplicate_activity' => '$this->duplicate_activity();',
  272. 'move_activity' => '$this->move_activity();',
  273. 'auto_evaluate' => '$this->auto_evaluate();',
  274. 'get_student_submission' => '$this->get_student_submission();',
  275. 'get_teacher_exercise' => '$this->get_teacher_exercise();'
  276. );
  277. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  278. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  279. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  280. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  281. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  282. }
  283. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  284. eval($action_iassign_limit[$this->action]);
  285. }
  286. else { // Student reaches this point
  287. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  288. // Arrive here with: "get_answer"; "view"
  289. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  290. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  291. }
  292. } // function action()
  293. /// This method prints the student submission to a specific exercise
  294. function get_student_submission () {
  295. global $DB;
  296. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  297. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  298. if (!$student || !$exercise) exit;
  299. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  300. if ($iassign_submission)
  301. print($iassign_submission->answer);
  302. die();
  303. }
  304. /// This method prints the teacher exercise
  305. function get_teacher_exercise () {
  306. global $DB, $COURSE;
  307. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  308. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  309. $fs = get_file_storage(); // Get reference to all files in Moodle data
  310. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id,
  311. 'mod_iassign',
  312. 'exercise',
  313. $iassign_statement->file);
  314. foreach ($files as $file) {
  315. if ($file->get_filename() != ".") {
  316. print($file->get_content());
  317. }
  318. }
  319. die();
  320. }
  321. /// This method runs activities auto evaluation in teacher area
  322. function auto_evaluate () {
  323. global $COURSE, $CFG, $USER, $DB, $OUTPUT;
  324. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  325. exit;
  326. // Get list of exercises in the instance:
  327. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  328. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  329. // Get list of enrolled students:
  330. $params = array('shortname' => 'student');
  331. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  332. $context = context_course::instance($this->course->id);
  333. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  334. $students_list = $DB->get_records_sql(
  335. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  336. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  337. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  338. print $OUTPUT->header();
  339. print '<script> var exercises = [ ';
  340. foreach ($exercises_list as $exercise) {
  341. print $exercise->id . ',';
  342. }
  343. print ' ]; var students = [ ';
  344. foreach ($students_list as $student) {
  345. print $student->userid . ',';
  346. }
  347. print ']; var ilms = [';
  348. foreach ($exercises_list as $exercise) {
  349. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  350. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  351. }
  352. print '];
  353. var endpoint = "'.$CFG->wwwroot . "/mod/iassign/view.php?action=get_student_submission&id=".$this->cm->id.'";
  354. window.onload = function(e){
  355. for (i = 0; i < exercises.length; i++) {
  356. var teacher_answer = "'.$CFG->wwwroot.'/mod/iassign/view.php?action=get_teacher_exercise&id='.$this->cm->id.'&iassign_exercise=" + exercises[i];
  357. for (j = 0; j < students.length; j++) {//" + students[j] + "
  358. var student_answer = endpoint + "&iassign_student=3&iassign_exercise=" + exercises[i];
  359. var final_url = ilms[i] + "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment="+encodeURIComponent(teacher_answer)+"&iLM_PARAM_TeacherAutoEval="+encodeURIComponent(student_answer);
  360. console.log(final_url);
  361. window.frames["ifrm"].location=final_url;
  362. break;
  363. }
  364. break;
  365. }
  366. }';
  367. print '</script>';
  368. print '<iframe name="ifrm"></iframe>';
  369. print $OUTPUT->footer();
  370. }
  371. /// This method moves an iAssign activity
  372. function move_activity () {
  373. global $USER, $CFG, $DB, $COURSE;
  374. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  375. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  376. $update_entry_new_iassign = new stdClass();
  377. $update_entry_new_iassign->id = $iassign_id;
  378. $update_entry_new_iassign->iassignid = $iassign_destiny;
  379. // Update the iassign_statement
  380. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  381. // Update file context
  382. $c_i = context_module::instance($this->cm->id);
  383. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  384. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  385. $path_module = context_course::instance($COURSE->id);
  386. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  387. if ($context_file) {
  388. $id_context = $context_file->id;
  389. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  390. $fs = get_file_storage(); // Get reference to all files in Moodle data
  391. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  392. foreach ($files as $value) {
  393. if ($value->get_filename() != ".") {
  394. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  395. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  396. $updateentry = new stdClass();
  397. $updateentry->id = $iassign_id;
  398. $updateentry->file = $newfile->get_itemid();
  399. $DB->update_record("iassign_statement", $updateentry);
  400. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  401. break;
  402. }
  403. }
  404. }
  405. $this->return_home_course('moved_activity');
  406. exit;
  407. }
  408. /// This method duplicates an iAssign activity
  409. function duplicate_activity () {
  410. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  411. $id = $this->cm->id;
  412. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  413. $context = context_module::instance($this->cm->id);
  414. $contextuser = context_user::instance($USER->id);
  415. // Get the the iAssign acitivity to be duplicated
  416. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  417. // Remove the current id of activity
  418. $iassign_statement->id=0;
  419. // Get the information about current author, and add this information in author_modified field
  420. $author = $DB->get_record("user", array('id' => $USER->id));
  421. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  422. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  423. // Store the activity in the table
  424. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  425. // Duplicate activity file
  426. $fs = get_file_storage(); // Get reference to all files in Moodle data
  427. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  428. foreach ($files as $value) {
  429. if ($value->get_filename() != ".") {
  430. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  431. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  432. $updateentry = new stdClass();
  433. $updateentry->id = $id_;
  434. $updateentry->file = $newfile->get_itemid();
  435. // Update the duplicated iLM iAssign with new file id
  436. $DB->update_record("iassign_statement", $updateentry);
  437. }
  438. }
  439. }
  440. // log event --------------------------------------------------------------------------------------
  441. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  442. $this->return_home_course('duplicated_activity');
  443. exit;
  444. }
  445. /// This method gets the content from the iLM and register it
  446. // It could be the "exercise template" (teacher) or an answer (student)
  447. function get_answer () {
  448. global $USER, $CFG, $DB, $OUTPUT;
  449. $id = $this->cm->id;
  450. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  451. $comment = false;
  452. if ($submission_comment)
  453. $comment = $this->write_comment_submission();
  454. // receives data of iLM using the current activity
  455. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  456. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  457. // receives data of submission of current activity
  458. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  459. // receives post and get
  460. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  461. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  462. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  463. $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)
  464. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  465. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  466. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  467. $msg = '';
  468. // Feedback
  469. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  470. $str_action = "view"; // repeat
  471. if (strtolower($iassign_ilm->name) == "igeom") {
  472. }
  473. $title = get_string('evaluate_iassign', 'iassign');
  474. print $OUTPUT->header();
  475. print $OUTPUT->box_start();
  476. // Action = { view ; repeat ; viewsubmission }
  477. // * '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")
  478. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  479. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  480. $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;
  481. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  482. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  483. print '<table width=100% >';
  484. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  485. //TODO alterar aqui???
  486. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  487. // empty_answer_post = No solution was posted.
  488. if ($comment)
  489. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  490. else
  491. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  492. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  493. } else {
  494. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  495. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  496. // Correct answer!!
  497. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  498. $this->write_solution = 1; //
  499. $status = 3;
  500. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  501. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  502. // log record
  503. $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;
  504. // Trigger module viewed event.
  505. $event = \mod_iassign\event\submission_created::create(array(
  506. 'objectid' => $this->iassign->id,
  507. 'context' => $this->context,
  508. 'other' => $info
  509. ));
  510. $event->add_record_snapshot('course', $this->course);
  511. $event->trigger();
  512. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  513. // Wrong answer...: get_answer_incorrect
  514. $status = 2;
  515. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  516. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  517. // log record
  518. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  519. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  520. // Trigger module viewed event.
  521. $event = \mod_iassign\event\submission_created::create(array(
  522. 'objectid' => $this->iassign->id,
  523. 'context' => $this->context,
  524. 'other' => $info
  525. ));
  526. $event->add_record_snapshot('course', $this->course);
  527. $event->trigger();
  528. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  529. // Presents to the learner the result of the automatic evaluate?
  530. if ($this->activity->get_activity()->show_answer == 0) { // no...
  531. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  532. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  533. print '<tr>';
  534. // log record
  535. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  536. // Trigger module viewed event.
  537. $event = \mod_iassign\event\submission_created::create(array(
  538. 'objectid' => $this->iassign->id,
  539. 'context' => $this->context,
  540. 'other' => $info
  541. ));
  542. $event->add_record_snapshot('course', $this->course);
  543. $event->trigger();
  544. } else { // yes!!!
  545. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  546. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  547. print '<tr>';
  548. print $msg;
  549. }
  550. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  551. $status = 1;
  552. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  553. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  554. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  555. print '<tr>';
  556. // log record
  557. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  558. $event = \mod_iassign\event\submission_created::create(array(
  559. 'objectid' => $this->iassign->id,
  560. 'context' => $this->context,
  561. 'other' => $info
  562. ));
  563. $event->add_record_snapshot('course', $this->course);
  564. $event->trigger();
  565. } // if ($iassign_ilm->evaluate == 1)
  566. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  567. print '</tr></table>';
  568. print $OUTPUT->box_end();
  569. // add or update evaluate
  570. if ($this->write_solution == 1) {
  571. $timenow = time();
  572. // new record
  573. if (!$iassign_submission) {
  574. $newentry = new stdClass();
  575. $newentry->userid = $this->userid_iassign;
  576. // $newentry->userid = $USER->id;
  577. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  578. $newentry->timecreated = $timenow;
  579. $newentry->timemodified = $timenow;
  580. $newentry->answer = $iLM_PARAM_ArchiveContent;
  581. $newentry->grade = round($grade_student, 2);
  582. $newentry->status = $status;
  583. $newentry->experiment = 1;
  584. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  585. print_error('error_insert', 'iassign');
  586. } else {
  587. // Trigger module viewed event.
  588. $event = \mod_iassign\event\submission_created::create(array(
  589. 'objectid' => $this->iassign->id,
  590. 'context' => $this->context
  591. ));
  592. $event->add_record_snapshot('course', $this->course);
  593. $event->trigger();
  594. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  595. }
  596. } elseif ($iassign_submission->status != 3) {
  597. $newentry = new stdClass();
  598. $newentry->id = $iassign_submission->id;
  599. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  600. $newentry->userid = $iassign_submission->userid;
  601. $newentry->timecreated = $iassign_submission->timecreated;
  602. $newentry->timemodified = $timenow;
  603. $newentry->answer = $iLM_PARAM_ArchiveContent;
  604. $newentry->grade = round($grade_student, 2);
  605. $newentry->status = $status;
  606. $newentry->experiment = $iassign_submission->experiment + 1;
  607. if (!$DB->update_record("iassign_submission", $newentry)) {
  608. print_error('error_update', 'iassign');
  609. //D depurar...
  610. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  611. //D $fp = fopen("teste1.txt","w");
  612. //D fwrite($fp,$stringAux);
  613. } else {
  614. // Trigger module viewed event.
  615. $event = \mod_iassign\event\submission_updated::create(array(
  616. 'objectid' => $this->iassign->id,
  617. 'context' => $this->context
  618. ));
  619. $event->add_record_snapshot('course', $this->course);
  620. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  621. }
  622. } else {
  623. if ($return_get_answer == 1) {
  624. $newentry = new stdClass();
  625. $newentry->id = $iassign_submission->id;
  626. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  627. $newentry->userid = $iassign_submission->userid;
  628. $newentry->timecreated = $iassign_submission->timecreated;
  629. $newentry->timemodified = $timenow;
  630. $newentry->answer = $iLM_PARAM_ArchiveContent;
  631. $newentry->grade = round($grade_student, 2);
  632. $newentry->status = $status;
  633. $newentry->experiment = $iassign_submission->experiment + 1;
  634. if (!$DB->update_record("iassign_submission", $newentry))
  635. print_error('error_update', 'iassign');
  636. else {
  637. $event = \mod_iassign\event\submission_updated::create(array(
  638. 'objectid' => $this->iassign->id,
  639. 'context' => $this->context
  640. ));
  641. $event->add_record_snapshot('course', $this->course);
  642. $event->trigger();
  643. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  644. print $OUTPUT->box_start();
  645. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  646. print $OUTPUT->box_end();
  647. }
  648. } elseif ($return_get_answer == 2) {
  649. print $OUTPUT->box_start();
  650. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  651. print $OUTPUT->box_end();
  652. } else {
  653. print $OUTPUT->box_start();
  654. print "
  655. <script type='text/javascript'>
  656. //<![CDATA[
  657. function overwrite () {
  658. document.formEnvio.return_get_answer.value = 1;
  659. document.formEnvio.submit();
  660. }
  661. function nooverwrite () {
  662. document.formEnvio.return_get_answer.value = 2;
  663. document.formEnvio.submit();
  664. }
  665. //]]>
  666. </script>";
  667. $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;
  668. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  669. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  670. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  671. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  672. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  673. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  674. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  675. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  676. <input type='hidden' name='return_get_answer'/> ";
  677. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  678. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  679. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  680. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  681. print " </form>";
  682. print $OUTPUT->box_end();
  683. }
  684. }
  685. } // if ($this->write_solution == 1)
  686. print $OUTPUT->footer();
  687. die();
  688. } // function get_answer()
  689. /// Export in file the answer of student.
  690. function export_file_answer () {
  691. global $DB;
  692. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  693. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  694. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  695. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  696. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  697. $extensions = explode(",", $iassign_ilm->extension);
  698. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  699. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  700. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  701. header("Pragma: public");
  702. header("Expires: 0");
  703. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  704. header("Cache-Control: private", false);
  705. header("Content-Type: document/unknown");
  706. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  707. set_time_limit(0);
  708. print($iassign_submission->answer);
  709. exit;
  710. } // function export_file_answer()
  711. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  712. // @calledby $this->export_package_answer()
  713. //TODO Precisa terminar! //TODO_HTML
  714. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  715. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  716. <head>
  717. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  718. $str_html .= " </head>
  719. <body>\n";
  720. $tam = sizeof($array_iassign_name);
  721. for ($ii=0; $ii<$tam; $ii++) {
  722. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  723. }
  724. $str_html .= "
  725. </body>\n</html>";
  726. return $str_html;
  727. }
  728. /// Export an package (zip) with all answer of students
  729. // @calledby $this->action()
  730. function export_package_answer () {
  731. global $DB, $CFG, $OUTPUT;
  732. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  733. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  734. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  735. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  736. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  737. $userid = optional_param('userid', NULL, PARAM_INT);
  738. $iassign_user = $DB->get_record("user", array("id" => $userid));
  739. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  740. //TODO_HTML echo "username=$username<br/>"; exit;
  741. $current_date = date('Y_m_d_H');
  742. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  743. // If temporary directory under Moodle data does not exists => create it
  744. if (!is_dir($diretorio)) {
  745. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  746. // created directory with permissions to be seen by everyone
  747. }
  748. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  749. if (!is_writable($diretorio)) { // send a highlighted message!
  750. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  751. exit; // just in case
  752. }
  753. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  754. $zip = new zip_archive(); // create ZIP
  755. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  756. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  757. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  758. $vet_student_filename = array();
  759. $vet_student_content = array();
  760. foreach ($iassign_statements as $iassign_statement) {
  761. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  762. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  763. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  764. $extensions = explode(",", $iassign_ilm->extension);
  765. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  766. if ($iassign_submission) {
  767. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  768. $student_content = $iassign_submission->answer;
  769. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  770. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  771. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  772. if ($resp) {
  773. $vet_student_filename[] = $student_filename;
  774. $vet_student_content[] = $student_content;
  775. }
  776. else { // send a highlighted message!
  777. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  778. exit; // just in case
  779. }
  780. }
  781. }
  782. $zip->close(); // close the ZIP file
  783. if (count($vet_student_filename)>0) {
  784. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  785. $result_tf = $vet_result[0];
  786. $filenameZip = $vet_result[1]->filename;
  787. }
  788. iassign_utils::download_file($zip_filename); // download the ZIP file
  789. exit;
  790. } // function export_package_answer()
  791. /// Editing status of interactive activities
  792. function edit_status () {
  793. global $USER, $DB, $OUTPUT;
  794. $newentry = new stdClass();
  795. $newentry->id = $this->iassign_submission_current;
  796. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  797. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  798. if ($iassign_submission->status != 0 && $newentry->status == 0)
  799. $newentry->status = $iassign_submission->status;
  800. $newentry->teacher = $USER->id;
  801. if (!$DB->update_record('iassign_submission', $newentry))
  802. print_error('error_update', 'iassign');
  803. else {
  804. // Trigger module viewed event.
  805. $event = \mod_iassign\event\submission_updated::create(array(
  806. 'objectid' => $this->iassign->id,
  807. 'context' => $this->context
  808. ));
  809. $event->add_record_snapshot('course', $this->course);
  810. $event->trigger();
  811. $this->action = 'viewsubmission';
  812. $this->view_iassign_current();
  813. } // if (!$DB->update_record('iassign_submission', $newentry))
  814. } // function edit_status()
  815. /// Editing grade of interactive activities
  816. function edit_grade () {
  817. global $USER, $DB, $OUTPUT;
  818. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  819. if ($newgrade && $newgrade >= 0) {
  820. $newentry = new stdClass();
  821. $newentry->id = $this->iassign_submission_current;
  822. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  823. $newentry->teacher = $USER->id;
  824. if (!$DB->update_record('iassign_submission', $newentry))
  825. print_error('error_update', 'iassign');
  826. else {
  827. // Trigger module viewed event.
  828. $event = \mod_iassign\event\submission_updated::create(array(
  829. 'objectid' => $this->iassign->id,
  830. 'context' => $this->context
  831. ));
  832. $event->add_record_snapshot('course', $this->course);
  833. $event->trigger();
  834. }
  835. } // if ($newgrade >= 0)
  836. $this->action = 'viewsubmission';
  837. $this->view_iassign_current();
  838. }
  839. /// Add or Edit interactive activities
  840. // @calledby $this->action()
  841. function add_edit_iassign () {
  842. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  843. require_once('iassign_form.php');
  844. $id = $this->cm->id;
  845. $iassignid = $this->iassign->id;
  846. $param = new stdClass();
  847. $param->action = $this->action; // oculto
  848. $param->id = $id; // oculto
  849. $COURSE->cm = $id;
  850. $COURSE->iassignid = $iassignid;
  851. $COURSE->iassign_file_id = NULL;
  852. $context = context_module::instance($this->cm->id);
  853. $contextuser = context_user::instance($USER->id);
  854. $component = 'mod_iassign';
  855. $filearea = 'exercise';
  856. if (!empty($this->iassign_current))
  857. $COURSE->iassign_id = $this->iassign_current;
  858. else
  859. $COURSE->iassign_id = 0;
  860. $total_of_activities = 0; // get the total number of activities in this iAssign block
  861. if ($this->action == 'add') {
  862. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  863. $params = array('iassignid' => $iassignid);
  864. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  865. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  866. $total_of_activities = count($iassign_statement);
  867. $param->iassignid = $iassignid;
  868. $param->name = "";
  869. $param->oldname = "";
  870. $param->type_iassign = 3;
  871. $param->proposition = "";
  872. $author = $DB->get_record("user", array("id" => $USER->id));
  873. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  874. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  875. $param->author = $param->author_name;
  876. $param->author_modified = $param->author_modified_name;
  877. $COURSE->iassign_list = array();
  878. $param->iassign_list = array();
  879. if ($iassign_statement) {
  880. foreach ($iassign_statement as $iassign) {
  881. $iassignid = $iassign->id;
  882. $param->iassign_list[$iassignid] = 0;
  883. $COURSE->iassign_list[$iassignid] = new stdClass();
  884. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  885. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  886. $COURSE->iassign_list[$iassignid]->enable = 1;
  887. } // foreach ($iassign_statement as $iassign)
  888. }
  889. $param->iassign_ilmid = 0;
  890. //echo "locallib.php: add_edit_iassign(): add<br/>";
  891. $param->file = 0;
  892. $param->fileold = 0;
  893. $param->filename = "";
  894. $param->grade = $iassign_data->grade;
  895. $param->timemodified = time();
  896. $param->timecreated = time();
  897. $param->timeavailable = $iassign_data->timeavailable;
  898. $param->timedue = $iassign_data->timedue;
  899. $param->preventlate = $iassign_data->preventlate;
  900. $param->test = $iassign_data->test;
  901. $param->special_param1 = 0;
  902. $param->visible = 1;
  903. $param->max_experiment = $iassign_data->max_experiment;
  904. $param->dependency = 0;
  905. $param->automatic_evaluate = 1;
  906. $param->show_answer = 1;
  907. } // if ($this->action == 'add')
  908. elseif ($this->action == 'edit') {
  909. $COURSE->iassign_list = array();
  910. $this_activity = $this->activity->get_activity();
  911. if ($this_activity != null) {
  912. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  913. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  914. $param->iassign_id = $iassign_statement_current->id; // oculto
  915. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  916. $param->name = $iassign_statement_current->name;
  917. $param->oldname = $iassign_statement_current->name;
  918. $param->type_iassign = $iassign_statement_current->type_iassign;
  919. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  920. //2019 $param->proposition = $iassign_statement_current->proposition;
  921. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  922. $param->author_name = $iassign_statement_current->author_name; // oculto
  923. $param->author = $iassign_statement_current->author_name;
  924. $author = $DB->get_record("user", array('id' => $USER->id));
  925. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  926. $param->author_modified = $param->author_modified_name;
  927. $dependency = explode(';', $iassign_statement_current->dependency);
  928. $param->iassign_list = array();
  929. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  930. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  931. $array_dependency = array();
  932. $subdependency = "";
  933. $sub_subdependency = "";
  934. // dependent on this exercise
  935. if ($iassign_statement_dependency) {
  936. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  937. // to whom this exercise depends
  938. foreach ($inter as $tmp)
  939. $sub_subdependency .= $this->search_sub_dependency($tmp);
  940. $list_dependency = $subdependency . $sub_subdependency;
  941. $array_dependency = explode(";", $list_dependency);
  942. }
  943. // Get all activity with the same iLM - iassignid
  944. $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";
  945. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  946. $total_of_activities = count($all_others_iassign_statement) + 1;
  947. $inter = array();
  948. if ($all_others_iassign_statement) {
  949. foreach ($all_others_iassign_statement as $iassign)
  950. if (in_array($iassign->id, $dependency))
  951. $inter[] = $iassign->id;
  952. }
  953. if ($all_others_iassign_statement) {
  954. foreach ($all_others_iassign_statement as $iassign) {
  955. $iassignid = $iassign->id;
  956. $COURSE->iassign_list[$iassignid] = new stdClass();
  957. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  958. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  959. if (in_array($iassignid, $dependency))
  960. $param->iassign_list[$iassignid] = 1;
  961. else
  962. $param->iassign_list[$iassignid] = 0;
  963. if (in_array($iassignid, $array_dependency))
  964. $COURSE->iassign_list[$iassignid]->enable = 0;
  965. else
  966. $COURSE->iassign_list[$iassignid]->enable = 1;
  967. } // foreach ($all_others_iassign_statement as $iassign)
  968. }
  969. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  970. $param->fileold = 0;
  971. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  972. $param->filename = '';
  973. $param->grade = $iassign_statement_current->grade;
  974. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  975. $param->timeavailable = $iassign_statement_current->timeavailable;
  976. $param->timedue = $iassign_statement_current->timedue;
  977. $param->preventlate = $iassign_statement_current->preventlate;
  978. $param->test = $iassign_statement_current->test;
  979. $param->special_param1 = $iassign_statement_current->special_param1;
  980. $param->position = $iassign_statement_current->position; // oculto
  981. $param->visible = $iassign_statement_current->visible;
  982. $param->max_experiment = $iassign_statement_current->max_experiment;
  983. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  984. $param->show_answer = $iassign_statement_current->show_answer;
  985. $fs = get_file_storage(); // Get reference to all files in Moodle data
  986. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  987. if ($files) {
  988. foreach ($files as $file) {
  989. if ($file->get_filename() != '.') {
  990. $param->filename = $file->get_filename();
  991. $param->file = $file->get_id();
  992. $param->fileold = $file->get_id();
  993. $COURSE->iassign_file_id = $file->get_id();
  994. }
  995. }
  996. }
  997. //TODO //MOOC2014 -- inicio
  998. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  999. //D if ($iassign_ilm_configs) {
  1000. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1001. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1002. //D } //MOOC2014 -- fim
  1003. } // if ($this_activity != null)
  1004. } // elseif ($this->action == 'edit')
  1005. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1006. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1007. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1008. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1009. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1010. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1011. $param->position = $total_of_activities;
  1012. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1013. $mform->set_data($param);
  1014. if ($mform->is_cancelled()) {
  1015. $this->return_home_course('iassign_cancel');
  1016. exit;
  1017. }
  1018. else { // if ($mform->is_cancelled())
  1019. $result = $mform->get_data();
  1020. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1021. if ($result) {
  1022. $result->context = $context;
  1023. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1024. $result->grade = 0;
  1025. if ($result->type_iassign == 1) {
  1026. $result->automatic_evaluate = 0;
  1027. $result->show_answer = 0;
  1028. }
  1029. elseif ($result->automatic_evaluate == 0)
  1030. $result->show_answer = 0;
  1031. // $_POST['iassign_list']
  1032. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1033. if ($result->iassign_list) {
  1034. foreach ($result->iassign_list as $key => $value)
  1035. $result->dependency .= $key . ';';
  1036. }
  1037. else
  1038. $result->dependency = 0;
  1039. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1040. //TODO Then get it directly from the form data $_POST!
  1041. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1042. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1043. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1044. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1045. if ($this->action == 'add') {
  1046. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1047. if ($iassign_statement_name) {
  1048. $this->return_home_course('error_iassign_name');
  1049. die();
  1050. }
  1051. // Really insert the new iActivity in table '*_iassign_statement'
  1052. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1053. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1054. // Trigger module viewed event.
  1055. $event = \mod_iassign\event\iassign_created::create(array(
  1056. 'objectid' => $iassignid,
  1057. 'context' => $context
  1058. ));
  1059. $event->add_record_snapshot('course', $this->course);
  1060. $event->trigger();
  1061. $this->return_home_course('iassign_add');
  1062. } // if ($this->action == 'add')
  1063. elseif ($this->action == 'edit') {
  1064. $iassignid = $this->activity->update_iassign($result);
  1065. $this->activity->update_calendar($iassignid, $result->oldname);
  1066. // Trigger module viewed event.
  1067. $event = \mod_iassign\event\iassign_updated::create(array(
  1068. 'objectid' => $iassignid,
  1069. 'context' => $context
  1070. ));
  1071. $event->add_record_snapshot('course', $this->course);
  1072. $event->trigger();
  1073. $this->return_home_course('iassign_update');
  1074. } // elseif ($this->action == 'edit')
  1075. die();
  1076. } // if ($result)
  1077. } // else if ($mform->is_cancelled())
  1078. print $OUTPUT->header();
  1079. $mform->display();
  1080. print $OUTPUT->footer();
  1081. die();
  1082. } // function add_edit_iassign()
  1083. /// Search for dependencies
  1084. function search_dependency ($search_iassing_id, $iassign_statement) {
  1085. global $DB, $OUTPUT;
  1086. $dependency = "";
  1087. if ($iassign_statement)
  1088. foreach ($iassign_statement as $iassign) {
  1089. $inter_dependency = explode(';', $iassign->dependency);
  1090. if (in_array($search_iassing_id, $inter_dependency)) {
  1091. $dependency .= $iassign->id . ";";
  1092. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1093. } // if (in_array($search_iassing_id, $inter_dependency))
  1094. } // foreach ($iassign_statement as $iassign)
  1095. return $dependency;
  1096. }
  1097. /// Search for "sub"dependency
  1098. function search_sub_dependency ($search_iassing_id) {
  1099. global $DB, $OUTPUT;
  1100. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1101. $dependency = "";
  1102. if ($iassign_statement) {
  1103. $inter_dependency = explode(';', $iassign_statement->dependency);
  1104. foreach ($inter_dependency as $tmp) {
  1105. if ($tmp != 0)
  1106. $dependency .= $tmp . ";";
  1107. $dependency .= $this->search_sub_dependency($tmp);
  1108. } // foreach ($inter_dependency as $tmp)
  1109. } // if ($iassign_statement)
  1110. return $dependency;
  1111. }
  1112. // Warning message
  1113. static function warning_message_iassign ($strcode) {
  1114. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1115. }
  1116. /// Update grade of iAssign
  1117. // Called always any iAssign activity is created
  1118. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1119. static function update_grade_iassign ($iassignid) {
  1120. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1121. require_once($CFG->libdir . '/gradelib.php');
  1122. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1123. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1124. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1125. // Each iAssign item is associated with one item on the "gradebook"
  1126. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1127. //$sum_grade = 0;
  1128. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1129. //foreach($grade as $tmp) {
  1130. // $sum_grade += $tmp->grade;
  1131. // }
  1132. //1 Solution 1
  1133. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1134. //1 $sum_grade = 0; //1
  1135. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1136. //2 Solution 2
  1137. $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
  1138. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1139. if (key($array_sum_grade))
  1140. $sum_grade = key($array_sum_grade); //2
  1141. else
  1142. $sum_grade = 0; //2
  1143. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1144. $grades = NULL;
  1145. $params = array('itemname' => $grade_iassign->name);
  1146. $params['iteminstance'] = $iassignid;
  1147. $params['gradetype'] = GRADE_TYPE_VALUE;
  1148. //2016 if ($sum_grade != 0) {
  1149. $params['grademax'] = $sum_grade;
  1150. $params['rawgrademax'] = $sum_grade;
  1151. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1152. $params['grademin'] = 0;
  1153. // @calls /lib/gradelib.php: call to grade_item->insert()
  1154. //TODO: is there any error here in Moodle version 3.0?
  1155. //TODO: Incorrect property 'grademax' found when inserting grade object
  1156. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1157. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1158. }
  1159. /// Update grade of student
  1160. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1161. global $CFG, $DB, $OUTPUT;
  1162. require_once($CFG->libdir . '/gradelib.php');
  1163. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1164. // Review all the student submission for this iAssign activity
  1165. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1166. $total_grade = 0;
  1167. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1168. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1169. if ($iassign_submission)
  1170. $total_grade += $iassign_submission->grade;
  1171. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1172. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1173. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1174. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1175. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1176. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1177. $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
  1178. if (key($array_sum_grade))
  1179. $sum_grade = key($array_sum_grade); //2
  1180. else
  1181. $sum_grade = 0; //2
  1182. $grades['userid'] = $userid;
  1183. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1184. $params = array('itemname' => $grade_iassign->name);
  1185. $params['iteminstance'] = $iassignid;
  1186. $params['gradetype'] = GRADE_TYPE_VALUE;
  1187. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1188. $params['grademax'] = $sum_grade;
  1189. $params['rawgrademax'] = $sum_grade;
  1190. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1191. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1192. }
  1193. /// Display caption of icons
  1194. function view_legend_icons () {
  1195. global $USER, $CFG, $DB, $OUTPUT;
  1196. $id = $this->cm->id;
  1197. if ($this->action == 'print')
  1198. print '<table border=1 width=100%><tr>';
  1199. else
  1200. print '<table width=100%><tr>';
  1201. print '<td >';
  1202. if ($this->action != 'print')
  1203. print $OUTPUT->help_icon('legend', 'iassign');
  1204. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1205. // $imagetext = '');
  1206. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1207. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1208. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1209. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1210. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1211. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1212. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1213. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1214. print '</td>' . "\n";
  1215. if ($this->action != 'print') {
  1216. $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>";
  1217. $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>";
  1218. $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>";
  1219. $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>";
  1220. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1221. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1222. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1223. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1224. } // if ($this->action != 'print')
  1225. print '</tr></table>' . "\n";
  1226. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1227. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1228. $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>";
  1229. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1230. print '</tr></table>' . "\n";
  1231. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1232. else
  1233. print '</td></tr></table>' . "\n";
  1234. } // function view_legend_icons()
  1235. /// Display activity current
  1236. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1237. function view_iassign_current () {
  1238. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1239. $id = $this->cm->id;
  1240. $iassignid = $this->iassign->id;
  1241. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1242. $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
  1243. // 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 ...
  1244. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1245. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1246. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1247. // 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
  1248. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1249. // log record
  1250. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1251. //Trigger module viewed event.
  1252. $event = \mod_iassign\event\submission_viewed::create(array(
  1253. 'objectid' => $iassign->id,
  1254. 'context' => $this->context,
  1255. 'other' => $info
  1256. ));
  1257. $event->add_record_snapshot('course', $this->course);
  1258. $event->trigger();
  1259. // Search of iLM data used in the current activity
  1260. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1261. // Add actual activity to navbar:
  1262. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1263. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1264. print $OUTPUT->header();
  1265. if ($this->action == 'viewsubmission') {
  1266. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1267. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1268. else
  1269. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1270. } else {
  1271. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1272. }
  1273. if ($iassign_submission)
  1274. $this->update_comment($iassign_submission->id);
  1275. $file = $iassign_statement_activity_item->file;
  1276. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1277. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1278. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1279. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1280. $this->bottonPost = 0; // hide submit button
  1281. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1282. $this->view_iassign = false; // disable visualization of activity
  1283. $repeat = "";
  1284. $last_iassign = "";
  1285. $student_answer = "";
  1286. $comment = "";
  1287. // *** Teacher access (view learner's submission)
  1288. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1289. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1290. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1291. // ---> access teacher for test
  1292. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1293. $this->bottonPost = 1;
  1294. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1295. $this->activity->view_dates();
  1296. $USER->iassignEdit = $this->bottonPost;
  1297. $this->activity->show_info_iassign();
  1298. if ($iassign_submission) {
  1299. //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;
  1300. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1301. } else {
  1302. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1303. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1304. }
  1305. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1306. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1307. // Prepare tags to present the iLM
  1308. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1309. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1310. // *** (end) Teacher access (view the activity)
  1311. // *** Teacher access (view learner's submission to the activity)
  1312. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1313. // It is teacher or 'nonediting teacher' that can evaluate
  1314. // ----> area teacher evaluate
  1315. $row = optional_param('row', 0, PARAM_INT);
  1316. $column = optional_param('column', 0, PARAM_INT);
  1317. $link_next = iassign_icons::insert('right_disable');
  1318. $link_previous = iassign_icons::insert('left_disable');
  1319. $link_up = iassign_icons::insert('up_disable');
  1320. $link_down = iassign_icons::insert('down_disable');
  1321. // next_activity
  1322. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1323. $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);
  1324. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1325. }
  1326. // previous_activity
  1327. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1328. $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);
  1329. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1330. }
  1331. // previous_student
  1332. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1333. $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);
  1334. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1335. }
  1336. // next_student
  1337. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1338. $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);
  1339. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1340. }
  1341. if ($iassign_submission) {
  1342. $student_answer = $iassign_submission->answer;
  1343. }
  1344. $last_iassign = get_string('last_iassign', 'iassign');
  1345. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1346. // Messages related to due date (and user role)
  1347. $this->activity->view_dates();
  1348. print $OUTPUT->box_start();
  1349. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1350. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1351. print $OUTPUT->user_picture($user_data);
  1352. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1353. print '</td>' . "\n";
  1354. print '<td width=20% align=right>' . "\n";
  1355. print '<table width=50 cellpadding="0">';
  1356. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1357. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1358. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1359. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1360. print '</table>' . "\n";
  1361. print '</td></tr></table>' . "\n";
  1362. print $OUTPUT->box_end();
  1363. print $OUTPUT->box_start();
  1364. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1365. print '<td width=60% valign="top">' . "\n";
  1366. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1367. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1368. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1369. $resp = get_string('yes');
  1370. else
  1371. $resp = get_string('no');
  1372. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1373. if ($iassign_statement_activity_item->show_answer == 1)
  1374. $resp = get_string('yes');
  1375. else
  1376. $resp = get_string('no');
  1377. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1378. print '</td>';
  1379. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1380. print '<td width=40% valign="top" align="left">';
  1381. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1382. // check status of solution sent by the student
  1383. if ($iassign_submission) {
  1384. switch ($iassign_submission->status) {
  1385. case 3 :
  1386. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1387. break;
  1388. case 2 :
  1389. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1390. break;
  1391. case 1 :
  1392. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1393. break;
  1394. default :
  1395. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1396. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1397. } // switch ($iassign_submission->status)
  1398. }
  1399. else { // if ($iassign_submission)
  1400. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1401. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1402. }
  1403. // update_status
  1404. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1405. $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);
  1406. print " <script type='text/javascript'>
  1407. //<![CDATA[
  1408. function overwriteStatus (newstatus) {
  1409. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1410. document.formEditStatus.return_status.value=newstatus;
  1411. document.formEditStatus.submit();
  1412. }
  1413. else
  1414. document.formEditStatus.return_status.value=-1;
  1415. }
  1416. //]]>
  1417. </script>";
  1418. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1419. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1420. 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";
  1421. print " <input type='hidden' name='return_status'>\n";
  1422. print "</form>\n";
  1423. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1424. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1425. $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);
  1426. print "
  1427. <script type='text/javascript'>
  1428. //<![CDATA[
  1429. function overwriteGrade (newgrade,maxgrade) {
  1430. if (newgrade<0 || newgrade>maxgrade) {
  1431. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1432. document.formEditGrade.return_grade.value=-1;
  1433. document.formEditGrade.submit();
  1434. }
  1435. else {
  1436. document.formEditGrade.return_grade.value=newgrade;
  1437. document.formEditGrade.submit();
  1438. }
  1439. }
  1440. //]]>
  1441. </script>";
  1442. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1443. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1444. print " <input type='text' name='grade' size='6'>";
  1445. print " <input type='hidden' name='return_grade'> ";
  1446. 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";
  1447. print "</form>";
  1448. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1449. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1450. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1451. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1452. if ($teacher)
  1453. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1454. } // if ($iassign_submission->experiment > 0)
  1455. print '</td>';
  1456. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1457. print '</tr></table>';
  1458. print $OUTPUT->box_end();
  1459. $USER->iassignEdit = $this->bottonPost;
  1460. if ($iassign_submission && $allow_resubmission) {
  1461. // Put the iLM to
  1462. print $OUTPUT->box_start();
  1463. print '<p><strong>' . $last_iassign . '</strong></p>';
  1464. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1465. $enderecoPOST = "";
  1466. // Prepare tags to present the iLM
  1467. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1468. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1469. print $OUTPUT->box_end();
  1470. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1471. // ATTENTION: exception used by iGeom (exercise with "script")
  1472. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1473. if (substr($ilm_name, 0, 5)=="igeom") {
  1474. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1475. $loadTeacherActivity = true;
  1476. }
  1477. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1478. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1479. // Prepare tags to present the iLM
  1480. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1481. }
  1482. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1483. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1484. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1485. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1486. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1487. // *** (end) Teacher access (view learner's submission to the activity)
  1488. // *** Student access (view the activity)
  1489. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1490. // It could be the learner (he could send or resend the activity)
  1491. // ---> access student
  1492. $time_now = time();
  1493. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1494. // activity of type example - not submit button for submission
  1495. $this->view_iassign = true;
  1496. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1497. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1498. // activity of type test - iLM automatic evaluator - submit button for submission
  1499. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1500. $this->bottonPost = 1;
  1501. $this->view_iassign = true;
  1502. } else
  1503. $this->view_iassign = false;
  1504. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1505. // activity of type exercise (learner can send his answer, if yet open...)
  1506. $this->view_iassign = true;
  1507. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1508. $this->view_iassign = false;
  1509. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1510. $this->bottonPost = 1; // allow the submit button
  1511. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1512. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1513. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1514. if (!$iassign_submission) {
  1515. $str_iassign_submission_id = '';
  1516. $str_iassign_submission_answer = '';
  1517. }
  1518. else {
  1519. $str_iassign_submission_id = $iassign_submission->id;
  1520. $str_iassign_submission_answer = $iassign_submission->answer;
  1521. }
  1522. if ($this->action != 'repeat') {
  1523. $repeat = "<a href='view.php?action=repeat&id="
  1524. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1525. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1526. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1527. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1528. }
  1529. $this->bottonPost = 1;
  1530. $this->write_solution = 1; // can register his submission
  1531. $student_answer = $str_iassign_submission_answer;
  1532. }
  1533. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1534. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1535. $last_iassign = get_string('last_iassign', 'iassign');
  1536. if ($iassign_submission) {
  1537. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1538. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1539. $student_answer = $iassign_submission->answer;
  1540. } else {
  1541. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1542. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1543. }
  1544. }
  1545. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1546. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1547. $this->bottonPost = 1;
  1548. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1549. } else {
  1550. $last_iassign = get_string('last_iassign', 'iassign');
  1551. if ($iassign_submission) {
  1552. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1553. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1554. $student_answer = $iassign_submission->answer;
  1555. } else {
  1556. // Symbol of "redo activity"
  1557. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1558. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1559. }
  1560. }
  1561. } // elseif ($iassign_statement_activity_item->test == 1)
  1562. elseif ($iassign_statement_activity_item->test == 0)
  1563. $this->view_iassign = false;
  1564. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1565. if ($iassign_submission)
  1566. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1567. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1568. else
  1569. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1570. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1571. $this->activity->view_dates();
  1572. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1573. print $OUTPUT->box_start();
  1574. print '<table width=100% border=0 valign="top">' . "\n";
  1575. print '<tr><td width=60% valign="top">' . "\n";
  1576. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1577. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1578. $flag_dependency = true;
  1579. if ($iassign_statement_activity_item->type_iassign == 3) {
  1580. if ($iassign_statement_activity_item->dependency == 0) {
  1581. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1582. } else {
  1583. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1584. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1585. foreach ($dependencys as $dependency) {
  1586. if ($dependency) {
  1587. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1588. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1589. if ($dependencysubmissions) {
  1590. if ($dependencysubmissions->status == 3)
  1591. $icon = iassign_icons::insert('correct');
  1592. elseif ($dependencysubmissions->status == 2) {
  1593. $icon = iassign_icons::insert('incorrect');
  1594. $flag_dependency = false;
  1595. } elseif ($dependencysubmissions->status == 1) {
  1596. $icon = iassign_icons::insert('post');
  1597. $flag_dependency = false;
  1598. } elseif ($dependencysubmissions->status == 0) {
  1599. $icon = iassign_icons::insert('not_post');
  1600. $flag_dependency = false;
  1601. }
  1602. } else {
  1603. $icon = iassign_icons::insert('not_post');
  1604. $flag_dependency = false;
  1605. } // if ($dependencysubmissions)
  1606. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1607. } // if ($dependency)
  1608. } // foreach ($dependencys as $dependency)
  1609. } // if ($iassign_statement_activity_item->dependency == 0)
  1610. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1611. if ($flag_dependency == false) {
  1612. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1613. $this->view_iassign = false;
  1614. print '</tr></table>' . "\n";
  1615. }
  1616. else {
  1617. $this->view_iassign = true;
  1618. print '</td>' . "\n";
  1619. } // if ($flag_dependency == false)
  1620. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1621. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1622. // receiver=1 - message to teacher
  1623. // receiver=2 - message to student
  1624. if ($iassign_submission) {
  1625. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1626. if ($verify_message)
  1627. $comment = iassign_icons::insert('comment_unread');
  1628. }
  1629. print '<td width=40% valign="top" align="left">';
  1630. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1631. if ($iassign_statement_activity_item->show_answer == 1) {
  1632. // check status of solution sent by the student
  1633. if ($iassign_submission) {
  1634. switch ($iassign_submission->status) {
  1635. case 3 :
  1636. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1637. break;
  1638. case 2 :
  1639. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1640. break;
  1641. case 1 :
  1642. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1643. break;
  1644. default :
  1645. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1646. $repeat = "";
  1647. $last_iassign = "";
  1648. } // switch ($iassign_submission->status)
  1649. } else {
  1650. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1651. $repeat = "";
  1652. $last_iassign = "";
  1653. }
  1654. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1655. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  1656. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  1657. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  1658. if ($iassign_statement_activity_item->max_experiment == 0)
  1659. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  1660. else {
  1661. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  1662. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  1663. $repeat = "";
  1664. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  1665. $this->bottonPost = 0;
  1666. $this->write_solution = 0;
  1667. }
  1668. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  1669. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  1670. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1671. if ($teacher)
  1672. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  1673. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  1674. } // if ($iassign_statement_activity_item->show_answer==1)
  1675. else {
  1676. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  1677. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1678. $repeat = "";
  1679. $last_iassign = "";
  1680. } elseif ($iassign_submission->status == 1) {
  1681. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1682. }
  1683. }
  1684. print '</td>';
  1685. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1686. print '</tr></table>' . "\n";
  1687. // Presents the iLM
  1688. print '<table width=100% border=0 valign="top">' . "\n";
  1689. print '<td width=80% align="left">';
  1690. 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\".
  1691. print '<td width=20% align="rigth">';
  1692. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  1693. print $repeat; // symbol of "redo activity"
  1694. print '</td></tr></table>' . "\n";
  1695. //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)'
  1696. $output = '';
  1697. if (!$iassign_ilm) {
  1698. $iassign_ilm = new stdClass();
  1699. $iassign_ilm->file_jar = "";
  1700. }
  1701. $output .= $OUTPUT->box_start();
  1702. $USER->iassignEdit = $this->bottonPost;
  1703. // ---
  1704. // Presents the iLM
  1705. // Prepare tags to present the iLM
  1706. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  1707. $student_answer = ""; //?
  1708. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  1709. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  1710. $student_answer = "";
  1711. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  1712. } else {
  1713. // When student is redoing his activity
  1714. // ATTENTION: exception used by iGeom (exercise with "script")
  1715. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  1716. if (substr($ilm_name, 0, 5)=="igeom") {
  1717. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1718. $loadTeacherActivity = true;
  1719. }
  1720. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  1721. }
  1722. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  1723. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  1724. //1 $history_comment = '';
  1725. //1 if ($iassign_submission) {
  1726. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  1727. //1 }
  1728. //1 if (!empty($history_comment)) {
  1729. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  1730. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  1731. //1 $output .= $history_comment;
  1732. //1 $output .= "</table>\n";
  1733. //1 }
  1734. //1 $output .= "</form></center>\n";
  1735. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  1736. //1 }
  1737. $output .= $OUTPUT->box_end();
  1738. print $output;
  1739. } // if ($this->view_iassign)
  1740. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  1741. } // if ($this->view_iassign)
  1742. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1743. else
  1744. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1745. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  1746. print '<table width=100% border=0 valign="top">' . "\n";
  1747. print '<tr><td width=60% valign="top">' . "\n";
  1748. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1749. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1750. print '</tr></table>' . "\n";
  1751. $student_answer = "";
  1752. $enderecoPOST = "";
  1753. // Prepare tags to present the iLM
  1754. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  1755. print $output;
  1756. }
  1757. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  1758. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1759. 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
  1760. // Put a block with area to sent/answer comments
  1761. $output = '';
  1762. $history_comment = '';
  1763. $row = optional_param('row', 0, PARAM_INT);
  1764. $column = optional_param('column', 0, PARAM_INT);
  1765. if ($iassign_submission) {
  1766. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1767. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1768. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1769. }
  1770. else {
  1771. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1772. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1773. }
  1774. $output .= $OUTPUT->box_start();
  1775. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  1776. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  1777. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  1778. $output .= "</form></center>\n";
  1779. if (!empty($history_comment)) {
  1780. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  1781. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  1782. $output .= $history_comment;
  1783. $output .= "</table>";
  1784. }
  1785. $output .= $OUTPUT->box_end();
  1786. print $output;
  1787. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1788. // final block 'studant'
  1789. print $OUTPUT->footer();
  1790. die();
  1791. } // function view_iassign_current()
  1792. /// Export the data from performance report into CSV file format
  1793. function export_csv () {
  1794. global $USER, $CFG, $DB, $OUTPUT;
  1795. $str = "";
  1796. $fields = "student_id, student_name";
  1797. // Finding all iassign activities for the iassign:
  1798. $id = $this->cm->id;
  1799. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1800. $c = 1;
  1801. foreach ($iassign_list as $iassign) {
  1802. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  1803. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  1804. $c ++;
  1805. }
  1806. // Finding enrolled students:
  1807. $params = array('shortname' => 'student');
  1808. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  1809. $context = context_course::instance($this->course->id);
  1810. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1811. $students = $DB->get_records_sql(
  1812. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1813. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1814. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1815. foreach ($students as $student) {
  1816. $str .= $student->userid . ',';
  1817. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  1818. foreach ($iassign_list as $iassign) {
  1819. $str .= ',' . $iassign->id . ',';
  1820. $str .= '"' . $iassign->name . '",';
  1821. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  1822. if ($student_submissions) {
  1823. $str .= $student_submissions->experiment . ',';
  1824. $str .= $student_submissions->grade . ',';
  1825. switch ($student_submissions->status) {
  1826. case 3:
  1827. $str .= '"correct",';
  1828. break;
  1829. case 2:
  1830. $str .= '"incorrect",';
  1831. break;
  1832. case 1:
  1833. $str .= '"post",';
  1834. break;
  1835. case 0:
  1836. $str .= '"not_post",';
  1837. break;
  1838. }
  1839. } else {
  1840. $str .= ',,"not_post",';
  1841. }
  1842. $str .= $iassign->iassign_ilmid . ',';
  1843. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  1844. $str .= '"' . $ilm_activity->name . '"';
  1845. }
  1846. $str .= "\n";
  1847. }
  1848. $str = $fields . "\n" . $str;
  1849. header("Content-type: text/csv");
  1850. header("Content-disposition: attachment; filename=report.csv");
  1851. header("Pragma: no-cache");
  1852. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  1853. header('Content-Length: ' . strlen($str));
  1854. header('Connection: close');
  1855. print $str;
  1856. flush();
  1857. } // function export_csv()
  1858. /// Display report of performance
  1859. function report () {
  1860. global $USER, $CFG, $DB, $OUTPUT;
  1861. $id = $this->cm->id;
  1862. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1863. if ($this->action != 'print') {
  1864. $title = get_string('report', 'iassign');
  1865. print $OUTPUT->header();
  1866. } // if ($this->action != 'print')
  1867. print $OUTPUT->box_start();
  1868. $this->view_legend_icons();
  1869. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  1870. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  1871. print $OUTPUT->box_end();
  1872. if ($this->action == 'print')
  1873. print '<table border=1 width="100%">' . "\n";
  1874. else
  1875. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1876. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  1877. // $num = array();
  1878. $i = 1;
  1879. $num = array();
  1880. foreach ($iassign_list as $iassign) {
  1881. $test_exercise = "";
  1882. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  1883. if (($iassign_submission) && $iassign->type_iassign < 3) {
  1884. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  1885. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  1886. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  1887. $num[$i] = new stdClass();
  1888. $num[$i]->name = $iassign->name;
  1889. $num[$i]->id = $i;
  1890. $num[$i]->iassignid = $iassign->id;
  1891. print ' <tr >' . "\n";
  1892. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  1893. print "<td class=\"cell c0 actvity\">";
  1894. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  1895. print ' </tr>' . "\n";
  1896. $i ++;
  1897. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  1898. } // foreach ($iassign_list as $iassign)
  1899. print "</table>";
  1900. print "<p></p>";
  1901. if ($this->action == 'print')
  1902. print '<table border=1 width="100%">' . "\n";
  1903. else
  1904. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1905. $context = context_course::instance($this->course->id);
  1906. if ($i > 1) {
  1907. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  1908. $params = array('shortname' => 'student');
  1909. $role = $DB->get_record_sql(
  1910. "SELECT s.id, s.shortname FROM {role} s " .
  1911. " WHERE s.shortname = :shortname", $params);
  1912. // $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");
  1913. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1914. $students = $DB->get_records_sql(
  1915. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1916. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1917. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1918. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  1919. for ($j = 1; $j < $i; $j ++) {
  1920. $sum_iassign_correct[$j] = 0;
  1921. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  1922. }
  1923. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  1924. $sum_iassign = $j - 1;
  1925. print '</tr>' . "\n";
  1926. $total = 0;
  1927. $sum_student = 0;
  1928. $comment = iassign_icons::insert('comment_read');
  1929. $sum_comment = 0;
  1930. $sum_correct_iassign = array();
  1931. $sum_correct_student = array();
  1932. $USER->matrix_iassign = array();
  1933. if ($students) {
  1934. $w = 0;
  1935. foreach ($students as $tmp) {
  1936. $users_array[$w] = $tmp;
  1937. $w ++;
  1938. }
  1939. for ($x = 0; $x < $w; $x ++) {
  1940. print '<tr>' . "\n";
  1941. $sum_student ++;
  1942. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  1943. print ' <td >' . $name . '</td>' . "\n";
  1944. $total_student = 0;
  1945. $tentativas = 0;
  1946. for ($j = 1; $j < $i; $j ++) {
  1947. $sum_comment = 0;
  1948. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  1949. print ' <td valign="bottom" align="center">' . "\n";
  1950. if ($student_submissions) {
  1951. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  1952. $tentativas = $student_submissions->experiment;
  1953. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  1954. $params = array('iassign_submissionid' => $student_submissions->id);
  1955. $student_submissions_comment = $DB->get_record_sql(
  1956. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1957. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  1958. if ($student_submissions_comment)
  1959. foreach ($student_submissions_comment as $tmp)
  1960. $sum_comment = $tmp;
  1961. // informations to previous activities
  1962. if ($j - 1 < 1 || $j == $i)
  1963. $iassign_previous = "-1";
  1964. else
  1965. $iassign_previous = $num[$j - 1]->iassignid;
  1966. if ($x - 1 < 0 || $x == $w)
  1967. $user_previous = "-1";
  1968. else
  1969. $user_previous = $users_array[$x - 1]->userid;
  1970. // next
  1971. if ($i - 1 > $j)
  1972. $iassign_next = $num[$j + 1]->iassignid;
  1973. else
  1974. $iassign_next = "-1";
  1975. if ($w - 1 > $x)
  1976. $user_next = $users_array[$x + 1]->userid;
  1977. else
  1978. $user_next = "-1";
  1979. $position = "&row= $x&column=$j";
  1980. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  1981. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1982. $url .= $position;
  1983. // receiver=1 - message to teacher
  1984. // receiver=2 - message to student
  1985. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  1986. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  1987. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  1988. $verify_message = $DB->get_record_sql(
  1989. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1990. "WHERE iassign_submissionid = :iassign_submissionid " .
  1991. " AND return_status= :return_status " .
  1992. " AND receiver= :receiver", $params);
  1993. if ($verify_message)
  1994. foreach ($verify_message as $tmp)
  1995. $sum_verify_message = $tmp;
  1996. if ($sum_verify_message > 0)
  1997. $comment = iassign_icons::insert('comment_unread');
  1998. else
  1999. $comment = iassign_icons::insert('comment_read');
  2000. if ($student_submissions->status == 3) {
  2001. $sum_iassign_correct[$j] ++;
  2002. $total_student ++;
  2003. $feedback = iassign_icons::insert('correct');
  2004. }
  2005. elseif ($student_submissions->status == 2) {
  2006. $feedback = iassign_icons::insert('incorrect');
  2007. }
  2008. elseif ($student_submissions->status == 1) {
  2009. $feedback = iassign_icons::insert('post');
  2010. }
  2011. elseif ($student_submissions->status == 0) {
  2012. $feedback = iassign_icons::insert('not_post');
  2013. }
  2014. if ($this->action != 'print') {
  2015. print '<table><tr>';
  2016. if ($tentativas > 0)
  2017. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2018. else
  2019. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2020. print '<td> &nbsp; </td>';
  2021. print '</tr>' . "\n";
  2022. if ($sum_comment > 0 && $sum_verify_message > 0)
  2023. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2024. else if ($sum_comment > 0)
  2025. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2026. print '</table>' . "\n";
  2027. }
  2028. if ($this->action == 'print')
  2029. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2030. } // if ($student_submissions)
  2031. else { // if ($student_submissions)
  2032. // informations to browse previous activities
  2033. if ($j - 1 < 1 || $j == $i)
  2034. $iassign_previous = "-1";
  2035. else
  2036. $iassign_previous = $num[$j - 1]->iassignid;
  2037. if ($x - 1 < 0 || $x == $w)
  2038. $user_previous = "-1";
  2039. else
  2040. $user_previous = $users_array[$x - 1]->userid;
  2041. // next
  2042. if ($i - 1 > $j)
  2043. $iassign_next = $num[$j + 1]->iassignid;
  2044. else
  2045. $iassign_next = "-1";
  2046. if ($w - 1 > $x)
  2047. $user_next = $users_array[$x + 1]->userid;
  2048. else
  2049. $user_next = "-1";
  2050. $position = "&row= $x&column=$j";
  2051. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2052. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2053. $url .= $position;
  2054. $feedback = iassign_icons::insert('not_post');
  2055. if ($this->action == 'print')
  2056. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2057. else {
  2058. print '<table><tr>';
  2059. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2060. print '<td> &nbsp; </td>';
  2061. print '</tr><tr>' . "\n";
  2062. print '<td> &nbsp;</td>';
  2063. if ($sum_comment > 0)
  2064. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2065. else
  2066. print '<td> &nbsp;</td>';
  2067. print '</tr></table>';
  2068. }
  2069. } // else if ($student_submissions)
  2070. $USER->matrix_iassign[$x][$j] = new stdClass();
  2071. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2072. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2073. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2074. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2075. if ($student_submissions)
  2076. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2077. else
  2078. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2079. print '</td>' . "\n";
  2080. } // for ($j=1; $j<$i; $j++)
  2081. $total = $total + $total_student;
  2082. $porcentagem = ($total_student / ($j - 1)) * 100;
  2083. if ($tentativas != 0 && $tentativas != null) {
  2084. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2085. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2086. }
  2087. else {
  2088. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2089. }
  2090. print '</tr>' . "\n";
  2091. $sum_correct_student[$sum_student] = new stdClass();
  2092. $sum_correct_student[$sum_student]->name = $name;
  2093. $sum_correct_student[$sum_student]->sum = $total_student;
  2094. } // for ($x = 0; $x < $w; $x ++)
  2095. for ($i = 1; $i < $j; $i ++) {
  2096. if (is_null($sum_iassign_correct[$i]))
  2097. $sum_iassign_correct[$i] = 0;
  2098. $sum_correct_iassign[$i] = new stdClass();
  2099. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2100. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2101. }
  2102. // print '</tr></table>' . "\n";
  2103. }
  2104. } // if ($i>1)
  2105. else {
  2106. print_string('no_activity', 'iassign');
  2107. }
  2108. print "</table>\n";
  2109. if ($this->action != 'print')
  2110. print $OUTPUT->footer();
  2111. die();
  2112. } // function report()
  2113. /// Display graphics of performance
  2114. function stats () {
  2115. global $USER, $CFG, $DB, $OUTPUT;
  2116. $id = $this->cm->id;
  2117. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2118. if ($this->action != 'printstats')
  2119. $title = get_string('graphic', 'iassign');
  2120. $num = array();
  2121. $sum_correct_iassign = array();
  2122. $sum_correct_student = array();
  2123. $sum_student = 0;
  2124. $i = 1;
  2125. foreach ($iassign_list as $iassign) {
  2126. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2127. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2128. $sum_iassign_correct[$i] = 0;
  2129. $num[$i] = new stdClass();
  2130. $num[$i]->name = $iassign->name;
  2131. $num[$i]->id = $i;
  2132. $num[$i]->iassignid = $iassign->id;
  2133. $i ++;
  2134. } // if ($iassign->type_iassign == 3)
  2135. } // foreach ($iassign_list as $iassign)
  2136. $sum_iassign = $i - 1;
  2137. $context = context_course::instance($this->course->id);
  2138. if ($i > 1) {
  2139. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2140. $params = array('shortname' => 'student');
  2141. $role = $DB->get_record_sql(
  2142. "SELECT s.id, s.shortname FROM {role} s " .
  2143. " WHERE s.shortname = :shortname", $params);
  2144. // $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");
  2145. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2146. $students = $DB->get_records_sql(
  2147. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2148. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2149. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2150. $total = 0;
  2151. $sum_student = 0;
  2152. $j = 0;
  2153. $sum_correct_iassign = array();
  2154. $sum_correct_student = array();
  2155. $sum_experiment = array();
  2156. if ($students) {
  2157. foreach ($students as $users) {
  2158. $sum_student ++;
  2159. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2160. // rows
  2161. $total_student = 0;
  2162. for ($j = 1; $j < $i; $j ++) {
  2163. $total_experiment = 0;
  2164. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2165. if ($student_submissions) {
  2166. if ($student_submissions->status == 3) {
  2167. $sum_iassign_correct[$j] ++;
  2168. $total_student ++;
  2169. } // if ($student_submissions->status == 3)
  2170. $total_experiment += $student_submissions->experiment;
  2171. }
  2172. $sum_experiment[$j] = $total_experiment;
  2173. } // for ($j=1; $j<$i; $j++)
  2174. $total = $total + $total_student;
  2175. $sum_correct_student[$sum_student] = new stdClass();
  2176. $sum_correct_student[$sum_student]->name = $name;
  2177. $sum_correct_student[$sum_student]->sum = $total_student;
  2178. } // foreach ($students as $users)
  2179. }
  2180. for ($i = 1; $i < $j; $i ++) {
  2181. if (is_null($sum_iassign_correct[$i]))
  2182. $sum_iassign_correct[$i] = 0;
  2183. $sum_correct_iassign[$i] = new stdClass();
  2184. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2185. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2186. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2187. } // for ($i = 1; $i < $j; $i++)
  2188. } // if ($i > 1)
  2189. if ($this->action != 'printstats') {
  2190. $title = get_string('graphic', 'iassign');
  2191. print $OUTPUT->header();
  2192. $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>";
  2193. $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>";
  2194. print '<table width=100%><tr>';
  2195. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2196. print '<td width=15% align="right">' . $link_report . '</td>';
  2197. print '</td></tr></table>' . "\n";
  2198. print "<br><br>";
  2199. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2200. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2201. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2202. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2203. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2204. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2205. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2206. print '</tr>' . "\n";
  2207. $sum_correct = 0;
  2208. if ($sum_correct_iassign) {
  2209. foreach ($sum_correct_iassign as $iassign) {
  2210. if (is_null($iassign->experiment))
  2211. $iassign->experiment = 0;
  2212. $bar = "";
  2213. $sum = $iassign->sum;
  2214. $percent = ($sum / $sum_student) * 100;
  2215. $text = number_format($percent, 1) . '%';
  2216. $sum_correct += $sum;
  2217. if ($sum > 0) {
  2218. for ($i = 1; $i < $percent * 2; $i ++)
  2219. $bar .= iassign_icons::insert('hbar_blue');
  2220. $bar .= iassign_icons::insert('hbar_blue_r');
  2221. } // if ($sum > 0)
  2222. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2223. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2224. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2225. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2226. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2227. print '</tr>' . "\n";
  2228. } // foreach ($sum_correct_iassign as $iassign)
  2229. }
  2230. print "</table>";
  2231. print "<br><br>";
  2232. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2233. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2234. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2235. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2236. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2237. print '</tr>' . "\n";
  2238. $sum_correct = 0;
  2239. foreach ($sum_correct_student as $student) {
  2240. $bar = "";
  2241. $sum = $student->sum;
  2242. $percent = ($sum / $sum_iassign) * 100;
  2243. $text = number_format($percent, 1) . '%';
  2244. $sum_correct += $sum;
  2245. if ($sum > 0) {
  2246. for ($i = 1; $i < $percent * 2; $i ++)
  2247. $bar .= iassign_icons::insert('hbar_blue');
  2248. $bar .= iassign_icons::insert('hbar_blue_r');
  2249. } // if ($sum > 0)
  2250. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2251. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2252. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2253. print '</tr>' . "\n";
  2254. } // foreach ($sum_correct_student as $student)
  2255. print "</table>\n";
  2256. print "<br><br>\n";
  2257. $var = 0;
  2258. $cv = 0;
  2259. $dv = 0;
  2260. $avg = 0;
  2261. if ($sum_correct_student) {
  2262. $avg = $sum_correct / $sum_student;
  2263. if ($avg > 0) {
  2264. foreach ($sum_correct_student as $student)
  2265. $var += pow($student->sum - $avg, 2);
  2266. $var = $var / $sum_student;
  2267. $dv = sqrt($var);
  2268. $cv = ($dv / $avg) * 100;
  2269. }
  2270. }
  2271. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2272. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2273. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2274. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2275. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2276. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2277. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2278. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2279. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2280. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2281. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2282. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2283. print "</table>\n";
  2284. print $OUTPUT->footer();
  2285. } else {
  2286. print "<STYLE TYPE='text/css'>
  2287. <!--
  2288. .boldtable {
  2289. font-family:sans-serif;
  2290. font-size:10pt;
  2291. }
  2292. -->
  2293. </STYLE>\n";
  2294. print '<table border=1 width=100%>' . "\n";
  2295. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2296. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2297. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2298. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2299. print '</tr>' . "\n";
  2300. $sum_correct = 0;
  2301. foreach ($sum_correct_iassign as $iassign) {
  2302. $bar = "";
  2303. $sum = $iassign->sum;
  2304. $percent = ($sum / $sum_student) * 100;
  2305. $text = number_format($percent, 1) . '%';
  2306. $sum_correct += $sum;
  2307. if ($sum > 0) {
  2308. for ($i = 1; $i < $percent * 2; $i ++)
  2309. $bar .= iassign_icons::insert('hbar_blue');
  2310. $bar .= iassign_icons::insert('hbar_blue_r');
  2311. } // if ($sum > 0)
  2312. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2313. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2314. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2315. print '</tr>' . "\n";
  2316. } // foreach ($sum_correct_iassign as $iassign)
  2317. print "</table>";
  2318. print "<br><br>";
  2319. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2320. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2321. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2322. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2323. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2324. print '</tr>' . "\n";
  2325. $sum_correct = 0;
  2326. foreach ($sum_correct_student as $student) {
  2327. $bar = "";
  2328. $sum = $student->sum;
  2329. $percent = ($sum / $sum_iassign) * 100;
  2330. $text = number_format($percent, 1) . '%';
  2331. $sum_correct += $sum;
  2332. if ($sum > 0) {
  2333. for ($i = 1; $i < $percent * 2; $i ++)
  2334. $bar .= iassign_icons::insert('hbar_blue');
  2335. $bar .= iassign_icons::insert('hbar_blue_r');
  2336. } // if ($sum > 0)
  2337. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2338. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2339. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2340. print '</tr>' . "\n";
  2341. } // foreach ($sum_correct_student as $student)
  2342. print "</table>\n";
  2343. print "<br/><br/>\n";
  2344. $var = 0;
  2345. $cv = 0;
  2346. $dv = 0;
  2347. $avg = 0;
  2348. if ($sum_correct_student) {
  2349. $avg = $sum_correct / $sum_student;
  2350. if ($avg > 0) {
  2351. foreach ($sum_correct_student as $student)
  2352. $var += pow($student->sum - $avg, 2);
  2353. $var = $var / $sum_student;
  2354. $dv = sqrt($var);
  2355. $cv = ($dv / $avg) * 100;
  2356. }
  2357. }
  2358. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2359. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2360. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2361. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2362. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2363. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2364. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2365. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2366. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2367. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2368. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2369. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2370. print "</table>\n";
  2371. } // if ($this->action != 'printstats')
  2372. die();
  2373. }
  2374. /// Display graphics of performance for students
  2375. function stats_students () {
  2376. global $USER, $CFG, $DB, $OUTPUT;
  2377. $id = $this->cm->id;
  2378. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2379. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2380. $title = get_string('results', 'iassign');
  2381. $sum_correct = 0;
  2382. $sum_incorrect = 0;
  2383. $sum_post = 0;
  2384. $sum_nopost = 0;
  2385. $sum_iassign = count($iassign_statement_list);
  2386. $bar_nopost = "";
  2387. $bar_correct = "";
  2388. $bar_incorrect = "";
  2389. $bar_post = "";
  2390. $text_nopost = "";
  2391. $text_correct = "";
  2392. $text_incorrect = "";
  2393. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2394. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2395. if ($iassign_submission) {
  2396. if ($iassign_submission->status == 3)
  2397. $sum_correct ++;
  2398. elseif ($iassign_submission->status == 2)
  2399. $sum_incorrect ++;
  2400. elseif ($iassign_submission->status == 1)
  2401. $sum_post ++;
  2402. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2403. $sum_nopost ++;
  2404. } // if ($iassign_submission)
  2405. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2406. if ($sum_iassign > 0) {
  2407. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2408. $text_correct = number_format($percent_correct, 1) . '%';
  2409. }
  2410. if ($sum_correct > 0) {
  2411. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2412. $bar_correct .= iassign_icons::insert('hbar_green');
  2413. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2414. } // if ($sum_correct > 0)
  2415. if ($sum_iassign > 0) {
  2416. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2417. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2418. }
  2419. if ($sum_incorrect > 0) {
  2420. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2421. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2422. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2423. } // if ($sum_incorrect > 0)
  2424. if ($sum_iassign > 0) {
  2425. $percent_post = ($sum_post / $sum_iassign) * 100;
  2426. $text_post = number_format($percent_post, 1) . '%';
  2427. }
  2428. if ($sum_post > 0) {
  2429. for ($i = 1; $i < $percent_post * 2; $i ++)
  2430. $bar_post .= iassign_icons::insert('hbar_blue');
  2431. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2432. } // if ($sum_post > 0)
  2433. if ($sum_iassign > 0) {
  2434. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2435. $text_nopost = number_format($percent_nopost, 1) . '%';
  2436. }
  2437. if ($sum_nopost > 0) {
  2438. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2439. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2440. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2441. } // if ($sum_nopost > 0)
  2442. print $OUTPUT->header();
  2443. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2444. print '<table width=100%><tr>';
  2445. print '<td align="right">' . $link_return . '</td>' . "\n";
  2446. print '</td></tr></table>' . "\n";
  2447. print "<br/><br/>\n";
  2448. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2449. print '<tr><th colspan=3 class="header c1">' . "\n";
  2450. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2451. // $imagetext = '');
  2452. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2453. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2454. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2455. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2456. print '</tr>' . "\n";
  2457. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2458. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2459. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2460. print '</tr>' . "\n";
  2461. if ($sum_post) {
  2462. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2463. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2464. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2465. print '</tr>' . "\n";
  2466. } // if ($sum_post)
  2467. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2468. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2469. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2470. print '</tr>' . "\n";
  2471. print "</table>";
  2472. print "<br><br>";
  2473. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2474. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2475. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2476. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2477. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2478. $sum_grade = 0;
  2479. $sum_grade_student = 0;
  2480. $avg = 0;
  2481. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2482. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2483. if (!$iassign_submission) {
  2484. $iassign_submission = new stdClass();
  2485. $iassign_submission->grade = 0;
  2486. }
  2487. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2488. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2489. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2490. print '</tr>' . "\n";
  2491. $sum_grade += $iassign_statement_activity_item->grade;
  2492. $sum_grade_student += $iassign_submission->grade;
  2493. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2494. if ($sum_grade > 0)
  2495. $avg = $sum_grade_student / $sum_grade * 100;
  2496. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2497. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2498. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2499. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2500. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2501. print "</table>";
  2502. print $OUTPUT->footer();
  2503. die();
  2504. } // function stats_students()
  2505. /// Display page of iAssign's activity
  2506. function view_iassigns () {
  2507. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2508. $id = $this->cm->id;
  2509. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2510. $notice = optional_param('notice', '', PARAM_TEXT);
  2511. if (strpos($notice, 'error'))
  2512. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2513. else if ($notice != '')
  2514. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2515. print $OUTPUT->box_start();
  2516. print '<table width=100% border=0><tr>' . "\n";
  2517. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2518. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2519. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2520. $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>";
  2521. $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>";
  2522. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2523. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2524. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2525. // Has capability to see "report": teacher or up
  2526. print '<td width=10% align="left">' . "\n";
  2527. print $link_help;
  2528. print '</td>' . "\n";
  2529. print '<td width=10% align="left">' . "\n";
  2530. print $link_report;
  2531. print '</td>' . "\n";
  2532. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2533. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2534. print '<td width=15% align="left">' . "\n";
  2535. print $link_add;
  2536. print "</td>\n";
  2537. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2538. //print '</tr></table>' . "\n";
  2539. print '<div style="float: right;">';
  2540. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2541. if ($iassign_list) {
  2542. print '<td align="right">' . "\n";
  2543. // $USER->iassignEdit == 0 view 'Turn editing off'
  2544. // $USER->iassignEdit == 1 view 'Turn editing on'
  2545. if (!isset($USER->iassignEdit))
  2546. $USER->iassignEdit = 0;
  2547. if ($USER->iassignEdit == 0) {
  2548. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2549. $botton = 1;
  2550. } // if ($USER->iassignEdit == 0)
  2551. elseif ($USER->iassignEdit == 1) {
  2552. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2553. $botton = 0;
  2554. } // elseif ($USER->iassignEdit == 1)
  2555. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2556. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2557. print " <input type=submit value='$bottonEdit_message'/>\n";
  2558. print "</form>\n";
  2559. print "</td>\n";
  2560. } // if ($iassign_list)
  2561. }
  2562. print '</tr></table>' . "\n";
  2563. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2564. // $this->view_legend_icons();
  2565. print $OUTPUT->box_end();
  2566. $iassign_array_exercise = array();
  2567. $i_exercise = 0;
  2568. $iassign_array_test = array();
  2569. $i_test = 0;
  2570. $iassign_array_example = array();
  2571. $i_example = 0;
  2572. $iassign_array_general = array();
  2573. $i_general = 0;
  2574. if ($iassign_list) {
  2575. if ($this->iassign->activity_group == 0) {
  2576. foreach ($iassign_list as $iassign) {
  2577. $iassign_array_general[$i_general] = $iassign;
  2578. $i_general ++;
  2579. }
  2580. } // if ($this->iassign->activity_group == 0)
  2581. else {
  2582. foreach ($iassign_list as $iassign) {
  2583. if ($iassign->type_iassign == 3) {
  2584. $iassign_array_exercise[$i_exercise] = $iassign;
  2585. $i_exercise ++;
  2586. } // if ($iassign->type_iassign == 3)
  2587. if ($iassign->type_iassign == 2) {
  2588. $iassign_array_test[$i_test] = $iassign;
  2589. $i_test ++;
  2590. } // if ($iassign->type_iassign == 2)
  2591. if ($iassign->type_iassign == 1) {
  2592. $iassign_array_example[$i_example] = $iassign;
  2593. $i_example ++;
  2594. } // if ($iassign->type_iassign == 1)
  2595. }
  2596. }
  2597. if ($iassign_array_exercise) {
  2598. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  2599. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2600. }
  2601. if ($iassign_array_test) {
  2602. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  2603. $this->show_iassign($title, $iassign_array_test, $i_test);
  2604. }
  2605. if ($iassign_array_example) {
  2606. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  2607. $this->show_iassign($title, $iassign_array_example, $i_example);
  2608. }
  2609. if ($iassign_array_general) {
  2610. $title = "";
  2611. $this->show_iassign($title, $iassign_array_general, $i_general);
  2612. }
  2613. } else { // if ($iassign_list)
  2614. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2615. }
  2616. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2617. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2618. print $OUTPUT->box_start();
  2619. print '<table width=100% border=0><tr>' . "\n";
  2620. print '<td width=10% align="left">' . "\n";
  2621. print $link_report;
  2622. print '</td>' . "\n";
  2623. print '</tr></table>' . "\n";
  2624. print $OUTPUT->box_end();
  2625. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2626. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2627. print $OUTPUT->box_start();
  2628. print '<table width=100% border=0><tr>' . "\n";
  2629. print '<td align="left">' . "\n";
  2630. print $link_add;
  2631. print '</td>' . "\n";
  2632. print '</tr></table>' . "\n";
  2633. print $OUTPUT->box_end();
  2634. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2635. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2636. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2637. $this->view_legend_icons();
  2638. } // function view_iassigns()
  2639. /// Display all iAssigns
  2640. function show_iassign ($title, $iassign_array, $i) {
  2641. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  2642. $id = $this->cm->id;
  2643. print $OUTPUT->box_start();
  2644. print " <script type='text/javascript'>
  2645. //<![CDATA[
  2646. function validate_move () {
  2647. var radios = document.getElementsByName('iassign_destiny');
  2648. var formValid = false;
  2649. //alert('aqui validate_move()');
  2650. var i = 0;
  2651. while (!formValid && i < radios.length) {
  2652. if (radios[i].checked) formValid = true;
  2653. i++;
  2654. }
  2655. if (!formValid) {
  2656. document.getElementById('move_dest').classList.add('alert-danger');
  2657. }
  2658. return formValid;
  2659. }
  2660. var modal;
  2661. function load_move(id_ias) {
  2662. document.form_move_activity.iassign_current.value = id_ias;
  2663. modal.style.display = 'block';
  2664. var radios = document.getElementsByName('iassign_destiny');
  2665. var i = 0;
  2666. while (i < radios.length) {
  2667. radios[i].checked = false;
  2668. i++;
  2669. }
  2670. document.getElementById('move_dest').classList.remove('alert-danger');
  2671. }
  2672. function load_modal_elements() {
  2673. modal = document.getElementById('myModal');
  2674. var span = document.getElementById('close_modal');
  2675. span.onclick = function() {
  2676. modal.style.display = 'none';
  2677. }
  2678. window.onclick = function(event) {
  2679. if (event.target == modal) {
  2680. modal.style.display = 'none';
  2681. }
  2682. }
  2683. }
  2684. window.onload = load_modal_elements;
  2685. //]]>
  2686. </script>\n";
  2687. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  2688. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  2689. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  2690. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  2691. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  2692. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  2693. <input type='hidden' name='iassign_current' value='' />";
  2694. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  2695. $section = $course_sections[0];
  2696. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  2697. for ($k = 0; $k < count($ids_sections); $k++) {
  2698. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  2699. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  2700. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  2701. if ($c_cm) {
  2702. if ($ccm->instance == $c_cm->instance) {
  2703. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2704. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2705. }
  2706. else {
  2707. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2708. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2709. }
  2710. }
  2711. }
  2712. $radio_buttons .= "</ul>";
  2713. }
  2714. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  2715. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  2716. </form>
  2717. </div></div> </div></div>\n";
  2718. print " <style>.modal {
  2719. display: none;
  2720. position: fixed;
  2721. z-index: 1;
  2722. left: 0;
  2723. top: 0;
  2724. width: 100%;
  2725. height: 100%;
  2726. overflow: scroll;
  2727. background-color: rgb(0,0,0);
  2728. background-color: rgba(0,0,0,0.4);
  2729. }
  2730. .modal-content {
  2731. background-color: #fefefe;
  2732. margin: 15% auto;
  2733. padding: 10px 10px;
  2734. border: 1px solid #888;
  2735. width: 50%;
  2736. }
  2737. #close_modal {
  2738. color: #aaa;
  2739. float: right;
  2740. font-size: 28px;
  2741. font-weight: bold;
  2742. margin-top: -15px;
  2743. margin-right: -3px;
  2744. }
  2745. #close_modal:hover,
  2746. #close_modal:focus {
  2747. color: black;
  2748. text-decoration: none;
  2749. cursor: pointer;
  2750. }
  2751. #modal_title {
  2752. min-height: 3rem;
  2753. color: initial;
  2754. background: initial;
  2755. font-size: 1.5rem;
  2756. line-height: 1.5;
  2757. padding: 15px;
  2758. border-bottom: 1px solid #e5e5e5;
  2759. }
  2760. .input_move {
  2761. width: 90%;
  2762. padding: 2px;
  2763. }
  2764. .input_move:hover {
  2765. background: #eff0ef;
  2766. }
  2767. </style>";
  2768. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2769. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  2770. for ($j = 0; $j < $i; $j ++) {
  2771. $iassign_current = $iassign_array[$j]->id;
  2772. // receiver=1 - message to teacher
  2773. // receiver=2 - message to student
  2774. $sum_comment = 0;
  2775. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  2776. foreach ($iassign_submissions as $iassign_submission) {
  2777. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  2778. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2779. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2780. if ($verify_message)
  2781. foreach ($verify_message as $tmp)
  2782. $sum_comment += $tmp;
  2783. } // foreach ($iassign_submissions as $iassign_submission)
  2784. if ($sum_comment == 0)
  2785. $comment_unread = "";
  2786. else {
  2787. $comment_unread_message = get_string('comment_unread', 'iassign');
  2788. if ($sum_comment == 1)
  2789. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2790. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  2791. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  2792. }
  2793. if ($j == $i - 1)
  2794. $iassign_down = $iassign_array[$j]->id;
  2795. else
  2796. $iassign_down = $iassign_array[$j + 1]->id;
  2797. if ($j > 0)
  2798. $iassign_up = $iassign_array[$j - 1]->id;
  2799. else
  2800. $iassign_up = $iassign_array[$j]->id;
  2801. if ($iassign_array[$j]->visible == 0)
  2802. $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>";
  2803. else
  2804. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2805. $links .= $comment_unread;
  2806. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  2807. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  2808. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  2809. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  2810. if ($j==0) // first activity
  2811. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2812. else
  2813. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2814. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  2815. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  2816. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  2817. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  2818. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  2819. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  2820. if (count($iassign_array) > 1) {
  2821. if ($j == 0)
  2822. $links .= $link_down;
  2823. elseif ($j == $i - 1)
  2824. $links .= $link_up;
  2825. else
  2826. $links .= $link_up . $link_down;
  2827. } // if (count($iassign_array) > 1)
  2828. $links .= $link_edit . $link_delete;
  2829. if ($iassign_array[$j]->visible == 0)
  2830. $links .= $link_visible_show;
  2831. else
  2832. $links .= $link_visible_hide;
  2833. $links .= $link_duplicate_activity . $link_move_activity;
  2834. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2835. print '<p>' . $links . '</p>' . "\n";
  2836. }
  2837. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2838. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  2839. print '<table width=100% ><tr>' . "\n";
  2840. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2841. print '</tr></table>' . "\n";
  2842. for ($j = 0; $j < $i; $j ++) {
  2843. $icon_status = "";
  2844. $icon_comment = "";
  2845. if ($iassign_array[$j]->visible == 1) {
  2846. $iassign_current = $iassign_array[$j]->id;
  2847. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  2848. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2849. $icon_status = "";
  2850. $icon_comment = "";
  2851. if ($iassign_submission) {
  2852. // receiver=1 - message to teacher
  2853. // receiver=2 - message to student
  2854. // $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");
  2855. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  2856. $verify_message = $DB->get_record_sql(
  2857. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2858. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2859. if ($verify_message)
  2860. foreach ($verify_message as $tmp)
  2861. $sum_comment = $tmp;
  2862. if ($sum_comment > 0) {
  2863. $comment_unread_message = get_string('comment_unread', 'iassign');
  2864. if ($sum_comment == 1)
  2865. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2866. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  2867. }
  2868. // $icon_comment = iassign_icons::insert('comment_unread');
  2869. if ($iassign_array[$j]->type_iassign == 3) {
  2870. if ($iassign_array[$j]->show_answer == 1) {
  2871. if ($iassign_submission->status == 3)
  2872. $icon_status = iassign_icons::insert('correct');
  2873. elseif ($iassign_submission->status == 2)
  2874. $icon_status = iassign_icons::insert('incorrect');
  2875. elseif ($iassign_submission->status == 1)
  2876. $icon_status = iassign_icons::insert('post');
  2877. elseif ($iassign_submission->status == 0)
  2878. $icon_status = iassign_icons::insert('not_post');
  2879. } // if ($iassign_array[$j]->show_answer==1)
  2880. else {
  2881. if ($iassign_submission->status == 0)
  2882. $icon_status = iassign_icons::insert('not_post');
  2883. else
  2884. $icon_status = iassign_icons::insert('post');
  2885. }
  2886. } // if ($iassign_array[$j]->type_iassign == 3)
  2887. } // if ($iassign_submission)
  2888. elseif ($iassign_array[$j]->type_iassign == 3) {
  2889. $icon_status = iassign_icons::insert('not_post');
  2890. } // if ($iassign_array[$j]->type_iassign == 3)
  2891. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  2892. } // if ($iassign_array[$j]->visible == 1)
  2893. } // for ($j = 0; $j < $i; $j++)
  2894. } else if (isguestuser()) {
  2895. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2896. print '<table width=100% ><tr>' . "\n";
  2897. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2898. print '</tr></table>' . "\n";
  2899. for ($j = 0; $j < $i; $j ++) {
  2900. $icon_status = "";
  2901. $icon_comment = "";
  2902. if ($iassign_array[$j]->visible == 1) {
  2903. $iassign_current = $iassign_array[$j]->id;
  2904. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2905. print '<p>' . $links . '</p>' . "\n";
  2906. } // if ($iassign_array[$j]->visible == 1)
  2907. }
  2908. }
  2909. print $OUTPUT->box_end();
  2910. } // function show_iassign($title, $iassign_array, $i)
  2911. /// Show message of return
  2912. function return_home_course ($message) {
  2913. //D global $DB, $OUTPUT;
  2914. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2915. //D echo $OUTPUT->box_start();
  2916. //D echo '<table width=100% border=0 valign="top">' . "\n";
  2917. //D echo '<tr><td align="left"><strong>' . "\n";
  2918. //D print_string($message, 'iassign');
  2919. //D echo '</strong></td>' . "\n";
  2920. //D echo '<td width=20% align="right">' . "\n";
  2921. //D echo $link_return;
  2922. //D echo '</td></tr></table>' . "\n";
  2923. //D echo $OUTPUT->box_end();
  2924. //D // echo $OUTPUT->footer();
  2925. redirect(new moodle_url($this->return . '&notice=' . $message));
  2926. exit;
  2927. }
  2928. /// Search comment of activity
  2929. function search_comment_submission ($iassign_submissionid) {
  2930. global $USER, $DB, $OUTPUT, $COURSE;
  2931. // $context = context_course::instance($COURSE->id);
  2932. $colorEdit1 = "#a7bede"; // "#dce7ec"
  2933. $colorEdit2 = "#b7ceee";
  2934. $has_capability = 0;
  2935. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  2936. $text = "";
  2937. if ($comments) {
  2938. $even = 1;
  2939. foreach ($comments as $tmp) {
  2940. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  2941. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  2942. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2943. // $text .= $tmp->comment . "</td></tr>";
  2944. //} else {
  2945. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2946. if ($even) {
  2947. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2948. $even = 0;
  2949. } else {
  2950. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2951. $even = 1;
  2952. }
  2953. $text .= $tmp->comment . "</td></tr>\n";
  2954. } // foreach ($comments as $tmp)
  2955. }
  2956. return $text;
  2957. }
  2958. /// Update comment of activity
  2959. function update_comment ($iassign_submissionid) {
  2960. global $USER, $DB, $OUTPUT;
  2961. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  2962. $receiver = 1; // student message to teacher
  2963. else
  2964. $receiver = 2; // teacher message to student
  2965. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  2966. if ($verify_message) {
  2967. foreach ($verify_message as $message) {
  2968. if ($message->receiver == $receiver) {
  2969. $newentry = new stdClass();
  2970. $newentry->id = $message->id;
  2971. $newentry->return_status = 1;
  2972. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  2973. print_error('error_update', 'iassign');
  2974. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  2975. } // if ($message->receiver == $receiver)
  2976. // Trigger module viewed event.
  2977. $event = \mod_iassign\event\submission_comment_updated::create(array(
  2978. 'objectid' => $this->iassign->id,
  2979. 'context' => $this->context
  2980. ));
  2981. $event->add_record_snapshot('course', $this->course);
  2982. $event->trigger();
  2983. } // foreach ($verify_message as $message)
  2984. }
  2985. }
  2986. /// Record comment of activity
  2987. function write_comment_submission () {
  2988. global $USER, $CFG, $DB;
  2989. $id = $this->cm->id;
  2990. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  2991. $row = optional_param('row', 0, PARAM_INT);
  2992. $column = optional_param('column', 0, PARAM_INT);
  2993. $sum_comment = 0;
  2994. $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);
  2995. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  2996. $str1 = trim($submission_comment);
  2997. $str2 = trim(get_string('box_comment_message', 'iassign'));
  2998. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  2999. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3000. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3001. $receiver = 1; // student message to teacher
  3002. $this->action = 'view';
  3003. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3004. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3005. } else {
  3006. $receiver = 2; // teacher message to student
  3007. $this->action = 'viewsubmission';
  3008. //D $tousers = array(); //MOOC 2016
  3009. //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
  3010. }
  3011. //MOOC 2016: foi p/ 15 linhas acima:
  3012. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3013. if (!$iassign_submission) {
  3014. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3015. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3016. $this->iassign_submission_current = $id_submission;
  3017. } else {
  3018. $id_submission = $iassign_submission->id;
  3019. } // if (!$iassign_submission)
  3020. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3021. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3022. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3023. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3024. $comments = $DB->get_record_sql(
  3025. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3026. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3027. if ($comments)
  3028. foreach ($comments as $tmp)
  3029. $sum_comment = $tmp;
  3030. if ($sum_comment == 0) {
  3031. $newentry = new stdClass();
  3032. $newentry->iassign_submissionid = $id_submission;
  3033. $newentry->comment_authorid = $USER->id;
  3034. $newentry->timecreated = time();
  3035. $newentry->comment = $submission_comment;
  3036. $newentry->receiver = $receiver;
  3037. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3038. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3039. //T $eventdata = new stdClass();
  3040. //T $eventdata->component = 'mod_iassign'; //your component name
  3041. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3042. //T $eventdata->userfrom = $USER;
  3043. //T $eventdata->userto = $touser;
  3044. //T $eventdata->subject = "Teste de Subject";
  3045. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3046. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3047. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3048. //T $eventdata->smallmessage = "Teste de Mensagem";
  3049. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3050. //T // alteracao tulio faria
  3051. //T //message_send($eventdata);
  3052. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3053. // Trigger module viewed event.
  3054. $event = \mod_iassign\event\submission_comment_created::create(array(
  3055. 'objectid' => $this->iassign->id,
  3056. 'context' => $this->context
  3057. ));
  3058. $event->add_record_snapshot('course', $this->course);
  3059. $event->trigger();
  3060. }
  3061. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3062. // if ($this->action=='viewsubmission') {
  3063. // echo $OUTPUT->header();
  3064. // $this->return_last('confirm_add_comment', $link_return);
  3065. // die;
  3066. // }
  3067. return true;
  3068. } // function write_comment_submission()
  3069. /// Writes a new submission
  3070. // The first student answer is under 'function get_answer()'
  3071. function new_submission ($iassignid, $id_user, $receiver) {
  3072. global $USER, $DB, $OUTPUT;
  3073. $newentry = new stdClass();
  3074. $newentry->iassign_statementid = $iassignid;
  3075. $newentry->userid = $id_user;
  3076. $newentry->timecreated = time();
  3077. $newentry->timemodified = time();
  3078. $newentry->answer = 0; // student only submit message
  3079. if ($receiver == 2) // teacher message to student (write id teacher)
  3080. $newentry->teacher = $USER->id;
  3081. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3082. return_home_course('error_insert_submissions');
  3083. else {
  3084. // Trigger module view event
  3085. $event = \mod_iassign\event\submission_created::create(array(
  3086. 'objectid' => $this->iassign->id,
  3087. 'context' => $this->context
  3088. ));
  3089. $event->add_record_snapshot('course', $this->course);
  3090. $event->trigger();
  3091. }
  3092. return $newentry->id;
  3093. }
  3094. /// Return to a specific address of page
  3095. function return_last ($message, $link_return) {
  3096. global $DB, $OUTPUT;
  3097. print $OUTPUT->box_start();
  3098. print '<table width=100% border=0 valign="top">' . "\n";
  3099. print '<tr><td align="left"><strong>' . "\n";
  3100. print_string($message, 'iassign');
  3101. print '</strong></td>' . "\n";
  3102. print '<td width=20% align="right">' . "\n";
  3103. print $link_return;
  3104. print '</td></tr></table>' . "\n";
  3105. print $OUTPUT->box_end();
  3106. print $OUTPUT->footer();
  3107. die();
  3108. } // function return_last($message, $link_return)
  3109. } // class iassign
  3110. /// Class for manage activities
  3111. class activity {
  3112. var $activity;
  3113. /// Constructor of class.
  3114. // @param int $id Id of activity
  3115. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3116. //D public function activity($id) { self::__construct($id); }
  3117. function __construct ($id) {
  3118. global $DB;
  3119. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3120. if (empty($this->activity))
  3121. $this->activity = null;
  3122. }
  3123. /// Get an activity
  3124. // @return NULL
  3125. function get_activity () {
  3126. if ($this->activity != null)
  3127. return $this->activity;
  3128. else
  3129. return null;
  3130. }
  3131. /// Delete interactive activities
  3132. function delete ($return) {
  3133. global $USER, $CFG, $DB, $OUTPUT;
  3134. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3135. $output = $OUTPUT->header();
  3136. $output .= $OUTPUT->box_start();
  3137. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3138. if ($iassign_submission_currents) {
  3139. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3140. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3141. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3142. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3143. $output .= $OUTPUT->box_end();
  3144. $output .= $OUTPUT->footer();
  3145. print $output;
  3146. die();
  3147. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3148. } // if ($iassign_submission_currents)
  3149. else
  3150. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3151. $output .= '<table width=50% border=0>';
  3152. $output .= '<tr valign="top"><td>';
  3153. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3154. $output .= '</td><td>';
  3155. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3156. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3157. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3158. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3159. $output .= "</form>\n";
  3160. $output .= '</td><td>';
  3161. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3162. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3163. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3164. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3165. $output .= "</form>\n";
  3166. $output .= '</td></tr></table>' . "\n";
  3167. $output .= $OUTPUT->box_end();
  3168. $output .= $OUTPUT->footer();
  3169. print $output;
  3170. } // function delete($return)
  3171. /// Function for confirm the delete of activity
  3172. // @param String $return Url of return
  3173. // @param Object $iassign Object content an activity
  3174. function deleteyes ($return, $iassign) {
  3175. global $USER, $CFG, $DB, $OUTPUT;
  3176. $msg = '';
  3177. if (!empty($this->activity->id)) {
  3178. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3179. if ($iassign_submission_currents) {
  3180. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3181. foreach ($iassign_submission_currents as $iassign_submission)
  3182. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3183. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3184. } // if ($iassign_submission_currents)
  3185. }
  3186. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3187. $this->delete_calendar($this->activity->id);
  3188. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3189. iassign::update_grade_iassign($this->activity->iassignid);
  3190. if ($delete_iassign_current) {
  3191. $iassign->return_home_course('confirm_delete_iassign');
  3192. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3193. } else {
  3194. $iassign->return_home_course('error_confirm_delete_iassign');
  3195. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3196. }
  3197. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3198. }
  3199. }
  3200. /// Changes position of activities (between those inside a group of interactive activities)
  3201. // @param $move_action = must be "up" or "down"
  3202. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3203. function move_iassign ($move_action, $target, $return) {
  3204. global $DB, $OUTPUT;
  3205. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3206. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3207. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3208. if ($move_action=="firstdown") {
  3209. $final_position_source = 2;
  3210. $final_position_target = 1;
  3211. }
  3212. else
  3213. if ($move_action=="down") {
  3214. $final_position_target = $this->activity->position;
  3215. $final_position_source = $final_position_target + 1;
  3216. }
  3217. else
  3218. if ($move_action=="up") {
  3219. $final_position_target = $this->activity->position;
  3220. $final_position_source = $final_position_target - 1;
  3221. }
  3222. else { // error:
  3223. print_error('error_update_move_iassign', 'iassign');
  3224. exit;
  3225. }
  3226. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3227. $newentry->id = $this->activity->id; // ID of the "source activity"
  3228. $newentry->position = $final_position_source;
  3229. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3230. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3231. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3232. print_error('error_update_move_iassign', 'iassign');
  3233. }
  3234. else { // first update performed successfully
  3235. $newentry->id = $iassign_target->id;
  3236. $newentry->position = $final_position_target;
  3237. if (!$DB->update_record('iassign_statement', $newentry))
  3238. print_error('error_update_move_iassign', 'iassign');
  3239. }
  3240. redirect($return);
  3241. }
  3242. /// Enable or disable the display of interactive activities
  3243. function visible_iassign ($return) {
  3244. global $DB;
  3245. $newentry = new stdClass();
  3246. $newentry->id = $this->activity->id;
  3247. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3248. if (!$DB->update_record('iassign_statement', $newentry))
  3249. print_error('error_update_visible_iassign', 'iassign');
  3250. redirect($return);
  3251. }
  3252. /// Add news interactive activities (register in table 'iassign_statement')
  3253. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3254. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3255. function new_iassign ($param) {
  3256. global $DB;
  3257. $newentry = new stdClass();
  3258. $newentry->iassignid = $param->iassignid;
  3259. $newentry->name = $param->name;
  3260. $newentry->type_iassign = $param->type_iassign;
  3261. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3262. $proposition = $param->proposition;
  3263. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3264. else $proposition_text = $proposition;
  3265. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3266. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3267. //TODO Then get it directly from the form data $_POST!
  3268. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3269. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3270. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3271. $newentry->author_name = $param->author_name;
  3272. $newentry->author_modified_name = $param->author_modified_name;
  3273. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3274. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3275. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3276. $newentry->grade = $param->grade;
  3277. $newentry->timemodified = time();
  3278. $newentry->timecreated = time();
  3279. if ($param->type_iassign == 1) {
  3280. $newentry->timedue = 0;
  3281. $newentry->timeavailable = 0;
  3282. } // if ($param->type_iassign == 1)
  3283. else {
  3284. $newentry->timedue = $param->timedue;
  3285. $newentry->timeavailable = $param->timeavailable;
  3286. }
  3287. $newentry->preventlate = $param->preventlate;
  3288. $newentry->test = $param->test;
  3289. $newentry->special_param1 = $param->special_param1;
  3290. $newentry->visible = $param->visible;
  3291. $newentry->position = $param->position;
  3292. $newentry->max_experiment = $param->max_experiment;
  3293. $newentry->dependency = $param->dependency;
  3294. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3295. $newentry->show_answer = $param->show_answer;
  3296. $id = $DB->insert_record("iassign_statement", $newentry);
  3297. if ($id) {
  3298. $component = 'mod_iassign';
  3299. $filearea = 'exercise';
  3300. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3301. $file = $fs->get_file_by_id($param->file);
  3302. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3303. // File already inserted in other context!
  3304. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3305. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3306. $updateentry = new stdClass();
  3307. $updateentry->id = $id;
  3308. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3309. $updateentry->file = $newfile->get_itemid();
  3310. if (!$DB->update_record("iassign_statement", $updateentry))
  3311. print_error('error_add', 'iassign');
  3312. if ($param->type_iassign == 3)
  3313. iassign::update_grade_iassign($param->iassignid);
  3314. //TODO iLM_HTML5 :: //MOOC2014
  3315. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3316. //D if ($iassign_ilm_configs) {
  3317. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3318. //D if ($iassign_ilm_config->param_type != 'static') {
  3319. //D $newentry = new stdClass();
  3320. //D $newentry->iassign_statementid = $id;
  3321. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3322. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3323. //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});
  3324. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3325. //D print_error('error_add_param', 'iassign');
  3326. //D }
  3327. //D }
  3328. //D }
  3329. // log event --------------------------------------------------------------------------------------
  3330. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3331. // log event --------------------------------------------------------------------------------------
  3332. return $id;
  3333. }
  3334. else
  3335. print_error('error_add', 'iassign');
  3336. } // function new_iassign($param)
  3337. /// Add the calendar entries for this iassign
  3338. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3339. // @return bool
  3340. static function add_calendar ($iassignid) {
  3341. global $DB, $CFG;
  3342. require_once($CFG->dirroot . '/calendar/lib.php');
  3343. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3344. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3345. $event = new stdClass();
  3346. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3347. $event->description = $iassign_statement_activity_item->name;
  3348. $event->courseid = $iassign->course;
  3349. $event->groupid = 0;
  3350. $event->userid = 0;
  3351. $event->modulename = 'iassign';
  3352. $event->instance = $iassign->id;
  3353. $event->eventtype = 'due';
  3354. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3355. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3356. calendar_event::create($event);
  3357. }
  3358. /// Update the calendar entries for this iassign
  3359. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3360. // @return bool
  3361. function update_calendar ($iassignid, $olddescription) {
  3362. global $DB, $CFG;
  3363. require_once($CFG->dirroot . '/calendar/lib.php');
  3364. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3365. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3366. $event = new stdClass();
  3367. $event->id = 0;
  3368. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3369. if ($events) {
  3370. foreach ($events as $value) {
  3371. if ($value->description == $olddescription) {
  3372. $event->id = $value->id;
  3373. }
  3374. }
  3375. }
  3376. if ($event->id != 0) {
  3377. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3378. $event->description = $iassign_statement_activity_item->name;
  3379. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3380. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3381. $calendarevent = calendar_event::load($event->id);
  3382. $calendarevent->update($event);
  3383. } else
  3384. $this->add_calendar($iassignid);
  3385. }
  3386. /// Update the calendar entries for this iassign
  3387. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3388. // @return bool
  3389. function delete_calendar ($iassignid) {
  3390. global $DB, $CFG;
  3391. require_once($CFG->dirroot . '/calendar/lib.php');
  3392. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3393. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3394. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3395. if ($events) {
  3396. foreach ($events as $value) {
  3397. if ($value->description == $iassign_statement_activity_item->name) {
  3398. $DB->delete_records('event', array('id' => $value->id));
  3399. }
  3400. }
  3401. }
  3402. }
  3403. /// Update interactive activities
  3404. function update_iassign ($param) {
  3405. global $DB;
  3406. $component = 'mod_iassign';
  3407. $filearea = 'exercise';
  3408. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3409. $file = $fs->get_file_by_id($param->file);
  3410. $fileold = $fs->get_file_by_id($param->fileold);
  3411. if ($param->file != $param->fileold) {
  3412. if ($fileold) {
  3413. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3414. foreach ($fileoldarea as $value) {
  3415. $value->delete();
  3416. }
  3417. }
  3418. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3419. $itemid = $file->get_itemid() + $param->iassign_id;
  3420. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3421. $param->file = $newfile->get_itemid();
  3422. } else
  3423. $param->file = $file->get_itemid();
  3424. } else {
  3425. $param->file = $file->get_itemid();
  3426. }
  3427. $newentry = new stdClass();
  3428. $newentry->id = $param->iassign_id;
  3429. $newentry->name = $param->name;
  3430. $newentry->type_iassign = $param->type_iassign;
  3431. //2019 $newentry->proposition = $param->proposition;
  3432. $proposition = $param->proposition;
  3433. if (is_array($proposition))
  3434. $proposition_text = $proposition['text'];
  3435. else
  3436. $proposition_text = $proposition;
  3437. $newentry->proposition = $proposition_text;
  3438. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3439. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3440. $newentry->grade = $param->grade;
  3441. $newentry->author_modified_name = $param->author_modified_name;
  3442. $newentry->timemodified = time();
  3443. if ($param->type_iassign == 1) {
  3444. $newentry->timedue = 0;
  3445. $newentry->timeavailable = 0;
  3446. } // if ($param->type_iassign == 1)
  3447. else {
  3448. $newentry->timedue = $param->timedue;
  3449. $newentry->timeavailable = $param->timeavailable;
  3450. }
  3451. $newentry->preventlate = $param->preventlate;
  3452. $newentry->test = $param->test;
  3453. $newentry->special_param1 = $param->special_param1;
  3454. $newentry->visible = $param->visible;
  3455. $newentry->max_experiment = $param->max_experiment;
  3456. $newentry->dependency = $param->dependency;
  3457. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3458. $newentry->show_answer = $param->show_answer;
  3459. if (!$DB->update_record("iassign_statement", $newentry))
  3460. print_error('error_update', 'iassign');
  3461. if ($param->type_iassign == 3) {
  3462. iassign::update_grade_iassign($param->iassignid);
  3463. }
  3464. //$id = $newentry->id; // MOOC 2016 --- inicio
  3465. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3466. //if ($iassign_activity_item_configs) {
  3467. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3468. // $newentry = new stdClass();
  3469. // $newentry->id = $iassign_activity_item_config->id;
  3470. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3471. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3472. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3473. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3474. // print_error('error_edit_param', 'iassign');
  3475. // }
  3476. // } // MOOC 2016 --- final
  3477. // log event --------------------------------------------------------------------------------------
  3478. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3479. // log event --------------------------------------------------------------------------------------
  3480. return $newentry->id;
  3481. // if ($param->type_iassign==3)
  3482. // $this->update_grade_iassign($param->iassignid);
  3483. } // function update_iassign($param)
  3484. /// Show information of activity
  3485. function show_info_iassign () {
  3486. global $DB, $OUTPUT;
  3487. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3488. if ($this->activity->type_iassign == 3) {
  3489. if ($this->activity->dependency == 0) {
  3490. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3491. } else {
  3492. $dependencys = explode(';', $this->activity->dependency);
  3493. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3494. foreach ($dependencys as $dependency) {
  3495. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3496. if ($dependencyiassign)
  3497. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3498. } // foreach ($dependencys as $dependency)
  3499. } // if ($iassign_statement_activity_item->dependency == 0)
  3500. if ($this->activity->max_experiment == 0)
  3501. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3502. else
  3503. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3504. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3505. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3506. print $OUTPUT->box($output);
  3507. } // function show_info_iassign()
  3508. /// Shows date of opening and closing activities
  3509. function view_dates () {
  3510. global $USER, $CFG, $DB, $OUTPUT;
  3511. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3512. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3513. $status_iassign = "";
  3514. $status_iassign1 = "";
  3515. $status_iassign2 = "";
  3516. if ($this->activity->type_iassign == 1) // activity of type example
  3517. $type_iassign = get_string('example_iassign', 'iassign');
  3518. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3519. $type_iassign = get_string('test_iassign', 'iassign');
  3520. if ($this->activity->timeavailable > time()) {
  3521. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3522. } elseif ($this->activity->timedue < time()) {
  3523. $status_iassign = get_string('last_timedue', 'iassign');
  3524. }
  3525. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3526. $type_iassign = get_string('exercise_iassign', 'iassign');
  3527. if ($this->activity->timeavailable > time()) {
  3528. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3529. } elseif ($this->activity->timedue < time()) { // after delivery
  3530. $status_iassign = get_string('last_timedue', 'iassign');
  3531. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3532. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3533. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3534. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3535. if ($this->activity->test == 1) // allowed to test after of deadline
  3536. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3537. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3538. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3539. } // elseif ($iassign_statement_activity_item->test == 0)
  3540. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3541. } // elseif ($iassign_statement_activity_item->timedue < time())
  3542. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3543. $output = '<table width=100% >' . "\n";
  3544. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3545. $output .= '<tr>' . "\n";
  3546. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3547. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3548. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3549. // leo $output .= '<td width=80%>' . $type_iassign;
  3550. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3551. // $output .= '</td>' . "\n";
  3552. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3553. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3554. $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>";
  3555. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3556. } else {
  3557. $link_next = "";
  3558. $link_previous = "";
  3559. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3560. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3561. // previous_activity
  3562. if ($iassign_previous) {
  3563. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3564. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3565. } // next_activity
  3566. if ($iassign_next) {
  3567. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3568. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3569. }
  3570. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3571. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3572. $output .= '</tr></table>' . "\n";
  3573. $output .= '<table width=100% >' . "\n";
  3574. if ($this->activity->type_iassign > 1) {
  3575. if ($this->activity->timeavailable)
  3576. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3577. if ($this->activity->timedue)
  3578. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3579. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3580. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3581. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3582. $output .= '</table>' . "\n";
  3583. print $OUTPUT->box($output);
  3584. } // function view_dates()
  3585. } // class activity
  3586. /// Class to manage Interactive Learning Module (iLM)
  3587. class ilm {
  3588. var $ilm;
  3589. /// Constructor of class
  3590. // @param int $id Id of iLM
  3591. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3592. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3593. function __construct ($id) {
  3594. global $DB;
  3595. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3596. if (empty($this->ilm))
  3597. $this->ilm = null;
  3598. }
  3599. /// Shows activity in iLM
  3600. // @calledby view_iassign_current()
  3601. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3602. global $USER, $CFG, $DB;
  3603. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3604. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3605. $typec = strtolower($iassign_ilm->type);
  3606. require_once 'ilm_handlers/' . $typec . '.php';
  3607. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3608. return $retorno;
  3609. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3610. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3611. // @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);
  3612. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3613. // @param Object $file File in use in activity
  3614. // @return int Return the id of log
  3615. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3616. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3617. $newentry = new stdClass();
  3618. $newentry->iassign_statementid = $iassign_activity_itemid;
  3619. $newentry->userid = $USER->id;
  3620. $newentry->file = $content_or_id_from_ilm_security;
  3621. $newentry->timecreated = time();
  3622. $newentry->view = 1;
  3623. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3624. if (!$id_iLM_security) {
  3625. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3626. } // from (!$DB->insert_record("iassign_security", $newentry))
  3627. return $id_iLM_security;
  3628. }
  3629. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3630. // @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);
  3631. // @param int $userid
  3632. // @param int $iassign_activity_itemid Id of iassign statement
  3633. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3634. global $DB;
  3635. // 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")
  3636. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3637. }
  3638. } // class ilm
  3639. /// Class to manage settings of iLM.
  3640. class ilm_settings {
  3641. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  3642. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3643. // @param int $ilm_id Id of iLM
  3644. // @param array $options An array with options for create dynamic tag html APPLET
  3645. // @return string Return with a tag html APPLET created
  3646. static function build_ilm_tags ($ilm_id, $options = array()) {
  3647. global $DB;
  3648. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3649. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3650. $typec = strtolower($iassign_ilm->type);
  3651. require_once 'ilm_handlers/' . $typec . '.php';
  3652. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3653. return $retorno;
  3654. } // static function build_ilm_tags($ilm_id, $options = array())
  3655. /// Function for get modified date of iLM file
  3656. // @param string $file_jar String with Ids of iLM files
  3657. // @return string Return with the filenames and modified date
  3658. static function applet_filetime ($file_jar) {
  3659. $filetime = "";
  3660. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3661. $files_jar = explode(",", $file_jar);
  3662. foreach ($files_jar as $one_file) {
  3663. $file = $fs->get_file_by_id($one_file);
  3664. if ($file)
  3665. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3666. }
  3667. return $filetime;
  3668. }
  3669. /// Function for verify an default applet
  3670. // @param String $file_jar String containing an list de ids of applet files
  3671. // @return boolean Return true or fale if applet is default
  3672. static function applet_default ($file_jar) {
  3673. $is_default = true;
  3674. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3675. $files_jar = explode(",", $file_jar);
  3676. foreach ($files_jar as $one_file) {
  3677. $file = $fs->get_file_by_id($one_file);
  3678. if ($file)
  3679. $is_default &= ($file->get_itemid() == 0);
  3680. }
  3681. return $is_default;
  3682. }
  3683. /// Function for get form variables for add, edit, or copy iLM
  3684. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  3685. // @see settings_form.php
  3686. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  3687. // @param int $ilm_id Id of iLM
  3688. // @param string $action String with the action
  3689. // @return object Return an object with forms variables
  3690. static function add_edit_copy_ilm ($ilm_id, $action) {
  3691. global $USER, $DB, $CFG;
  3692. require_once('settings_form.php'); // put the form
  3693. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3694. $param = new stdClass();
  3695. $param->action = $action;
  3696. $param->ilm_id = $ilm_id;
  3697. $CFG->action_ilm = $action;
  3698. $CFG->ilm_id = $ilm_id;
  3699. if ($action == 'add') {
  3700. $param->title = get_string('add_ilm', 'iassign');
  3701. $param->name = "";
  3702. $param->version = "";
  3703. $param->url = "";
  3704. $param->description = "";
  3705. $param->extension = "";
  3706. $param->author = $USER->id;
  3707. $param->file_jar = "";
  3708. $param->file_jar_static = "";
  3709. $param->file_class = "";
  3710. $param->width = 800;
  3711. $param->height = 600;
  3712. $param->enable = 0; // 0 - hide / 1 - show
  3713. $param->timecreated = time();
  3714. $param->timemodified = time();
  3715. $param->evaluate = 0;
  3716. $param->parent = 0;
  3717. }
  3718. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  3719. if ($iassign_ilm) {
  3720. $description = json_decode($iassign_ilm->description);
  3721. $param->title = get_string('edit_ilm', 'iassign');
  3722. $param->id = $iassign_ilm->id;
  3723. $param->name_ilm = $iassign_ilm->name;
  3724. $param->name = $iassign_ilm->name;
  3725. $param->version = $iassign_ilm->version;
  3726. $param->ilm_type = $iassign_ilm->type;
  3727. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3728. $param->url = $iassign_ilm->url;
  3729. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  3730. if (!isset($description->{current_language()})) {
  3731. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  3732. else
  3733. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  3734. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  3735. }
  3736. else
  3737. $param->description = $description->{current_language()};
  3738. $param->description_lang = $iassign_ilm->description;
  3739. $param->extension = $iassign_ilm->extension;
  3740. $param->author = $iassign_ilm->author;
  3741. $param->file_jar = $iassign_ilm->file_jar;
  3742. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  3743. $param->file_class = $iassign_ilm->file_class;
  3744. $param->width = $iassign_ilm->width;
  3745. $param->height = $iassign_ilm->height;
  3746. $param->enable = $iassign_ilm->enable;
  3747. $param->timecreated = $iassign_ilm->timecreated;
  3748. $param->timemodified = time();
  3749. $param->evaluate = $iassign_ilm->evaluate;
  3750. $param->parent = $iassign_ilm->parent;
  3751. }
  3752. }
  3753. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  3754. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  3755. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3756. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  3757. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  3758. // echo "Sem dados<br/>"; exit;
  3759. return;
  3760. }
  3761. $description = json_decode($iassign_ilm->description);
  3762. if ($iassign_ilm) {
  3763. if ($iassign_ilm->parent == 0)
  3764. $iassign_ilm->parent = $ilm_id;
  3765. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  3766. $param->title = get_string('new_version_ilm', 'iassign');
  3767. $param->name_ilm = $iassign_ilm->name;
  3768. $param->name = $iassign_ilm->name;
  3769. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  3770. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  3771. $param->version = $iassign_ilm->version; // do not erase field 'version'
  3772. $param->ilm_type = $iassign_ilm->type;
  3773. $param->url = $iassign_ilm->url;
  3774. $param->description = $description->{current_language()};
  3775. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  3776. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3777. $param->extension = $iassign_ilm->extension;
  3778. $param->author = $USER->id;
  3779. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  3780. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  3781. $param->file_jar_static = '';
  3782. $param->file_class = $iassign_ilm->file_class;
  3783. $param->width = $iassign_ilm->width;
  3784. $param->height = $iassign_ilm->height;
  3785. $param->enable = 0;
  3786. $param->timecreated = time();
  3787. $param->timemodified = time();
  3788. $param->evaluate = $iassign_ilm->evaluate;
  3789. $param->parent = $iassign_ilm->parent;
  3790. }
  3791. }
  3792. elseif ($action == 'copy') {
  3793. $description = json_decode($iassign_ilm->description);
  3794. if ($iassign_ilm) {
  3795. if ($iassign_ilm->parent == 0)
  3796. $iassign_ilm->parent = $ilm_id;
  3797. $param->title = get_string('copy_ilm', 'iassign');
  3798. $param->id = $iassign_ilm->id;
  3799. $param->name_ilm = $iassign_ilm->name;
  3800. $param->name = $iassign_ilm->name;
  3801. $param->version = "";
  3802. $param->ilm_type = $iassign_ilm->type;
  3803. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3804. $param->url = $iassign_ilm->url;
  3805. $param->description = $description->{current_language()};
  3806. $param->description_lang = $iassign_ilm->description;
  3807. $param->extension = $iassign_ilm->extension;
  3808. $param->author = $USER->id;
  3809. $param->file_jar = '';
  3810. $param->file_jar_static = '';
  3811. $param->file_class = $iassign_ilm->file_class;
  3812. $param->width = $iassign_ilm->width;
  3813. $param->height = $iassign_ilm->height;
  3814. $param->enable = 0;
  3815. $param->timecreated = time();
  3816. $param->timemodified = time();
  3817. $param->evaluate = $iassign_ilm->evaluate;
  3818. $param->parent = $iassign_ilm->parent;
  3819. }
  3820. }
  3821. return $param;
  3822. } // static function add_edit_copy_ilm($ilm_id, $action)
  3823. /// Function for save iLM file in moodledata
  3824. // @param int $itemid Itemid of file save in draft (upload file)
  3825. // @param int $ilm_id Id of iLM
  3826. // @return string Return an string with ids of iLM files
  3827. static function new_file_ilm ($itemid, $iassign_ilm) {
  3828. global $CFG, $USER, $DB;
  3829. $return = null;
  3830. $file_jar = array();
  3831. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3832. $contextuser = context_user::instance($USER->id);
  3833. $contextsystem = context_system::instance();
  3834. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  3835. if ($files_ilm) {
  3836. foreach ($files_ilm as $value) {
  3837. // CHECK IF file is HTML type
  3838. if ($iassign_ilm->type == 1) {
  3839. // Check if the file extension is ZIP
  3840. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  3841. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  3842. if ((strtolower($ext) == 'zip')) {
  3843. // Coping...:
  3844. $destination = 'ilm_debug/' . $value->get_filename();
  3845. $value->copy_content_to($destination);
  3846. // Extracting content...:
  3847. $zip = new ZipArchive();
  3848. $extracted = './ilm';
  3849. $dir = "";
  3850. if ($zip->open($destination) === TRUE) {
  3851. $dir = './ilm/' . trim($zip->getNameIndex(0));
  3852. if (is_dir($dir)) {
  3853. $i = 1;
  3854. $previous = str_replace("/", "", $zip->getNameIndex(0));
  3855. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  3856. $i ++;
  3857. }
  3858. $name = $previous . "_" . $i;
  3859. $dir = './ilm/' . $name . "/";
  3860. $j = 0;
  3861. while ($item_name = $zip->getNameIndex($j)) {
  3862. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  3863. $j++;
  3864. }
  3865. $zip->close();
  3866. }
  3867. $zip->open($destination);
  3868. $zip->extractTo($extracted);
  3869. $zip->close();
  3870. // After the extraction, remove it from DEBUG
  3871. unlink($destination);
  3872. } else { // Error trying to open destination...
  3873. // After the extraction error, also remove it from DEBUG
  3874. unlink($destination);
  3875. print_error('error_add_ilm_zip', 'iassign');
  3876. }
  3877. return $dir;
  3878. }
  3879. } // if ($iassign_ilm->type == 1)
  3880. if ($value->get_filename() != '.') {
  3881. $file_ilm = array(
  3882. 'userid' => $USER->id,
  3883. 'contextid' => $contextsystem->id,
  3884. 'component' => 'mod_iassign',
  3885. 'filearea' => 'ilm',
  3886. 'itemid' => rand(1, 999999999),
  3887. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  3888. 'filename' => $value->get_filename());
  3889. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  3890. array_push($file_jar, $file_ilm->get_id());
  3891. }
  3892. }
  3893. if (!empty($file_jar)) {
  3894. $return = implode(",", $file_jar);
  3895. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  3896. foreach ($old_file_jar as $value) {
  3897. $file = $fs->get_file_by_id($value);
  3898. if ($file)
  3899. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  3900. }
  3901. }
  3902. }
  3903. else // if ($files_ilm)
  3904. $return = $iassign_ilm->file_jar;
  3905. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  3906. return $return;
  3907. } // static function new_file_ilm($itemid, $iassign_ilm)
  3908. /// Function for save in database an new iLM
  3909. // @param object $param An object with iLM params
  3910. static function new_ilm ($itemid) {
  3911. global $CFG, $USER, $OUTPUT;
  3912. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3913. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3914. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3915. }
  3916. $pathtemp = $CFG->dataroot . '/temp/';
  3917. $contextuser = context_user::instance($USER->id);
  3918. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3919. $zip = new zip_packer();
  3920. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3921. foreach ($files as $file) {
  3922. if (!$file->is_directory())
  3923. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3924. }
  3925. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3926. // Verifica se o pacote possui o XML
  3927. if (!$application_xml) {
  3928. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3929. return;
  3930. } else {
  3931. $missing = "";
  3932. if (!isset($application_xml->name)) {
  3933. $missing .= "name";
  3934. }
  3935. if (!isset($application_xml->version)) {
  3936. $missing .= ", version";
  3937. }
  3938. if (!isset($application_xml->type)) {
  3939. $missing .= ", type";
  3940. }
  3941. if (!isset($application_xml->extension)) {
  3942. $missing .= ", extension";
  3943. }
  3944. if (!isset($application_xml->file_jar)) {
  3945. $missing .= ", file_jar";
  3946. }
  3947. if (!isset($application_xml->file_class)) {
  3948. $missing .= ", file_class";
  3949. }
  3950. if (!isset($application_xml->width)) {
  3951. $missing .= ", width";
  3952. }
  3953. if (!isset($application_xml->height)) {
  3954. $missing .= ", height";
  3955. }
  3956. if (!isset($application_xml->evaluate)) {
  3957. $missing .= ", evaluate";
  3958. }
  3959. if (strlen($missing) > 2) {
  3960. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3961. return;
  3962. }
  3963. }
  3964. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3965. $typec = strtolower($application_xml->type);
  3966. require_once 'ilm_handlers/' . $typec . '.php';
  3967. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3968. return $retorno;
  3969. } // static function new_ilm($itemid)
  3970. /// Function for save in database an iLM edit
  3971. // @param object $param An object with iLM params
  3972. static function edit_ilm ($param, $itemid) {
  3973. // Descobrir o tipo de iLM:
  3974. global $DB, $USER, $CFG;
  3975. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  3976. $pathtemp = $CFG->dataroot . '/temp/';
  3977. $contextuser = context_user::instance($USER->id);
  3978. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3979. $zip = new zip_packer();
  3980. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3981. $files_extract = null;
  3982. foreach ($files as $file) {
  3983. if (!$file->is_directory())
  3984. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3985. }
  3986. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  3987. $typec = strtolower($iassign_t->type);
  3988. require_once 'ilm_handlers/' . $typec . '.php';
  3989. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  3990. }
  3991. /// Function for register the new iLM (in database and in the directory)
  3992. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  3993. // @param object $param An object with iLM params
  3994. static function copy_new_version_ilm ($param) {
  3995. global $DB, $CFG, $USER;
  3996. $itemid = $param->file;
  3997. $pathtemp = $CFG->dataroot . '/temp/';
  3998. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3999. //D echo "pathtemp=$pathtemp<br/>";
  4000. $contextuser = context_user::instance($USER->id);
  4001. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4002. $zip = new zip_packer();
  4003. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4004. $files_extract = null;
  4005. foreach ($files as $file) {
  4006. if (!$file->is_directory())
  4007. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4008. }
  4009. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4010. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4011. $typec = strtolower($iassign_t->type);
  4012. require_once 'ilm_handlers/' . $typec . '.php';
  4013. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4014. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4015. } // static function copy_new_version_ilm($param)
  4016. //VER::
  4017. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4018. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4019. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4020. /// Function for change visibility of iLM
  4021. // @param int $ilm_id Id of iLM
  4022. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4023. static function visible_ilm ($ilm_id, $status) {
  4024. global $DB;
  4025. if ($status == 0)
  4026. $visible = 1;
  4027. else
  4028. $visible = 0;
  4029. $newentry = new stdClass();
  4030. $newentry->id = $ilm_id;
  4031. $newentry->enable = $visible;
  4032. if (!$DB->update_record("iassign_ilm", $newentry))
  4033. error(get_string('error_edit_ilm', 'iassign'));
  4034. }
  4035. /// Function for confirm change default iLM
  4036. // @param int $ilm_id Id of iLM
  4037. // @param int $ilm_parent Id of parent iLM
  4038. // @return string Return with an string for create default page confirmation
  4039. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4040. global $OUTPUT, $DB;
  4041. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4042. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4043. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4044. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4045. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4046. return $return;
  4047. }
  4048. /// Function for change the default iLM
  4049. // @see settings_ilm.php
  4050. // @param int $ilm_id Id of iLM
  4051. // @return int Return Id of default iLM
  4052. static function default_ilm ($ilm_id) {
  4053. global $DB;
  4054. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4055. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4056. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4057. $iassign_ilm_default->id = $iassign_ilm->id;
  4058. $iassign_ilm_default->parent = 0;
  4059. $iassign_ilm->parent = $iassign_ilm_default->id;
  4060. $iassign_ilm->id = 0;
  4061. $iassign_ilm_default->enable = 1;
  4062. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4063. print_error('error_edit_ilm', 'iassign');
  4064. }
  4065. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4066. if (!$inserted) {
  4067. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4068. print_error($msg_error);
  4069. //xx print_error('error_add_ilm', 'iassign');
  4070. }
  4071. return $iassign_ilm_default->id;
  4072. } // static function default_ilm ($ilm_id)
  4073. /// Function for confirm delete iLM
  4074. // @param int $ilm_id Id of iLM
  4075. // @param int $ilm_parent Id of parent iLM
  4076. // @return string Return with an string for create delete page confirmation
  4077. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4078. global $OUTPUT, $DB;
  4079. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4080. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4081. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4082. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4083. }
  4084. /// Function for delete directory where the iLM is allocated.
  4085. // @param string $dirPath
  4086. // @throws InvalidArgumentException
  4087. public static function delete_dir ($dirPath) {
  4088. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4089. $dirPath .= '/';
  4090. }
  4091. $files = glob($dirPath . '*', GLOB_MARK);
  4092. foreach ($files as $file) {
  4093. if (is_dir($file)) {
  4094. ilm_settings::delete_dir($file);
  4095. } else {
  4096. unlink($file);
  4097. }
  4098. }
  4099. rmdir($dirPath);
  4100. }
  4101. /// Function for delete iLM
  4102. // @param int $ilm_id Id of iLM
  4103. // @return int Return Id of parent iLM
  4104. static function delete_ilm ($ilm_id) {
  4105. global $DB;
  4106. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4107. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4108. $typec = strtolower($iassign_ilm->type);
  4109. require_once 'ilm_handlers/' . $typec . '.php';
  4110. $retorno = $typec::delete_ilm($ilm_id);
  4111. return $retorno;
  4112. }
  4113. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4114. // @param int $ilm_id Id of iLM
  4115. static function export_ilm ($ilm_id) {
  4116. global $DB;
  4117. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4118. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4119. $typec = strtolower($iassign_ilm->type);
  4120. require_once 'ilm_handlers/' . $typec . '.php';
  4121. $typec::export_ilm($ilm_id);
  4122. } // static function export_ilm($ilm_id)
  4123. //TODO iLM_HTML5 :: //MOOC 2016
  4124. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4125. // @param int $ilm_id Id of iLM
  4126. static function export_update_ilm ($ilm_id) {
  4127. global $DB, $CFG;
  4128. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4129. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4130. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4131. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4132. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4133. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4134. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4135. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4136. $upgrade_descriptor .= '</upgrade>' . "\n";
  4137. file_put_contents($xml_filename, $upgrade_descriptor);
  4138. header("Pragma: public");
  4139. header("Expires: 0");
  4140. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4141. header("Cache-Control: private", false);
  4142. header('Content-Type: application/xml; charset=utf-8');
  4143. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4144. header("Content-Length: " . @filesize($xml_filename));
  4145. set_time_limit(0);
  4146. @readfile("$xml_filename") || die("File not found.");
  4147. unlink($xml_filename);
  4148. exit;
  4149. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4150. /// Function for save iLM from XML descriptor
  4151. // @param array $application_xml Data of XML descriptor
  4152. // @param array $files_extract Filenames of extract files
  4153. // @return array Return an array content id of JAR files
  4154. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4155. global $CFG, $USER;
  4156. // Tratamento diferenciado se for do tipo HTML5:
  4157. $source = "";
  4158. $diretorio = "";
  4159. if (strtolower($application_xml->type) == 'html5') {
  4160. $i = 0;
  4161. foreach ($files_extract as $key => $value) {
  4162. $file = $CFG->dataroot . '/temp/' . $key;
  4163. // Verifica se já existe a pasta no diretório dos iLM:
  4164. if ($i == 0) {
  4165. $source = $file;
  4166. if (file_exists("ilm/" . basename($file))) {
  4167. $j = 1;
  4168. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4169. $j ++;
  4170. }
  4171. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4172. // mkdir($diretorio, 0777, true);
  4173. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4174. }
  4175. else {
  4176. $diretorio = 'ilm/' . basename($file);
  4177. // mkdir($diretorio, 0777, true);
  4178. mkdir($diretorio, 0755, true);
  4179. }
  4180. break;
  4181. }
  4182. $i ++;
  4183. }
  4184. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4185. if ($item->isDir()) {
  4186. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4187. }
  4188. else {
  4189. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4190. }
  4191. }
  4192. ilm_settings::delete_dir($source);
  4193. return "./" . $diretorio;
  4194. }
  4195. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4196. $file_jar = array();
  4197. $files_ilm = explode(",", $application_xml->file_jar);
  4198. $contextsystem = context_system::instance();
  4199. foreach ($files_ilm as $value) {
  4200. $file_ilm = array(
  4201. 'userid' => $USER->id,
  4202. 'contextid' => $contextsystem->id,
  4203. 'component' => 'mod_iassign',
  4204. 'filearea' => 'ilm',
  4205. 'itemid' => rand(1, 999999999),
  4206. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4207. 'filename' => $value);
  4208. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4209. array_push($file_jar, $file_ilm->get_id());
  4210. }
  4211. foreach ($files_extract as $key => $value) {
  4212. $file = $CFG->dataroot . '/temp/' . $key;
  4213. if (file_exists($file))
  4214. unlink($file);
  4215. }
  4216. return $file_jar;
  4217. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4218. /// Function for import the iLM from an package
  4219. // @param int $itemid Itemid of zip file
  4220. static function import_ilm ($itemid) {
  4221. global $CFG, $USER, $OUTPUT;
  4222. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4223. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4224. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4225. }
  4226. $pathtemp = $CFG->dataroot . '/temp/';
  4227. $contextuser = context_user::instance($USER->id);
  4228. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4229. $zip = new zip_packer();
  4230. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4231. foreach ($files as $file) {
  4232. if (!$file->is_directory())
  4233. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4234. }
  4235. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4236. // Verifica se o pacote possui o XML
  4237. if (!$application_xml) {
  4238. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4239. return;
  4240. } else {
  4241. $missing = "";
  4242. if (!isset($application_xml->name)) {
  4243. $missing .= "name";
  4244. }
  4245. if (!isset($application_xml->version)) {
  4246. $missing .= ", version";
  4247. }
  4248. if (!isset($application_xml->type)) {
  4249. $missing .= ", type";
  4250. }
  4251. if (!isset($application_xml->extension)) {
  4252. $missing .= ", extension";
  4253. }
  4254. if (!isset($application_xml->file_jar)) {
  4255. $missing .= ", file_jar";
  4256. }
  4257. if (!isset($application_xml->file_class)) {
  4258. $missing .= ", file_class";
  4259. }
  4260. if (!isset($application_xml->width)) {
  4261. $missing .= ", width";
  4262. }
  4263. if (!isset($application_xml->height)) {
  4264. $missing .= ", height";
  4265. }
  4266. if (!isset($application_xml->evaluate)) {
  4267. $missing .= ", evaluate";
  4268. }
  4269. if (strlen($missing) > 2) {
  4270. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4271. return;
  4272. }
  4273. }
  4274. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4275. $typec = strtolower($application_xml->type);
  4276. require_once 'ilm_handlers/' . $typec . '.php';
  4277. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4278. } // static function import_ilm($itemid)
  4279. /// Function for list iLM defaults
  4280. // @return string Return an string with a table of iLM
  4281. static function list_ilm () {
  4282. global $DB, $OUTPUT;
  4283. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4284. $str = '';
  4285. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4286. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4287. if ($iassign_ilm) {
  4288. foreach ($iassign_ilm as $ilm) {
  4289. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4290. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4291. $str .= '<tr><td>';
  4292. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4293. $str .= '<tr>';
  4294. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4295. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4296. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4297. $str .= '</tr>';
  4298. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4299. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4300. $str .= '</table>';
  4301. $str .= '</td></tr>';
  4302. }
  4303. }
  4304. $str .= '</table>';
  4305. return $str;
  4306. }
  4307. /// Function for download and install an upgrade of an iLM
  4308. // @param int $ilm_id Id of iLM
  4309. static function upgrade_ilm ($ilm_id) {
  4310. global $DB, $CFG, $USER;
  4311. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4312. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4313. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4314. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4315. if (!$result)
  4316. print_error('error_upgrade_ilm', 'iassign');
  4317. else {
  4318. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4319. $extension = explode(".", $zip_filename);
  4320. if ($extension[count($extension) - 1] != 'ipz') {
  4321. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4322. die;
  4323. }
  4324. $zip = new zip_packer();
  4325. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4326. $contextuser = context_user::instance($USER->id);
  4327. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4328. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4329. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4330. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4331. if (file_exists($zip_filename))
  4332. unlink($zip_filename);
  4333. if (empty($file_jar)) {
  4334. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4335. print_error($msg_error);
  4336. //xx print_error('error_add_ilm', 'iassign');
  4337. }
  4338. else {
  4339. $newentry = new stdClass();
  4340. $newentry->name = (String) $application_xml->name;
  4341. $newentry->version = (String) $application_xml->version;
  4342. $newentry->url = (String) $application_xml->url;
  4343. $newentry->description = $description_str;
  4344. $newentry->extension = strtolower((String) $application_xml->extension);
  4345. $newentry->file_jar = implode(",", $file_jar);
  4346. $newentry->file_class = (String) $application_xml->file_class;
  4347. $newentry->width = (String) $application_xml->width;
  4348. $newentry->height = (String) $application_xml->height;
  4349. $newentry->enable = 0;
  4350. $newentry->timemodified = time();
  4351. $newentry->author = $USER->id;
  4352. $newentry->timecreated = time();
  4353. $newentry->evaluate = (String) $application_xml->evaluate;
  4354. $newentry->parent = $ilm_id;
  4355. }
  4356. }
  4357. return $iassign_ilm->id;
  4358. } // static function upgrade_ilm($ilm_id)
  4359. //MOOC2014 -- inicio
  4360. //TODO: REVIEW
  4361. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4362. // static function move_iassign($ilm_id)
  4363. //MOOC2014 -- final
  4364. /// Function for list iLM versions with all informations
  4365. // @return string Return an string with a table of iLM
  4366. static function view_ilm ($ilmid, $from) {
  4367. global $DB;
  4368. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4369. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4370. $typec = strtolower($iassign_ilm->type);
  4371. require_once 'ilm_handlers/' . $typec . '.php';
  4372. $retorno = $typec::view_ilm($ilmid, $from);
  4373. return $retorno;
  4374. }
  4375. /// Function for get form variables for add, edit, or copy iLM params
  4376. // @param int $ilm_param_id Id of iLM param
  4377. // @param string $action String with the action
  4378. // @return object Return an object with forms variables
  4379. static function add_edit_copy_param ($ilm_param_id, $action) {
  4380. global $DB;
  4381. require_once('params_form.php');
  4382. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4383. $param = new stdClass();
  4384. $param->action = $action;
  4385. $param->ilm_param_id = $ilm_param_id;
  4386. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4387. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4388. $type = $iassign_ilm_config->param_type;
  4389. if ($action == 'add') {
  4390. $param->title = get_string('add_ilm', 'iassign');
  4391. $param->iassign_ilmid = $ilm_param_id;
  4392. $param->param_name = "";
  4393. $param->param_value = "";
  4394. $param->description = "";
  4395. $param->visible = 1;
  4396. }
  4397. elseif ($action == 'edit') {
  4398. if ($iassign_ilm_config) {
  4399. $param->title = get_string('edit_ilm', 'iassign');
  4400. $param->id = $iassign_ilm_config->id;
  4401. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4402. $param->param_type = $type; //MOOC2014
  4403. $param->param_name = $iassign_ilm_config->param_name;
  4404. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4405. $param->param_value = $iassign_ilm_config->param_value;
  4406. else //MOOC2014
  4407. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4408. $param->param_value = $iassign_ilm_config->param_value;
  4409. $param->description = $iassign_ilm_config->description;
  4410. $param->visible = $iassign_ilm_config->visible;
  4411. }
  4412. }
  4413. elseif ($action == 'copy') {
  4414. if ($iassign_ilm_config) {
  4415. $param->title = get_string('copy_ilm', 'iassign');
  4416. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4417. $param->param_type = $type; //MOOC2014
  4418. $param->param_name = $iassign_ilm_config->param_name;
  4419. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4420. $param->param_value = $iassign_ilm_config->param_value;
  4421. else //MOOC2014
  4422. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4423. $param->description = $iassign_ilm_config->description;
  4424. $param->visible = $iassign_ilm_config->visible;
  4425. }
  4426. }
  4427. return $param;
  4428. } // static function add_edit_copy_param($ilm_param_id, $action)
  4429. /// Function for change visibility of iLM param
  4430. // @param int $ilm_param_id Id of iLM param
  4431. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4432. static function visible_param ($ilm_param_id, $status) {
  4433. global $DB, $CFG;
  4434. if ($status == 0)
  4435. $visible = 1;
  4436. else
  4437. $visible = 0;
  4438. $newentry = new stdClass();
  4439. $newentry->id = $ilm_param_id;
  4440. $newentry->visible = $visible;
  4441. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4442. error(get_string('error_edit_param', 'iassign'));
  4443. }
  4444. /// Function for save in database an new iLM param
  4445. // @param object $param An object with iLM params
  4446. static function add_param ($param) {
  4447. global $DB;
  4448. $newentry = new stdClass();
  4449. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4450. //MOOC2014 $newentry->param_name = $param->param_name;
  4451. $newentry->param_type = $param->param_type; //MOOC2014
  4452. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4453. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4454. $newentry->param_value = $param->param_value;
  4455. else //MOOC2014
  4456. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4457. $newentry->description = $param->description;
  4458. $newentry->visible = $param->visible;
  4459. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4460. if (!$newentry->id) {
  4461. print_error('error_add_param', 'iassign');
  4462. }
  4463. }
  4464. /// Function for save in database a iLM param edit
  4465. // @param object $param An object with iLM params
  4466. static function edit_param ($param) {
  4467. global $DB;
  4468. $updentry = new stdClass();
  4469. $updentry->id = $param->id;
  4470. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4471. $updentry->param_type = $param->param_type; //MOOC2014
  4472. // $updentry->param_name = $param->param_name;
  4473. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4474. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4475. $updentry->param_value = $param->param_value;
  4476. else //MOOC2014
  4477. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4478. $updentry->description = $param->description;
  4479. $updentry->visible = $param->visible;
  4480. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4481. error(get_string('error_edit_param', 'iassign'));
  4482. }
  4483. }
  4484. /// Function for save in database a iLM param copy
  4485. // @param object $param An object with iLM params
  4486. static function copy_param ($param) {
  4487. global $DB;
  4488. $newentry = new stdClass();
  4489. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4490. //$newentry->param_name = $param->param_name;
  4491. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4492. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4493. $newentry->param_value = $param->param_value;
  4494. else //MOOC2014
  4495. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4496. $newentry->description = $param->description;
  4497. $newentry->visible = $param->visible;
  4498. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4499. if (!$newentry->id) {
  4500. print_error('error_add_param', 'iassign');
  4501. }
  4502. }
  4503. /// Function for delete iLM param of database
  4504. // @param int $param_id Id of iLM param
  4505. static function delete_param ($param_id) {
  4506. global $DB;
  4507. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4508. print_error('error_delete_param', 'iassign');
  4509. }
  4510. }
  4511. } // class ilm_settings
  4512. /// Class for manage iLM files (editor).
  4513. class ilm_manager {
  4514. var $id; // course id
  4515. var $url;
  4516. var $from;
  4517. /// Constructor for the base ilm_manager class
  4518. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4519. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4520. function __construct ($id, $url, $from) {
  4521. $this->id = $id; // course id
  4522. $this->url = $url;
  4523. $this->from = $from;
  4524. }
  4525. /// Function to get iAssign content file in Moodle data (exercise)
  4526. // @calledby x function preview_ilm($iassign_ilm) :
  4527. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4528. function get_file_ilm () {
  4529. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4530. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4531. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4532. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4533. $md_file = $fs->get_file_by_id($fileid);
  4534. $ilm_content_file = $md_file->get_content();
  4535. return $ilm_content_file;
  4536. }
  4537. /// Function for creating a new file from the iLM online editor
  4538. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4539. function ilm_editor_new () {
  4540. global $CFG, $DB, $OUTPUT, $PAGE;
  4541. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4542. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4543. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4544. $context = context_course::instance($this->id);
  4545. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4546. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4547. if (!$iassign) {
  4548. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4549. die();
  4550. }
  4551. $temp = explode(",", $iassign->extension);
  4552. $extension = $temp[0]; // default extension for this iLM
  4553. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4554. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4555. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4556. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4557. if ($stringArchiveContent != NULL) {
  4558. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4559. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4560. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4561. $filename = optional_param('filename', NULL, PARAM_RAW);
  4562. //Leo $filename = iassign_utils::format_filename($filename); //
  4563. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4564. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4565. //2019/02 $arrayfilename = explode(".", $filename);
  4566. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4567. //2019/02 $count_dots = count($arrayfilename);
  4568. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4569. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4570. //2019/02 if ($last_name != $extension)
  4571. //2019/02 $filename = $filename . '.' . $extension;
  4572. //2019/02 }
  4573. //2019/02 else { // no extension...
  4574. //2019/02 $filename = $filename . '.' . $extension;
  4575. //2019/02 }
  4576. // Store the name of recent created file
  4577. $_SESSION['file_name'] = $filename;
  4578. //$this->write_file_iassign($string, $filename);
  4579. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4580. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4581. die();
  4582. }
  4583. else { // if ($stringArchiveContent != NULL)
  4584. // iLM On-line editor
  4585. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4586. $str_get_iLM = "window.frames.iLM";
  4587. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4588. }
  4589. else { // otherwise it is JAR named 'iLM'
  4590. $str_get_iLM = "document.iLM";
  4591. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4592. }
  4593. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4594. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4595. $files_array = '';
  4596. foreach ($files as $value) {
  4597. if ($value->get_filename() != ".")
  4598. $files_array .= "'" . $value->get_filename() . "',";
  4599. }
  4600. $files_array .= "''";
  4601. $file = null;
  4602. $ia_content = "";
  4603. $filename = "";
  4604. $error_files_exists = get_string('error_file_exists', 'iassign');
  4605. $output = "<script type='text/javascript'>
  4606. //<![CDATA[
  4607. //D alert('locallib.php: ilm_editor_new');
  4608. function submit_iLM_Answer () {
  4609. var docFormOnLineEditor = document.formEnvio;
  4610. var resposta_exerc = new Array(3);
  4611. var valor_resposta = new Array(3);
  4612. var sessao = new Array(3);
  4613. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4614. resposta_exerc[0] = doc_iLM.getAnswer();
  4615. valor_resposta[0] = doc_iLM.getEvaluation();
  4616. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4617. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4618. var files = new Array(" . $files_array . ");
  4619. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4620. if (docFormOnLineEditor.filename.value=='') {
  4621. // ERROR: the file name is empty
  4622. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4623. return false;
  4624. }
  4625. // }
  4626. for (i=0; i<files.length; i++) {
  4627. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4628. alert('" . $error_files_exists . "');
  4629. return false;
  4630. }
  4631. }
  4632. docFormOnLineEditor.submit();
  4633. return true;
  4634. }
  4635. //]]>
  4636. </script>\n";
  4637. $output .= "
  4638. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4639. $output .= $OUTPUT->box_start();
  4640. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4641. $output .= "
  4642. <table width='100%' cellpadding='20'>
  4643. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4644. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4645. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4646. </tr>
  4647. </table>\n";
  4648. $output .= $OUTPUT->box_end();
  4649. $output .= "<center>\n";
  4650. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4651. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4652. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4653. $output .= $output_ilm;
  4654. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4655. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4656. </center>
  4657. </form>\n";
  4658. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4659. $PAGE->navbar->add($title);
  4660. $PAGE->set_title($title);
  4661. $PAGE->set_heading($title); // insert title above the navigation bar
  4662. print $OUTPUT->header();
  4663. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4664. print $output;
  4665. print $OUTPUT->footer();
  4666. }
  4667. die();
  4668. } // function ilm_editor_new()
  4669. /// Function for editing an file in online editor
  4670. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  4671. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  4672. global $CFG, $DB, $OUTPUT, $PAGE;
  4673. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4674. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4675. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4676. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4677. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4678. // If iLM is not registered, error!
  4679. if (!$iassign) {
  4680. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  4681. die;
  4682. }
  4683. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  4684. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  4685. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  4686. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  4687. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4688. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4689. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  4690. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  4691. if ($stringArchiveContent != NULL) {
  4692. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  4693. die();
  4694. } else { // if ($stringArchiveContent != NULL)
  4695. $end_file = '';
  4696. if ($content_file) {
  4697. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  4698. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  4699. }
  4700. $temp = explode(",", $iassign->extension);
  4701. $extension = $temp[0]; // default extension for this iLM
  4702. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  4703. $str_get_iLM = "window.frames.iLM";
  4704. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4705. } else { // otherwise it is JAR named 'iLM'
  4706. $str_get_iLM = "document.iLM";
  4707. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4708. }
  4709. $output = "<script type='text/javascript'>
  4710. //<![CDATA[
  4711. function submit_iLM_Answer () {
  4712. var docFormEditor = document.formEnvio;
  4713. var activityAnswer; // to get activity answer (text)
  4714. var activityValue; // to get activity answer value (float)
  4715. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4716. //activityAnswer = doc_iLM.getAnswer();
  4717. //activityValue = doc_iLM.getEvaluation();
  4718. activityAnswer = " . $str_get_iLM . ".getAnswer();
  4719. activityValue = " . $str_get_iLM . ".getEvaluation();
  4720. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  4721. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  4722. docFormEditor.submit();
  4723. return true;
  4724. }
  4725. //]]>
  4726. </script>\n";
  4727. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4728. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  4729. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4730. // return true;
  4731. // }
  4732. $output .= "
  4733. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4734. $output .= $OUTPUT->box_start();
  4735. $output .= "
  4736. <table width='100%' cellpadding='20'>
  4737. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  4738. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  4739. <input type='hidden' name='filename' value='$filename'/></td>
  4740. <td>
  4741. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4742. </tr>
  4743. </table>\n";
  4744. $output .= $OUTPUT->box_end();
  4745. $output .= " <center>\n";
  4746. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  4747. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  4748. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  4749. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  4750. </center>
  4751. </form>\n";
  4752. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4753. $PAGE->navbar->add($title);
  4754. $PAGE->set_title($title);
  4755. $PAGE->set_heading($title); // insert title above the navigation bar
  4756. print $OUTPUT->header();
  4757. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4758. print $output;
  4759. print $OUTPUT->footer();
  4760. } // else if ($stringArchiveContent != NULL)
  4761. die();
  4762. } // function ilm_editor_update()
  4763. /// Function for write iAssign file in Moodle data (exercise)
  4764. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  4765. // @param string $stringArchiveContent Content of iassign file
  4766. // @param string $filename Filename of iassign file
  4767. function write_file_iassign ($stringArchiveContent, $filename) {
  4768. global $USER;
  4769. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4770. $context = context_course::instance($this->id);
  4771. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4772. $dirid = $this->get_dir_ilm('dirid');
  4773. $dir = $fs->get_file_by_id($dirid);
  4774. $fileinfo = array('contextid' => $context->id, // ID of course
  4775. 'component' => 'mod_iassign', // usually = table name
  4776. 'filearea' => 'activity', // usually = table name
  4777. 'itemid' => 0, // usually = ID of row in table
  4778. 'filepath' => '/', // any path beginning and ending whith '/'
  4779. 'userid' => $USER->id,
  4780. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4781. 'filename' => $filename); // any filename
  4782. // Create file containing text. '$stringArchiveContent'
  4783. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4784. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  4785. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  4786. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  4787. // 'Activité interactive enregistrée avec succès sous le nom:';
  4788. // 'Atividade interativa gravada com sucesso sob o nome:'
  4789. $output = "
  4790. <script type='text/javascript'>
  4791. //<![CDATA[
  4792. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  4793. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4794. //]]>
  4795. </script>";
  4796. print $output;
  4797. die();
  4798. }
  4799. /// Function for write iAssign file in Moodle data (exercise)
  4800. // @param string $stringArchiveContent Content of iassign file
  4801. // @param string $filename Filename of iassign file
  4802. // @param int $itemid Itemid of iassign file
  4803. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  4804. global $OUTPUT, $USER;
  4805. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4806. $context = context_course::instance($this->id);
  4807. $dirid = $this->get_dir_ilm('dirid');
  4808. if ($stringArchiveContent != (-1)) {
  4809. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4810. $file = $fs->get_file_by_id($fileid);
  4811. if (!$file) {
  4812. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  4813. die;
  4814. }
  4815. $fileinfo = array('contextid' => $context->id, // ID of context
  4816. 'component' => 'mod_iassign', // usually = table name
  4817. 'filearea' => 'activity', // usually = table name
  4818. 'itemid' => 0, // usually = ID of row in table
  4819. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  4820. 'userid' => $USER->id,
  4821. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4822. 'license' => 'allrightsreserved', // allrightsreserved
  4823. 'timecreated' => $file->get_timecreated(),
  4824. 'filename' => $file->get_filename()); // any filename
  4825. $file->delete();
  4826. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4827. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  4828. }
  4829. $output = "<script type='text/javascript'>
  4830. //<![CDATA[
  4831. alert('" . get_string('sucess_update', 'iassign') . "');\n
  4832. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4833. //]]>
  4834. </script>";
  4835. print $output;
  4836. die();
  4837. }
  4838. /// Function for create an tag for iAssign filter
  4839. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  4840. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4841. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  4842. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4843. // @param int $fileid Id of file
  4844. // @return string Return an string with an tag of iassign filter
  4845. function tag_ilm ($fileid) {
  4846. global $DB;
  4847. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4848. $width = '600';
  4849. $height = '400';
  4850. $file = $fs->get_file_by_id($fileid);
  4851. $filetype = explode(".", $file->get_filename());
  4852. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  4853. foreach ($iassign_ilm as $value) {
  4854. $extensions = explode(",", $value->extension);
  4855. if (in_array($filetype[1], $extensions)) {
  4856. $width = $value->width;
  4857. $height = $value->height;
  4858. }
  4859. }
  4860. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  4861. }
  4862. /// Function for delete iAssign file in Moodle data (exercise)
  4863. function delete_file_ilm () {
  4864. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4865. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4866. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  4867. $file = $fs->get_file_by_id($fileid);
  4868. if ($file)
  4869. $file->delete();
  4870. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4871. die();
  4872. }
  4873. /// Function for delete selected iAssign file in Moodle data (exercise)
  4874. function delete_selected_ilm () {
  4875. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4876. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4877. $context = context_course::instance($this->id);
  4878. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4879. $dirid = $this->get_dir_ilm('dirid');
  4880. foreach ($files_id as $file_id) {
  4881. $file = $fs->get_file_by_id($file_id);
  4882. if ($file) {
  4883. if (!$file->is_directory())
  4884. $file->delete();
  4885. else {
  4886. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4887. foreach ($files_delete as $value)
  4888. $value->delete();
  4889. $file->delete();
  4890. }
  4891. }
  4892. }
  4893. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4894. die();
  4895. }
  4896. /// Function for duplicate iAssign file from "online" edition
  4897. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  4898. function duplicate_file_ilm () {
  4899. global $USER, $COURSE;
  4900. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4901. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4902. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4903. $filename = optional_param('filename', NULL, PARAM_RAW);
  4904. $file = $fs->get_file_by_id($fileid);
  4905. $context = context_course::instance($this->id);
  4906. $fileinfo = array(
  4907. 'contextid' => $context->id, // ID of context
  4908. 'component' => 'mod_iassign', // usually = table name
  4909. 'filearea' => 'activity', // usually = table name
  4910. 'itemid' => 0, // usually = ID of row in table
  4911. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  4912. 'userid' => $USER->id,
  4913. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4914. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  4915. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  4916. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  4917. die();
  4918. }
  4919. /// Function for rename iAssign file
  4920. function rename_file_ilm () {
  4921. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4922. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4923. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4924. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4925. $file = $fs->get_file_by_id($fileid);
  4926. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  4927. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  4928. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4929. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  4930. die();
  4931. }
  4932. /// Function for get iassign file for iassign form
  4933. function add_ilm () {
  4934. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4935. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4936. $output = "
  4937. <script type='text/javascript'>
  4938. //<![CDATA[
  4939. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  4940. iassign_file_link.innerHTML = '$filename';
  4941. window.opener.document.forms['mform1'].file.value='$fileid';
  4942. window.opener.document.forms['mform1'].filename.value='$filename';
  4943. window.close();
  4944. //]]>
  4945. </script>";
  4946. print $output;
  4947. die();
  4948. }
  4949. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  4950. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  4951. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  4952. function preview_ilm ($courseid, $iassign_ilm) {
  4953. global $OUTPUT, $CFG, $USER;
  4954. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4955. $title = get_string('modulename', 'iassign'); // iAssign
  4956. print $OUTPUT->header();
  4957. print $OUTPUT->box_start();
  4958. $javascript = "
  4959. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  4960. <script type='text/javascript'>
  4961. //<![CDATA[
  4962. function submit_close () {
  4963. window.opener.location.reload();
  4964. window.close();
  4965. }
  4966. //]]>
  4967. </script>\n";
  4968. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  4969. // to the complete "applet" tag
  4970. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  4971. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  4972. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  4973. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  4974. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  4975. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  4976. if ($ilm_name != "ivprog") {
  4977. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  4978. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  4979. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  4980. } else {
  4981. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  4982. $content_or_id_from_ilm_security = $this->get_file_ilm();
  4983. $timecreated = time();
  4984. $token = md5($timecreated);
  4985. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  4986. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  4987. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  4988. $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)
  4989. }
  4990. $html = "
  4991. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4992. <table border='1'>
  4993. <tr><td>
  4994. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  4995. <!-- iLM calls : end -->
  4996. </td></tr>
  4997. </table>
  4998. <table>
  4999. <tr>
  5000. <td align='center'>
  5001. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5002. </td></tr>
  5003. </table>
  5004. </form>\n";
  5005. print $javascript . $html;
  5006. print $OUTPUT->box_end();
  5007. //NAO echo format_string($html); // Moodle 3.X
  5008. die();
  5009. } // function preview_ilm($courseid, $iassign_ilm)
  5010. //r_ function preview_ilm ($iassign_ilm)
  5011. //r_ /// Function for preview iassign file from iassign filter.
  5012. //r_ function preview_ilm() {
  5013. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5014. //r_ $tag_filter = $this->tag_ilm($fileid);
  5015. //r_ $javascript = "<script type='text/javascript'>
  5016. //r_ //<![CDATA[
  5017. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5018. //r_ //]]>
  5019. //r_ </script>";
  5020. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5021. //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>
  5022. //r_ </table></form></body></html>";
  5023. //r_ echo $javascript . format_text($html);
  5024. //r_ die;
  5025. //r_ }
  5026. /// Function for export an package (zip) of iassign files
  5027. function export_files_ilm () {
  5028. global $CFG;
  5029. $context = context_course::instance($this->id);
  5030. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5031. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5032. $zip = new zip_archive();
  5033. $zip->open($zip_filename);
  5034. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5035. foreach ($files_id as $file_id) {
  5036. $file = $fs->get_file_by_id($file_id);
  5037. if (!$file->is_directory())
  5038. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5039. else {
  5040. $zip->add_directory($file->get_filepath());
  5041. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5042. foreach ($files_zip as $value) {
  5043. if (!$value->is_directory())
  5044. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5045. else
  5046. $zip->add_directory($value->get_filepath());
  5047. }
  5048. }
  5049. }
  5050. $zip->close();
  5051. header("Pragma: public");
  5052. header("Expires: 0");
  5053. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5054. header("Cache-Control: private", false);
  5055. header("Content-Type: application/zip");
  5056. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5057. header("Content-Transfer-Encoding: binary");
  5058. header("Content-Length: " . @filesize($zip_filename));
  5059. set_time_limit(0);
  5060. @readfile("$zip_filename") || die("File not found.");
  5061. unlink($zip_filename);
  5062. exit;
  5063. }
  5064. /// Function of execute a command in button editor tinymce
  5065. // @param int $fileid Id of file
  5066. function tinymce_ilm ($fileid) {
  5067. $tag_filter = $this->tag_ilm($fileid);
  5068. $output = "<script type='text/javascript'>
  5069. //<![CDATA[
  5070. var tag_filter = '$tag_filter';
  5071. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5072. // all right, insert it
  5073. } else {
  5074. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5075. }
  5076. // window.close();
  5077. //]]>
  5078. </script>\n";
  5079. print $output;
  5080. die();
  5081. }
  5082. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5083. /// Function to add content to the Editor Window
  5084. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5085. // @param int $fileid Id of file
  5086. function editor_ilm ($fileid, $editor) {
  5087. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5088. $output1 = "<script type='text/javascript'>
  5089. //<![CDATA[
  5090. var tag_filter = '$tag_filter';\n";
  5091. if ($editor == 'atto') {
  5092. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5093. } elseif ($editor == 'tinyMCE') {
  5094. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5095. } else
  5096. $output2 = "";
  5097. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5098. window.close();
  5099. //]]>
  5100. </script>\n";
  5101. //D var_dump($output);
  5102. print $output1 . $output2 . $output3;
  5103. die();
  5104. }
  5105. /// Function to add content to the Atto Editor Window
  5106. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5107. // @param int $fileid Id of file
  5108. function atto_ilm ($fileid) {
  5109. global $CFG, $DB;
  5110. $tag_filter = $this->tag_ilm($fileid);
  5111. $output = "<script type='text/javascript'>
  5112. //<![CDATA[
  5113. var tag_filter = '$tag_filter';
  5114. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5115. // all right, insert iLM tag to this editor
  5116. } else {
  5117. // error trying to insert
  5118. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5119. }
  5120. //window.close();
  5121. //]]>
  5122. </script>\n";
  5123. print $output;
  5124. die();
  5125. }
  5126. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5127. // @param string $key Key for return information
  5128. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5129. function get_dir_ilm ($key) {
  5130. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5131. $context = context_course::instance($this->id);
  5132. $dirid = optional_param('dirid', 0, PARAM_INT);
  5133. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5134. if ($dirid == 0) {
  5135. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5136. $dirid = $dir->get_id();
  5137. }
  5138. else {
  5139. $dir = $fs->get_file_by_id($dirid);
  5140. $dir_base = $dir->get_filepath();
  5141. }
  5142. $dir_parent = $dir->get_parent_directory();
  5143. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5144. return $data[$key];
  5145. }
  5146. /// Function for create an new dir
  5147. function new_dir_ilm () {
  5148. global $USER;
  5149. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5150. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5151. $dir_base = $this->get_dir_ilm('dir_base');
  5152. $context = context_course::instance($this->id);
  5153. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5154. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5155. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5156. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5157. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5158. }
  5159. /// Function for delete an dir
  5160. function delete_dir_ilm () { //
  5161. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5162. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5163. $context = context_course::instance($this->id);
  5164. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5165. $dir_parent = $this->get_dir_ilm('dir_parent');
  5166. if ($dir) {
  5167. if ($dir->is_directory()) {
  5168. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5169. foreach ($files_delete as $value)
  5170. $value->delete();
  5171. $dir->delete();
  5172. }
  5173. }
  5174. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5175. die();
  5176. }
  5177. /// Function for rename an dir
  5178. function rename_dir_ilm () {
  5179. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5180. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5181. $context = context_course::instance($this->id);
  5182. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5183. $dir_parent = $this->get_dir_ilm('dir_parent');
  5184. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5185. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5186. if ($dir->is_directory()) {
  5187. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5188. foreach ($files_rename_path as $value)
  5189. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5190. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5191. }
  5192. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5193. die();
  5194. }
  5195. /// Function for move an dir and your content for other dir
  5196. function selected_move_ilm () {
  5197. global $PAGE, $OUTPUT, $CFG;
  5198. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5199. $context = context_course::instance($this->id);
  5200. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5201. $dirid = $this->get_dir_ilm('dirid');
  5202. $dir_base = $this->get_dir_ilm('dir_base');
  5203. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5204. $code_javascript_ilm = "
  5205. <script type='text/javascript'>
  5206. //<![CDATA[
  5207. function getRadiobutton () {
  5208. var radioButtons = document.getElementsByTagName('input');
  5209. var param = '';
  5210. for (var counter=0; counter < radioButtons.length; counter++) {
  5211. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5212. param = radioButtons[counter].value;
  5213. }
  5214. return param;
  5215. }
  5216. function move_selected_ilm () {
  5217. var msgAnswer;
  5218. if (getRadiobutton() != '') {
  5219. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5220. if (msgAnswer)
  5221. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5222. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5223. }
  5224. else
  5225. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5226. }
  5227. function cancel_selected_ilm () {
  5228. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5229. }
  5230. //]]>
  5231. </script>\n";
  5232. $title = get_string('move_files', 'iassign');
  5233. $PAGE->set_title($title);
  5234. $PAGE->set_pagelayout('base');
  5235. print $OUTPUT->header();
  5236. print $OUTPUT->heading($title);
  5237. $dir_paths = array();
  5238. print $OUTPUT->box_start();
  5239. print "<center>";
  5240. foreach ($files_id as $file_id) {
  5241. $file = $fs->get_file_by_id($file_id);
  5242. if ($file) {
  5243. if (!$file->is_directory())
  5244. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5245. else {
  5246. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5247. array_push($dir_paths, $file->get_filepath());
  5248. }
  5249. }
  5250. }
  5251. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5252. if ($dir_base != '/') {
  5253. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5254. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5255. }
  5256. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5257. foreach ($files_tree as $file) {
  5258. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5259. $is_parent = false;
  5260. foreach ($dir_paths as $dir) {
  5261. $path = explode("/", $dir);
  5262. array_pop($path);
  5263. $path[count($path) - 1] = '';
  5264. $path = implode("/", $path);
  5265. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5266. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5267. }
  5268. if ($is_parent == false) {
  5269. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5270. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5271. }
  5272. }
  5273. }
  5274. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5275. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5276. print "</center>";
  5277. print $OUTPUT->box_end();
  5278. print $OUTPUT->footer();
  5279. print $code_javascript_ilm;
  5280. die;
  5281. }
  5282. /// Function for move files for an dir
  5283. function move_files_ilm () {
  5284. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5285. $context = context_course::instance($this->id);
  5286. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5287. $dirid = $this->get_dir_ilm('dirid');
  5288. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5289. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5290. foreach ($files_id as $file_id) {
  5291. $file = $fs->get_file_by_id($file_id);
  5292. if ($file) {
  5293. if ($file->is_directory()) {
  5294. $pathname = explode("/", $file->get_filepath());
  5295. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5296. foreach ($files_move_path as $value) {
  5297. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5298. $value->rename($path_move, $value->get_filename());
  5299. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5300. }
  5301. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5302. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5303. $file->rename($path_move, $file->get_filename());
  5304. } else {
  5305. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5306. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5307. }
  5308. }
  5309. }
  5310. //die;
  5311. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5312. die();
  5313. } // function move_files_ilm()
  5314. /// Function for recover files in use on all activities of a course
  5315. function recover_files_ilm () {
  5316. global $DB, $USER;
  5317. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5318. $courseid = optional_param('id', NULL, PARAM_INT);
  5319. $dirid = $this->get_dir_ilm('dirid');
  5320. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5321. $contextfile = context_course::instance($this->id);
  5322. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5323. foreach ($iassigns as $iassign) {
  5324. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5325. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5326. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5327. $context = context_module::instance($cm->id);
  5328. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5329. if ($files) {
  5330. foreach ($files as $value) {
  5331. $extension = explode(".", $value->get_filename());
  5332. if (!$value->is_directory()) {
  5333. $fileinfo = array('contextid' => $contextfile->id,
  5334. 'component' => 'mod_iassign',
  5335. 'filearea' => 'activity',
  5336. 'itemid' => 0,
  5337. 'filepath' => $this->get_dir_ilm('dir_base'),
  5338. 'userid' => $USER->id,
  5339. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5340. 'license' => 'allrightsreserved',
  5341. 'timecreated' => time(),
  5342. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5343. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5344. }
  5345. }
  5346. } // if ($files)
  5347. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5348. } // foreach ($iassigns as $iassign)
  5349. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5350. die();
  5351. } // function recover_files_ilm()
  5352. /// Auxiliary function the get all files in a given context
  5353. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5354. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5355. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5356. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5357. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5358. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5359. // (NAO s_iassign_statement.file = s_files.id)
  5360. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5361. $dir_base = $this->get_dir_ilm('dir_base');
  5362. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5363. $countf = 0;
  5364. $array_files_id = array(); // all files from this context
  5365. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5366. //$filename = $item_fc->get_filename();
  5367. //$filepath = $item_fc->get_filepath();
  5368. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5369. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5370. // $array_files_aux[] = $item_fc;
  5371. $itemid = $item_fc->get_id();
  5372. if (!in_array($itemid, $array_files_id)) {
  5373. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5374. if ($fileuserid == $userid)
  5375. $filesfrommine[] = $item_fc;
  5376. else
  5377. $filesfromothers[] = $item_fc;
  5378. $array_files_id[] = $itemid;
  5379. $countf++;
  5380. }
  5381. }
  5382. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5383. return $countf;
  5384. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5385. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5386. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5387. function get_all_ilm_files_by_fileid ($fileid) {
  5388. global $DB, $USER;
  5389. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5390. //TODO Criar coluna 'authorid'
  5391. $str_query = "SELECT * FROM {iassign_statement} " .
  5392. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5393. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5394. return $array_iassign_ilm;
  5395. }
  5396. //NN
  5397. //NN
  5398. // Build string with JavaScript code with function to edit/remove/double iLM files
  5399. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5400. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5401. global $CFG;
  5402. $error_files_exists = get_string('error_file_exists', 'iassign');
  5403. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5404. $code_javascript_ilm = "
  5405. <script type='text/javascript'>
  5406. //<![CDATA[
  5407. function preview_ilm (fileid, ilmid) { //JavaScript function
  5408. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5409. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5410. }
  5411. function update_ilm (ilmid, fileid) { //JavaScript function
  5412. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5413. }
  5414. function delete_ilm (ilmid, fileid) { //JavaScript function
  5415. var msgAnswer;
  5416. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5417. if (msgAnswer) {
  5418. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5419. }
  5420. }
  5421. function delete_selected_ilm () { //JavaScript function
  5422. var msgAnswer;
  5423. var param = getCheckbox();
  5424. if (param.join() != '') {
  5425. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5426. if (msgAnswer)
  5427. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5428. }
  5429. else
  5430. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5431. }
  5432. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5433. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5434. }
  5435. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5436. var filenamecopy;
  5437. var i;
  5438. var files = new Array(" . $files_array . ");
  5439. do {
  5440. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5441. } while (filenamecopy == '');
  5442. if (filenamecopy == null)
  5443. return false;\n
  5444. else {
  5445. for (i=0;i<files.length;i++) {
  5446. if (files[i]==filenamecopy) {
  5447. alert('" . $error_files_exists . "');
  5448. return false;\n
  5449. }
  5450. }\n" .
  5451. // @see: function 'duplicate_file_ilm()' above
  5452. "
  5453. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5454. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5455. } // else
  5456. }
  5457. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5458. var filenamecopy;
  5459. var i;
  5460. var files = new Array($files_array);
  5461. do {
  5462. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5463. } while (filenamecopy == '');
  5464. if (filenamecopy == null)
  5465. return false;
  5466. else {
  5467. for (i=0;i<files.length;i++) {
  5468. if (files[i]==filenamecopy) {
  5469. alert('" . $error_files_exists . "');
  5470. return false;
  5471. }
  5472. }
  5473. 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;
  5474. }
  5475. }
  5476. function export_files_ilm () { //JavaScript function
  5477. var param = getCheckbox();
  5478. if (param.join() != '')
  5479. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5480. else
  5481. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5482. }
  5483. function select_all_ilm () { //JavaScript function
  5484. var checkBoxes = document.getElementsByTagName('input');
  5485. var selectAll = document.getElementById('select_all');
  5486. for (var counter=0; counter < checkBoxes.length; counter++) {
  5487. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5488. checkBoxes[counter].checked = selectAll.checked;
  5489. }
  5490. }
  5491. function getCheckbox () { //JavaScript function
  5492. var checkBoxes = document.getElementsByTagName('input');
  5493. var param = new Array();
  5494. for (var counter=0; counter < checkBoxes.length; counter++) {
  5495. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5496. param.push(checkBoxes[counter].value);
  5497. }
  5498. return param;
  5499. }
  5500. function new_dir_ilm () { //JavaScript function
  5501. var dirname = '';
  5502. var i;
  5503. var dirs = new Array(" . $dirs_array . ");
  5504. do {
  5505. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5506. } while (dirname == '');
  5507. if (dirname == null)
  5508. return false;\n
  5509. else {
  5510. for (i=0;i<dirs.length;i++) {
  5511. if (dirs[i]==dirname) {
  5512. alert('" . $error_dir_exists . "');
  5513. return false;\n
  5514. }
  5515. }
  5516. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5517. }
  5518. }
  5519. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5520. var msgAnswer;
  5521. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5522. if (msgAnswer) {
  5523. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5524. }
  5525. }
  5526. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5527. var dirnamecopy;
  5528. var i;
  5529. var dirs = new Array($dirs_array);
  5530. do {
  5531. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5532. } while (dirnamecopy == '');
  5533. if (dirnamecopy == null)
  5534. return false;\n
  5535. else {
  5536. for (i=0;i<dirs.length;i++) {
  5537. if (dirs[i]==dirnamecopy) {
  5538. alert('" . $error_dir_exists . "');
  5539. return false;\n
  5540. }
  5541. }
  5542. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5543. }
  5544. }
  5545. function move_selected_ilm (ilmid) { //JavaScript function
  5546. var param = getCheckbox();
  5547. if (param.join() != '')
  5548. 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();
  5549. else
  5550. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5551. }
  5552. function recover_files_ilm () { //JavaScript function
  5553. var msgAnswer;
  5554. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5555. if (msgAnswer) {
  5556. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5557. }
  5558. }
  5559. window.onload = function() { //JavaScript function
  5560. var xPosition = 0;
  5561. var yPosition = 0;
  5562. element=document.getElementById('new_file');
  5563. while(element) {
  5564. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5565. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5566. element = element.offsetParent;
  5567. }
  5568. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5569. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5570. location.hash = '#new_file';
  5571. };
  5572. //]]>
  5573. </script>\n"; // end of $code_javascript_ilm
  5574. return $code_javascript_ilm;
  5575. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5576. /// List iassign files from course directory
  5577. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5578. function view_files_ilm ($iassign_ilm_class, $extension) {
  5579. global $CFG, $DB, $USER, $OUTPUT;
  5580. $fs = get_file_storage();
  5581. $context = context_course::instance($this->id);
  5582. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5583. $dirid = $this->get_dir_ilm('dirid');
  5584. $dir_base = $this->get_dir_ilm('dir_base');
  5585. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5586. $files_array = '';
  5587. foreach ($files_course as $value) {
  5588. if (!$value->is_directory())
  5589. $files_array .= "'" . $value->get_filename() . "',";
  5590. }
  5591. $files_array .= "''";
  5592. $error_files_exists = get_string('error_file_exists', 'iassign');
  5593. $dirs_array = '';
  5594. foreach ($files_course as $value) {
  5595. if ($value->is_directory()) {
  5596. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  5597. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5598. }
  5599. }
  5600. $dirs_array .= "''";
  5601. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5602. // TODO Rever o preview pois só deixar ver uma vez.
  5603. $code_javascript_ilm = "
  5604. <script type='text/javascript'>
  5605. //<![CDATA[
  5606. function preview_ilm (fileid, ilmid) {
  5607. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5608. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5609. }
  5610. function update_ilm (ilmid, fileid) {
  5611. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5612. }
  5613. function delete_ilm (ilmid, fileid) {
  5614. var msgAnswer;
  5615. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5616. if (msgAnswer) {
  5617. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5618. }
  5619. }
  5620. function delete_selected_ilm () {
  5621. var msgAnswer;
  5622. var param = getCheckbox();
  5623. if (param.join() != '') {
  5624. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5625. if (msgAnswer)
  5626. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5627. }
  5628. else
  5629. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5630. }
  5631. function add_ilm_iassign (ilmid, filename, fileid) {
  5632. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5633. }
  5634. function duplicate_ilm (ilmid, filename, fileid) {
  5635. var filenamecopy;
  5636. var i;
  5637. var files = new Array($files_array);
  5638. do {
  5639. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5640. } while (filenamecopy == '');
  5641. if (filenamecopy == null)
  5642. return false;\n
  5643. else {
  5644. for (i=0;i<files.length;i++) {
  5645. if (files[i]==filenamecopy) {
  5646. alert('$error_files_exists');
  5647. return false;\n
  5648. }
  5649. }\n" .
  5650. // @see: function 'duplicate_file_ilm()' above
  5651. "
  5652. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5653. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5654. } // else
  5655. }
  5656. function rename_ilm (ilmid, filename, fileid) {
  5657. var filenamecopy;
  5658. var i;
  5659. var files = new Array($files_array);
  5660. do {
  5661. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5662. } while (filenamecopy == '');
  5663. if (filenamecopy == null)
  5664. return false;
  5665. else {
  5666. for (i=0;i<files.length;i++) {
  5667. if (files[i]==filenamecopy) {
  5668. alert('$error_files_exists');
  5669. return false;
  5670. }
  5671. }
  5672. 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;
  5673. }
  5674. }
  5675. function export_files_ilm () {
  5676. var param = getCheckbox();
  5677. if (param.join() != '')
  5678. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5679. else
  5680. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5681. }
  5682. function select_all_ilm () {
  5683. var checkBoxes = document.getElementsByTagName('input');
  5684. var selectAll = document.getElementById('select_all');
  5685. for (var counter=0; counter < checkBoxes.length; counter++) {
  5686. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5687. checkBoxes[counter].checked = selectAll.checked;
  5688. }
  5689. }
  5690. function getCheckbox () {
  5691. var checkBoxes = document.getElementsByTagName('input');
  5692. var param = new Array();
  5693. for (var counter=0; counter < checkBoxes.length; counter++) {
  5694. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5695. param.push(checkBoxes[counter].value);
  5696. }
  5697. return param;
  5698. }
  5699. function new_dir_ilm () {
  5700. var dirname = '';
  5701. var i;
  5702. var dirs = new Array($dirs_array);
  5703. do {
  5704. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5705. } while (dirname == '');
  5706. if (dirname == null)
  5707. return false;\n
  5708. else {
  5709. for (i=0;i<dirs.length;i++) {
  5710. if (dirs[i]==dirname) {
  5711. alert('$error_dir_exists');
  5712. return false;\n
  5713. }
  5714. }
  5715. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5716. }
  5717. }
  5718. function delete_dir_ilm (ilmid, dirid) {
  5719. var msgAnswer;
  5720. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5721. if (msgAnswer) {
  5722. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5723. }
  5724. }
  5725. function rename_dir_ilm (ilmid, dirname, dirid) {
  5726. var dirnamecopy;
  5727. var i;
  5728. var dirs = new Array($dirs_array);
  5729. do {
  5730. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5731. } while (dirnamecopy == '');
  5732. if (dirnamecopy == null)
  5733. return false;\n
  5734. else {
  5735. for (i=0;i<dirs.length;i++) {
  5736. if (dirs[i]==dirnamecopy) {
  5737. alert('$error_dir_exists');
  5738. return false;\n
  5739. }
  5740. }
  5741. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5742. }
  5743. }
  5744. function move_selected_ilm (ilmid) {
  5745. var param = getCheckbox();
  5746. if (param.join() != '')
  5747. 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();
  5748. else
  5749. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5750. }
  5751. function recover_files_ilm () {
  5752. var msgAnswer;
  5753. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5754. if (msgAnswer) {
  5755. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5756. }
  5757. }
  5758. window.onload = function() {
  5759. var xPosition = 0;
  5760. var yPosition = 0;
  5761. element=document.getElementById('new_file');
  5762. while(element) {
  5763. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5764. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5765. element = element.offsetParent;
  5766. }
  5767. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5768. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5769. location.hash = '#new_file';
  5770. };
  5771. //]]>
  5772. </script>\n";
  5773. $output = "";
  5774. $select_all = "";
  5775. $count_files = 0;
  5776. $extensions_allow = array();
  5777. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  5778. foreach ($iassign_ilm as $item_iassign_ilm)
  5779. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  5780. foreach ($files_course as $value) {
  5781. $filename = $value->get_filename();
  5782. $filepath = $value->get_filepath();
  5783. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  5784. $pathname = $pathname[count($pathname) - 1];
  5785. $fileid = $value->get_id();
  5786. $tmp = explode(".", $filename);
  5787. $filetype = $tmp[1];
  5788. $author = $value->get_author();
  5789. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  5790. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  5791. $extensions = explode(",", $extension);
  5792. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  5793. $count_files ++;
  5794. // buscar fileid nas tabelas do iassign
  5795. $list_filein_use = "";
  5796. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5797. if ($iassign_statement_activity_list) {
  5798. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5799. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  5800. }
  5801. }
  5802. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  5803. if (!$iassign_ilm) {
  5804. $iassign_ilm = new stdClass();
  5805. $iassign_ilm->id = $ilmid;
  5806. }
  5807. // Do not use $var inside "..." - problem with some "unusual" operational system
  5808. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  5809. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  5810. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  5811. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  5812. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5813. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5814. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5815. $check_select = "";
  5816. $link_rename = "";
  5817. $link_delete = "";
  5818. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5819. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5820. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5821. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  5822. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5823. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5824. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5825. if ($value->get_userid() == $USER->id) {
  5826. if ($iassign_statement_activity_list) {
  5827. $check_select = "";
  5828. $link_edit = iassign_icons::insert('edit_iassign_disable');
  5829. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  5830. $link_rename = "";
  5831. } else {
  5832. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  5833. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  5834. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  5835. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  5836. }
  5837. }
  5838. if (!in_array($filetype, $extensions_allow)) {
  5839. $link_edit = "";
  5840. $link_add_ilm_iassign = "";
  5841. $link_add_ilm_tinymce = "";
  5842. $link_add_ilm_atto = "";
  5843. $link_filter = "";
  5844. }
  5845. if ($value->is_directory()) {
  5846. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  5847. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  5848. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  5849. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  5850. <td><center>$author</center></td>
  5851. <td><center>$timecreated</center></td>
  5852. <td><center>$timemodified</center></td></tr>\n";
  5853. }
  5854. else if ($this->from == 'iassign') {
  5855. $new_id = "";
  5856. $new_class = "";
  5857. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  5858. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  5859. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  5860. }
  5861. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  5862. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5863. <td><center>$author</center></td>
  5864. <td><center>$timecreated</center></td>
  5865. <td><center>$timemodified</center></td></tr>\n";
  5866. }
  5867. else if ($this->from == 'block') {
  5868. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  5869. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5870. <td><center>$author</center></td>
  5871. <td><center>$timecreated</center></td>
  5872. <td><center>$timemodified</center></td></tr>\n";
  5873. }
  5874. else if ($this->from == 'tinymce') {
  5875. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  5876. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5877. <td><center>$author</center></td>
  5878. <td><center>$timecreated</center></td>
  5879. <td><center>$timemodified</center></td></tr>\n";
  5880. }
  5881. else if ($this->from == 'atto') {
  5882. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  5883. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5884. <td><center>$author</center></td>
  5885. <td><center>$timecreated</center></td>
  5886. <td><center>$timemodified</center></td></tr>\n";
  5887. }
  5888. }
  5889. }
  5890. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  5891. $dir_base = "";
  5892. $header = "";
  5893. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  5894. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  5895. foreach ($basename as $value) {
  5896. $dir_base .= $value . "/";
  5897. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  5898. if ($dir_id) {
  5899. if ($value == "") {
  5900. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5901. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  5902. } else {
  5903. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5904. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  5905. }
  5906. }
  5907. } // foreach ($basename as $value)
  5908. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  5909. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  5910. $html .= "
  5911. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  5912. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  5913. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  5914. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  5915. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  5916. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  5917. </table>\n";
  5918. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  5919. $html .= "<table width='100%'><tr>\n";
  5920. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  5921. if ($count_files != 0) {
  5922. $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";
  5923. $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";
  5924. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  5925. }
  5926. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  5927. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  5928. $html .= "</form>\n";
  5929. print $code_javascript_ilm;
  5930. print $html;
  5931. } // function view_files_ilm($extension)
  5932. } // class ilm_manager
  5933. /// Class to insert of icons
  5934. class iassign_icons {
  5935. static function insert ($icon) {
  5936. global $CFG;
  5937. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  5938. return $string;
  5939. }
  5940. }
  5941. /// Class with util functions for plugin manage
  5942. class iassign_utils {
  5943. /// Function to return the filename extension
  5944. // @param string The $filename as an string
  5945. // @return string Return an string (last group after '.')
  5946. static function filename_extension ($filename) {
  5947. if ($filename == null || $filename == '') {
  5948. return null;
  5949. }
  5950. $itens = explode('.', $filename);
  5951. $num = count($itens);
  5952. if ($num < 2) {
  5953. return null;
  5954. }
  5955. return $itens[$num - 1];
  5956. }
  5957. /// Use the PHP class/package ZipArchive to create a Zip file
  5958. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  5959. // 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
  5960. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  5961. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  5962. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  5963. $zip = new zip_archive(); //2
  5964. $res = $zip->open($full_path_zip_filename);
  5965. $total_vet = count($vet_student_filename);
  5966. for ($ii=0; $ii<$total_vet; $ii++) {
  5967. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  5968. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  5969. }
  5970. $ret = $zip->close();
  5971. iassign_utils::download_file($full_path_zip_filename);
  5972. $filenameZip = $zip->filename;
  5973. return array($ret, $zip);
  5974. }
  5975. static function download_file ($zip_filename) {
  5976. header("Pragma: public");
  5977. header("Expires: 0");
  5978. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5979. header("Cache-Control: private", false);
  5980. header("Content-Type: application/zip");
  5981. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5982. header("Content-Transfer-Encoding: binary");
  5983. header("Content-Length: " . @filesize($zip_filename));
  5984. set_time_limit(0);
  5985. @readfile("$zip_filename") || die("File not found.");
  5986. unlink($zip_filename);
  5987. }
  5988. /// Function for format filename remove special caracters
  5989. // @param string $text String for clean
  5990. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  5991. // @return string Return an string in clean format
  5992. static function format_filename ($text) {
  5993. if ($text != '.') {
  5994. //D $text = htmlspecialchars(urldecode($text));
  5995. //D echo "locallib.php: format_filename: $text<br/>";
  5996. if (is_object($text)) // with iAssign did not filtered text from JSON format
  5997. $text = json_decode($text)->{current_language()};
  5998. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  5999. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6000. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6001. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6002. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6003. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6004. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6005. // E.g. text = "exerc_midpoint.course.geo"
  6006. // 0123456789012345678901234
  6007. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6008. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6009. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6010. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6011. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6012. //$ext = strrpos($text, ".");
  6013. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6014. //$text = str_replace($array1, $array2, $text);
  6015. }
  6016. return $text;
  6017. }
  6018. /// Function to filter characters to the file name to iLM content
  6019. // @param string $text String for clean
  6020. // @param string $ext String ot the extension of the iLM
  6021. // @return string Return an string in clean format
  6022. static function filter_filename_extension ($filename, $ext) {
  6023. if ($filename != '.') {
  6024. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6025. $arrTo = array("_","","","","","","","","","","","","");
  6026. $filename = str_replace($arrFrom, $arrTo, $filename);
  6027. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6028. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6029. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6030. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6031. $index_lastposition = strlen($filenameF);
  6032. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6033. $text = str_replace(".", "_", $text); // erase all other "."
  6034. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6035. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6036. }
  6037. else
  6038. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6039. return $filenameF;
  6040. }
  6041. /// Function for format pathname remove special caracters
  6042. // @param string $text String for clean
  6043. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6044. // @return string Return an string in clean format
  6045. static function format_pathname ($text, $is_lowercase = true) {
  6046. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6047. $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", "-", "_", "", "", "");
  6048. $text = str_replace($array1, $array2, $text);
  6049. if ($is_lowercase)
  6050. $text = strtolower($text);
  6051. return $text;
  6052. }
  6053. /// Function for format file name from iLM original name
  6054. // @param string $text String to build the file neam
  6055. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6056. // @return string Return an string in clean format
  6057. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6058. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6059. $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", "-", "_", "", "", "");
  6060. $index_firstposition_blank = strpos($ilm_name, " ");
  6061. if ($index_firstposition_blank) { // truncate the name!
  6062. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6063. }
  6064. $index_firstposition_dots = strpos($ilm_name, ":");
  6065. if ($index_firstposition_dots) { // truncate the name!
  6066. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6067. }
  6068. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6069. if ($is_lowercase)
  6070. $namefiltered = strtolower($namefiltered);
  6071. return $namefiltered;
  6072. }
  6073. /// Function for insert version in the filename
  6074. // @param string $filename Name of file
  6075. // @return string Return the filename with version
  6076. static function version_filename ($filename) {
  6077. $array_filename = explode('.', $filename);
  6078. if (count($array_filename) > 1)
  6079. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6080. else
  6081. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6082. return $filename;
  6083. }
  6084. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6085. static function remove_code_message ($string) {
  6086. $array = explode("&lt;ia_uc&gt;", $string);
  6087. return $array[0];
  6088. }
  6089. }
  6090. // class iassign_utils
  6091. /// Class with language functions for plugin manage
  6092. class iassign_language {
  6093. /// Function for return text in language or get default language (en)
  6094. // @param string $lang Code of language
  6095. // @param string $description JSON text content all languages
  6096. // @return string Return an string in the language selected
  6097. static function get_description_lang ($lang, $descriptions) {
  6098. $description_lang = "";
  6099. $description = json_decode($descriptions);
  6100. if ($description == null) {
  6101. $description_lang = $descriptions;
  6102. }
  6103. else {
  6104. if (isset($description->{$lang}))
  6105. $description_lang = $description->{$lang};
  6106. else
  6107. if (isset($description->en)) //MOOC2014
  6108. $description_lang = $description->en;
  6109. else //MOOC2014
  6110. $description_lang = "en"; //MOOC2014
  6111. }
  6112. return $description_lang;
  6113. }
  6114. /// Function for return all language supported by iLM
  6115. // @param string $descriptions JSON text content all languages
  6116. // @return string Return as string with all languages
  6117. static function get_all_lang ($descriptions) {
  6118. $langs = "";
  6119. $description = json_decode($descriptions);
  6120. if ($description) {
  6121. foreach ($description as $key => $value) {
  6122. $langs .= $key . " ; ";
  6123. }
  6124. $langs = substr($langs, 0, strlen($langs) - 3);
  6125. }
  6126. return $langs;
  6127. }
  6128. /// Function for convert json in xml //MOOC2014
  6129. // @param string $json JSON text
  6130. // @return string Return as string with xml tags
  6131. static function json_to_xml ($json) {
  6132. $xml = "";
  6133. $json = json_decode($json);
  6134. foreach ($json as $key => $value) {
  6135. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6136. }
  6137. return $xml;
  6138. }
  6139. }
  6140. // class iassign_language
  6141. /// Class with log functions for plugin manage.
  6142. class iassign_log {
  6143. /// Function for insert log event
  6144. // @param string $action Code action of event
  6145. // @param string $information Text for describe action of event
  6146. // @param int $cmid Id of context module
  6147. // @param int $ilmid Id of iLM
  6148. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6149. global $COURSE, $CFG, $USER, $DB;
  6150. $newentry = new stdClass();
  6151. $newentry->time = time();
  6152. $newentry->userid = $USER->id;
  6153. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6154. $newentry->course = $COURSE->id;
  6155. $newentry->cmid = $cmid;
  6156. $newentry->ilmid = $ilmid;
  6157. $newentry->action = $action;
  6158. $newentry->info = $information;
  6159. $newentry->language = current_language();
  6160. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6161. if (ini_get("browscap") && function_exists('get_browse')) {
  6162. $browser = get_browse(null, true);
  6163. $newentry->javascript = $browser['javascript'];
  6164. $newentry->java = $browser['javaapplets'];
  6165. }
  6166. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6167. print_error('error_add_log', 'iassign');
  6168. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6169. } // class iassign_log