locallib.php 323 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.2 2019/03/13
  7. * + Several fixes to allow iLM under HTML stack
  8. *
  9. * - v 4.9.1 2017/11/02
  10. * + 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")
  11. * + 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)'
  12. *
  13. * - v 4.9 2017/03/13
  14. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  15. *
  16. * - v 4.8 2016/05/12
  17. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  18. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  19. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  20. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  21. * replaced by
  22. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  23. * - v 4.7 2016/02/17
  24. * + 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(...)')
  25. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  26. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  27. * + 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)
  28. * + 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'
  29. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  30. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  31. *
  32. * --------------- (code bellow was used at our MOOC 2014)
  33. * - v 4.6 2014/02/25
  34. * + Fix bugs in filter function for open applets.
  35. * - v 4.5 2014/02/24
  36. * + Fix bugs in params.
  37. * + Insert new param type.
  38. * - v 4.4 2014/01/24
  39. * + Allow select type of params.
  40. * + Insert the use of applet params specific for activities.
  41. * - v 4.3 2014/01/23
  42. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  43. * - v 4.2 2016/02/13
  44. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  45. * --------------- (above code used at our MOOC 2014)
  46. *
  47. * - v 4.1 2013/12/13
  48. * + Insert log in iAssign actions.
  49. * + 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).
  50. * + Insert class for Log actions in system.
  51. * - v 4.0 2013/10/31
  52. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  53. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  54. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  55. * - v 3.9 2013/10/25
  56. * + Insert support of upgrade iLM.
  57. * + Insert support for more than one extension in iLM.
  58. * + Fix bugs in verion control.
  59. * - v 3.8 2013/09/19
  60. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  61. * - v 3.7 2013/09/12
  62. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  63. * + 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).
  64. * - v 3.6 2013/09/05
  65. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  66. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  67. * + Change tag APPLET in function ilm_settings::view_ilm.
  68. * - v 3.5 2013/08/26
  69. * + Fix bug in download package iassign without answers (iassign::report).
  70. * - v 3.4 2013/08/23
  71. * + Fix bug in export package iassign.
  72. * - v 3.3 2013/08/22
  73. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  74. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  75. * - v 3.2 2013/08/21
  76. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  77. * + Change functions for import files for ilm_manager.php.
  78. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  79. * - v 3.1 2013/08/15
  80. * + Change return file selected (ilm_manager::add_ilm).
  81. * + 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).
  82. * - v 3.0 2013/08/02
  83. * + 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).
  84. * - v 2.9 2013/08/01
  85. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  86. * - v 2.8 2013/07/25
  87. * + Insert the activity name in header of view (activity::view_dates).
  88. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  89. * - v 2.7 2013/07/24
  90. * + Create link previous and next for student view in one activity (activity::view_dates).
  91. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  92. * - v 2.6 2013/07/23
  93. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  94. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  95. * - v 2.5 2013/07/12
  96. * + 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).
  97. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  98. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  99. *
  100. * @author Patricia Alves Rodrigues
  101. * @author Leônidas O. Brandão
  102. * @contributor Igor Moreira Félix (2018-)
  103. * @contributor Márcio de Lima Passos (2014)
  104. * @version v 4.9.2 2019/03/13
  105. * @version v 4.8 2016/05/12
  106. * @package mod_iassign_lib
  107. * @since 2010/09/27
  108. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  109. *
  110. * <b>License</b>
  111. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  112. */
  113. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  114. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  115. //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"'
  116. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  117. /**
  118. * Standard base class for all iAssign
  119. */
  120. class iassign {
  121. var $cm;
  122. var $course;
  123. var $iassign;
  124. var $striassign;
  125. var $striassigns;
  126. var $context;
  127. var $activity;
  128. var $iassign_up;
  129. var $iassign_down;
  130. var $action;
  131. var $iassign_submission_current;
  132. var $userid_iassign;
  133. var $bottonPost;
  134. var $write_solution;
  135. var $view_iassign;
  136. // 3.1 update PHP 7.0 compatibility for all moodle versions
  137. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  138. /// Constructor for the base iassign class
  139. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  140. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  141. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  142. function __construct ($iassign, $cm, $course) {
  143. global $COURSE, $CFG, $USER, $DB;
  144. $botton = optional_param('botton', NULL, PARAM_TEXT);
  145. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  146. if (!is_null($botton))
  147. $USER->iassignEdit = $botton;
  148. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  149. // 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'
  150. $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"
  151. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  152. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  153. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  154. $this->action = optional_param('action', NULL, PARAM_TEXT);
  155. $this->cm = $cm;
  156. $this->context = context_module::instance($this->cm->id);
  157. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  158. $this->userid_iassign = $USER->id;
  159. if ($course) {
  160. $this->course = $course;
  161. }
  162. else if ($this->cm->course == $COURSE->id) {
  163. $this->course = $COURSE;
  164. }
  165. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  166. print_error('invalidid', 'iassign');
  167. }
  168. $this->coursecontext = context_course::instance($this->course->id);
  169. if ($iassign) {
  170. $this->iassign = $iassign;
  171. }
  172. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  173. print_error('invalidid', 'iassign');
  174. }
  175. $USER->context = context_module::instance($this->cm->id);
  176. $USER->cm = $this->cm->id;
  177. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  178. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  179. $this->context = context_module::instance($this->cm->id);
  180. $this->striassign = get_string('modulename', 'iassign');
  181. $this->striassigns = get_string('modulenameplural', 'iassign');
  182. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  183. $this->bottonPost = 0;
  184. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  185. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  186. $this->view();
  187. } // function __construct($iassign, $cm, $course)
  188. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  189. // This method provides the page to view each iLM with any interactive activity
  190. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  191. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  192. global $USER, $DB, $OUTPUT;
  193. // $iassign_statementid = $this->iassign->iassign_statementid;
  194. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  195. $iassign_statementid = $this->activity->get_activity()->id;
  196. else
  197. $iassign_statementid = "";
  198. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  199. // If this user has no capability to View 'iassign': stop here
  200. require_capability('mod/iassign:view', $this->context);
  201. // Trigger module view event
  202. $event = \mod_iassign\event\course_module_viewed::create(array(
  203. 'objectid' => $this->iassign->id,
  204. 'context' => $this->context
  205. ));
  206. $event->add_record_snapshot('course', $this->course);
  207. $event->trigger();
  208. if ($this->action) { // when student do/redo activity or teacher see student solution
  209. $this->action(); // calls '$this->view_iLM();'
  210. }
  211. else {
  212. print $OUTPUT->header();
  213. $this->view_iassigns(); // show the iLM with the content
  214. print $OUTPUT->footer();
  215. }
  216. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  217. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  218. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  219. //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" }
  220. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  221. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  222. //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" }
  223. //D else echo "Apagou!<br/>";
  224. die();
  225. } // function view()
  226. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  227. function action () {
  228. global $USER;
  229. // action:
  230. // up - move up activity (mover atividade para cima)
  231. // down - move down activity (mover atividade para baixo)
  232. // visible - view/hide activity (exibir/ocultar atividade)
  233. // delete - delete activity (excluir atividade)
  234. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  235. // deleteno - does not erase activity (não apaga atividade)
  236. // add - add activity (adicionar atividade)
  237. // edit - edit activity (modificar atividade)
  238. $action_iassign = array(
  239. 'newcomment' => '$this->get_answer();',
  240. 'view' => '$this->view_iassign_current();',
  241. 'get_answer' => '$this->get_answer();',
  242. 'repeat' => '$this->view_iassign_current();',
  243. 'overwrite' => '$this->get_answer();',
  244. 'stats_student' => '$this->stats_students();',
  245. 'download_answer' => '$this->export_file_answer();',
  246. 'download_all_answer' => '$this->export_package_answer();');
  247. $action_iassign_limit = array(
  248. 'view' => '$this->view_iassign_current();',
  249. 'newcomment' => '$this->get_answer();',
  250. 'viewsubmission' => '$this->view_iassign_current();',
  251. 'edit_status' => '$this->edit_status();',
  252. 'edit_grade' => '$this->edit_grade();',
  253. 'export_csv' => '$this->export_csv();',
  254. 'report' => '$this->report();',
  255. 'print' => '$this->report();',
  256. 'stats' => '$this->stats();',
  257. 'printstats' => '$this->stats();');
  258. $restricted = array('up' => '$this->activity->move_iassign($this->iassign_up,$this->return);',
  259. 'down' => '$this->activity->move_iassign($this->iassign_down,$this->return);',
  260. 'visible' => '$this->activity->visible_iassign($this->return);',
  261. 'delete' => '$this->activity->delete($this->return);',
  262. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  263. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  264. 'add' => '$this->add_edit_iassign();',
  265. 'edit' => '$this->add_edit_iassign();',
  266. 'get_answer' => '$this->get_answer();',
  267. 'duplicate_activity' => '$this->duplicate_activity();',
  268. 'move_activity' => '$this->move_activity();',
  269. 'auto_evaluate' => '$this->auto_evaluate();');
  270. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  271. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  272. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  273. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  274. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  275. }
  276. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  277. eval($action_iassign_limit[$this->action]);
  278. }
  279. else {
  280. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  281. // Arrive here with: "get_answer"; "view"
  282. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  283. }
  284. } // function action()
  285. /// This method runs activities auto evaluation in teacher area
  286. function auto_evaluate () {
  287. global $COURSE, $CFG, $USER, $DB, $OUTPUT;
  288. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  289. exit;
  290. print $OUTPUT->header();
  291. print $OUTPUT->footer();
  292. }
  293. /// This method moves an iAssign activity
  294. function move_activity () {
  295. global $USER, $CFG, $DB, $COURSE;
  296. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  297. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  298. $update_entry_new_iassign = new stdClass();
  299. $update_entry_new_iassign->id = $iassign_id;
  300. $update_entry_new_iassign->iassignid = $iassign_destiny;
  301. // Update the iassign_statement
  302. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  303. // Update file context
  304. $c_i = context_module::instance($this->cm->id);
  305. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  306. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  307. $path_module = context_course::instance($COURSE->id);
  308. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  309. if ($context_file) {
  310. $id_context = $context_file->id;
  311. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  312. $fs = get_file_storage(); // Get reference to all files in Moodle data
  313. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  314. foreach ($files as $value) {
  315. if ($value->get_filename() != ".") {
  316. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  317. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  318. $updateentry = new stdClass();
  319. $updateentry->id = $iassign_id;
  320. $updateentry->file = $newfile->get_itemid();
  321. $DB->update_record("iassign_statement", $updateentry);
  322. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  323. break;
  324. }
  325. }
  326. }
  327. $this->return_home_course('moved_activity');
  328. exit;
  329. }
  330. /// This method duplicates an iAssign activity
  331. function duplicate_activity () {
  332. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  333. $id = $this->cm->id;
  334. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  335. $context = context_module::instance($this->cm->id);
  336. $contextuser = context_user::instance($USER->id);
  337. // Get the the iAssign acitivity to be duplicated
  338. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  339. // Remove the current id of activity
  340. $iassign_statement->id=0;
  341. // Get the information about current author, and add this information in author_modified field
  342. $author = $DB->get_record("user", array('id' => $USER->id));
  343. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  344. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  345. // Store the activity in the table
  346. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  347. // Duplicate activity file
  348. $fs = get_file_storage(); // Get reference to all files in Moodle data
  349. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  350. foreach ($files as $value) {
  351. if ($value->get_filename() != ".") {
  352. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  353. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  354. $updateentry = new stdClass();
  355. $updateentry->id = $id_;
  356. $updateentry->file = $newfile->get_itemid();
  357. // Update the duplicated iLM iAssign with new file id
  358. $DB->update_record("iassign_statement", $updateentry);
  359. }
  360. }
  361. }
  362. // log event --------------------------------------------------------------------------------------
  363. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  364. $this->return_home_course('duplicated_activity');
  365. exit;
  366. }
  367. /// This method gets the content from the iLM and register it
  368. // It could be the "exercise template" (teacher) or an answer (student)
  369. function get_answer () {
  370. global $USER, $CFG, $DB, $OUTPUT;
  371. $id = $this->cm->id;
  372. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  373. $comment = false;
  374. if ($submission_comment)
  375. $comment = $this->write_comment_submission();
  376. // receives data of iLM using the current activity
  377. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  378. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  379. // receives data of submission of current activity
  380. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  381. // receives post and get
  382. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  383. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  384. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  385. $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)
  386. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  387. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  388. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  389. $msg = '';
  390. // Feedback
  391. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  392. $str_action = "view"; // repeat
  393. if (strtolower($iassign_ilm->name) == "igeom") {
  394. }
  395. $title = get_string('evaluate_iassign', 'iassign');
  396. print $OUTPUT->header();
  397. print $OUTPUT->box_start();
  398. // Action = { view ; repeat ; viewsubmission }
  399. // * '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")
  400. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  401. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  402. $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;
  403. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  404. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  405. print '<table width=100% >';
  406. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  407. //TODO alterar aqui???
  408. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  409. // empty_answer_post = No solution was posted.
  410. if ($comment)
  411. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  412. else
  413. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  414. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  415. } else {
  416. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  417. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  418. // Correct answer!!
  419. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  420. $this->write_solution = 1; //
  421. $status = 3;
  422. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  423. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  424. // log record
  425. $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;
  426. // Trigger module viewed event.
  427. $event = \mod_iassign\event\submission_created::create(array(
  428. 'objectid' => $this->iassign->id,
  429. 'context' => $this->context,
  430. 'other' => $info
  431. ));
  432. $event->add_record_snapshot('course', $this->course);
  433. $event->trigger();
  434. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  435. // Wrong answer...: get_answer_incorrect
  436. $status = 2;
  437. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  438. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  439. // log record
  440. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  441. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  442. // Trigger module viewed event.
  443. $event = \mod_iassign\event\submission_created::create(array(
  444. 'objectid' => $this->iassign->id,
  445. 'context' => $this->context,
  446. 'other' => $info
  447. ));
  448. $event->add_record_snapshot('course', $this->course);
  449. $event->trigger();
  450. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  451. // Presents to the learner the result of the automatic evaluate?
  452. if ($this->activity->get_activity()->show_answer == 0) { // no...
  453. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  454. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  455. print '<tr>';
  456. // log record
  457. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  458. // Trigger module viewed event.
  459. $event = \mod_iassign\event\submission_created::create(array(
  460. 'objectid' => $this->iassign->id,
  461. 'context' => $this->context,
  462. 'other' => $info
  463. ));
  464. $event->add_record_snapshot('course', $this->course);
  465. $event->trigger();
  466. } else { // yes!!!
  467. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  468. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  469. print '<tr>';
  470. print $msg;
  471. }
  472. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  473. $status = 1;
  474. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  475. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  476. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  477. print '<tr>';
  478. // log record
  479. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  480. $event = \mod_iassign\event\submission_created::create(array(
  481. 'objectid' => $this->iassign->id,
  482. 'context' => $this->context,
  483. 'other' => $info
  484. ));
  485. $event->add_record_snapshot('course', $this->course);
  486. $event->trigger();
  487. } // if ($iassign_ilm->evaluate == 1)
  488. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  489. print '</tr></table>';
  490. print $OUTPUT->box_end();
  491. // add or update evaluate
  492. if ($this->write_solution == 1) {
  493. $timenow = time();
  494. // new record
  495. if (!$iassign_submission) {
  496. $newentry = new stdClass();
  497. $newentry->userid = $this->userid_iassign;
  498. // $newentry->userid = $USER->id;
  499. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  500. $newentry->timecreated = $timenow;
  501. $newentry->timemodified = $timenow;
  502. $newentry->answer = $iLM_PARAM_ArchiveContent;
  503. $newentry->grade = $grade_student;
  504. $newentry->status = $status;
  505. $newentry->experiment = 1;
  506. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  507. print_error('error_insert', 'iassign');
  508. } else {
  509. // Trigger module viewed event.
  510. $event = \mod_iassign\event\submission_created::create(array(
  511. 'objectid' => $this->iassign->id,
  512. 'context' => $this->context
  513. ));
  514. $event->add_record_snapshot('course', $this->course);
  515. $event->trigger();
  516. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  517. }
  518. } elseif ($iassign_submission->status != 3) {
  519. $newentry = new stdClass();
  520. $newentry->id = $iassign_submission->id;
  521. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  522. $newentry->userid = $iassign_submission->userid;
  523. $newentry->timecreated = $iassign_submission->timecreated;
  524. $newentry->timemodified = $timenow;
  525. $newentry->answer = $iLM_PARAM_ArchiveContent;
  526. $newentry->grade = $grade_student;
  527. $newentry->status = $status;
  528. $newentry->experiment = $iassign_submission->experiment + 1;
  529. if (!$DB->update_record("iassign_submission", $newentry)) {
  530. print_error('error_update', 'iassign');
  531. //D depurar...
  532. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  533. //D $fp = fopen("teste1.txt","w");
  534. //D fwrite($fp,$stringAux);
  535. } else {
  536. // Trigger module viewed event.
  537. $event = \mod_iassign\event\submission_updated::create(array(
  538. 'objectid' => $this->iassign->id,
  539. 'context' => $this->context
  540. ));
  541. $event->add_record_snapshot('course', $this->course);
  542. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  543. }
  544. } else {
  545. if ($return_get_answer == 1) {
  546. $newentry = new stdClass();
  547. $newentry->id = $iassign_submission->id;
  548. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  549. $newentry->userid = $iassign_submission->userid;
  550. $newentry->timecreated = $iassign_submission->timecreated;
  551. $newentry->timemodified = $timenow;
  552. $newentry->answer = $iLM_PARAM_ArchiveContent;
  553. $newentry->grade = $grade_student;
  554. $newentry->status = $status;
  555. $newentry->experiment = $iassign_submission->experiment + 1;
  556. if (!$DB->update_record("iassign_submission", $newentry))
  557. print_error('error_update', 'iassign');
  558. else {
  559. $event = \mod_iassign\event\submission_updated::create(array(
  560. 'objectid' => $this->iassign->id,
  561. 'context' => $this->context
  562. ));
  563. $event->add_record_snapshot('course', $this->course);
  564. $event->trigger();
  565. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  566. print $OUTPUT->box_start();
  567. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  568. print $OUTPUT->box_end();
  569. }
  570. } elseif ($return_get_answer == 2) {
  571. print $OUTPUT->box_start();
  572. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  573. print $OUTPUT->box_end();
  574. } else {
  575. print $OUTPUT->box_start();
  576. print "
  577. <script type='text/javascript'>
  578. //<![CDATA[
  579. function overwrite () {
  580. document.formEnvio.return_get_answer.value = 1;
  581. document.formEnvio.submit();
  582. }
  583. function nooverwrite () {
  584. document.formEnvio.return_get_answer.value = 2;
  585. document.formEnvio.submit();
  586. }
  587. //]]>
  588. </script>";
  589. $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;
  590. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  591. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  592. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  593. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  594. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  595. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  596. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  597. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  598. <input type='hidden' name='return_get_answer'/> ";
  599. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  600. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  601. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  602. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  603. print " </form>";
  604. print $OUTPUT->box_end();
  605. }
  606. }
  607. } // if ($this->write_solution == 1)
  608. print $OUTPUT->footer();
  609. die();
  610. } // function get_answer()
  611. /// Export in file the answer of student.
  612. function export_file_answer () {
  613. global $DB;
  614. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  615. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  616. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  617. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  618. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  619. $extensions = explode(",", $iassign_ilm->extension);
  620. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  621. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  622. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  623. header("Pragma: public");
  624. header("Expires: 0");
  625. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  626. header("Cache-Control: private", false);
  627. header("Content-Type: document/unknown");
  628. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  629. set_time_limit(0);
  630. print($iassign_submission->answer);
  631. exit;
  632. } // function export_file_answer()
  633. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  634. // @calledby $this->export_package_answer()
  635. //TODO Precisa terminar! //TODO_HTML
  636. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  637. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  638. <head>
  639. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  640. $str_html .= " </head>
  641. <body>\n";
  642. $tam = sizeof($array_iassign_name);
  643. for ($ii=0; $ii<$tam; $ii++) {
  644. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  645. }
  646. $str_html .= "
  647. </body>\n</html>";
  648. return $str_html;
  649. }
  650. /// Export an package (zip) with all answer of students
  651. // @calledby $this->action()
  652. function export_package_answer () {
  653. global $DB, $CFG, $OUTPUT;
  654. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  655. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  656. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  657. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  658. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  659. $userid = optional_param('userid', NULL, PARAM_INT);
  660. $iassign_user = $DB->get_record("user", array("id" => $userid));
  661. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  662. //TODO_HTML echo "username=$username<br/>"; exit;
  663. $current_date = date('Y_m_d_H');
  664. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  665. // If temporary directory under Moodle data does not exists => create it
  666. if (!is_dir($diretorio)) {
  667. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  668. // created directory with permissions to be seen by everyone
  669. }
  670. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  671. if (!is_writable($diretorio)) { // send a highlighted message!
  672. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  673. exit; // just in case
  674. }
  675. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  676. $zip = new zip_archive(); // create ZIP
  677. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  678. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  679. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  680. $vet_student_filename = array();
  681. $vet_student_content = array();
  682. foreach ($iassign_statements as $iassign_statement) {
  683. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  684. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  685. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  686. $extensions = explode(",", $iassign_ilm->extension);
  687. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  688. if ($iassign_submission) {
  689. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  690. $student_content = $iassign_submission->answer;
  691. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  692. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  693. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  694. if ($resp) {
  695. $vet_student_filename[] = $student_filename;
  696. $vet_student_content[] = $student_content;
  697. }
  698. else { // send a highlighted message!
  699. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  700. exit; // just in case
  701. }
  702. }
  703. }
  704. $zip->close(); // close the ZIP file
  705. if (count($vet_student_filename)>0) {
  706. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  707. $result_tf = $vet_result[0];
  708. $filenameZip = $vet_result[1]->filename;
  709. }
  710. iassign_utils::download_file($zip_filename); // download the ZIP file
  711. exit;
  712. } // function export_package_answer()
  713. /// Editing status of interactive activities
  714. function edit_status () {
  715. global $USER, $DB, $OUTPUT;
  716. $newentry = new stdClass();
  717. $newentry->id = $this->iassign_submission_current;
  718. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  719. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  720. if ($iassign_submission->status != 0 && $newentry->status == 0)
  721. $newentry->status = $iassign_submission->status;
  722. $newentry->teacher = $USER->id;
  723. if (!$DB->update_record('iassign_submission', $newentry))
  724. print_error('error_update', 'iassign');
  725. else {
  726. // Trigger module viewed event.
  727. $event = \mod_iassign\event\submission_updated::create(array(
  728. 'objectid' => $this->iassign->id,
  729. 'context' => $this->context
  730. ));
  731. $event->add_record_snapshot('course', $this->course);
  732. $event->trigger();
  733. $this->action = 'viewsubmission';
  734. $this->view_iassign_current();
  735. } // if (!$DB->update_record('iassign_submission', $newentry))
  736. } // function edit_status()
  737. /// Editing grade of interactive activities
  738. function edit_grade () {
  739. global $USER, $DB, $OUTPUT;
  740. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  741. if ($newgrade && $newgrade >= 0) {
  742. $newentry = new stdClass();
  743. $newentry->id = $this->iassign_submission_current;
  744. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  745. $newentry->teacher = $USER->id;
  746. if (!$DB->update_record('iassign_submission', $newentry))
  747. print_error('error_update', 'iassign');
  748. else {
  749. // Trigger module viewed event.
  750. $event = \mod_iassign\event\submission_updated::create(array(
  751. 'objectid' => $this->iassign->id,
  752. 'context' => $this->context
  753. ));
  754. $event->add_record_snapshot('course', $this->course);
  755. $event->trigger();
  756. }
  757. } // if ($newgrade >= 0)
  758. $this->action = 'viewsubmission';
  759. $this->view_iassign_current();
  760. }
  761. /// Add or Edit interactive activities
  762. // @calledby $this->action()
  763. function add_edit_iassign () {
  764. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  765. require_once('iassign_form.php');
  766. $id = $this->cm->id;
  767. $iassignid = $this->iassign->id;
  768. $param = new stdClass();
  769. $param->action = $this->action; // oculto
  770. $param->id = $id; // oculto
  771. $COURSE->cm = $id;
  772. $COURSE->iassignid = $iassignid;
  773. $COURSE->iassign_file_id = NULL;
  774. $context = context_module::instance($this->cm->id);
  775. $contextuser = context_user::instance($USER->id);
  776. $component = 'mod_iassign';
  777. $filearea = 'exercise';
  778. if (!empty($this->iassign_current))
  779. $COURSE->iassign_id = $this->iassign_current;
  780. else
  781. $COURSE->iassign_id = 0;
  782. $total_of_activities = 0; // get the total number of activities in this iAssign block
  783. if ($this->action == 'add') {
  784. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  785. $total_of_activities = count($iassign_data);
  786. $params = array('iassignid' => $iassignid);
  787. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  788. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  789. $param->iassignid = $iassignid;
  790. $param->name = "";
  791. $param->oldname = "";
  792. $param->type_iassign = 3;
  793. $param->proposition = "";
  794. $author = $DB->get_record("user", array("id" => $USER->id));
  795. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  796. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  797. $param->author = $param->author_name;
  798. $param->author_modified = $param->author_modified_name;
  799. $COURSE->iassign_list = array();
  800. $param->iassign_list = array();
  801. if ($iassign_statement) {
  802. foreach ($iassign_statement as $iassign) {
  803. $iassignid = $iassign->id;
  804. $param->iassign_list[$iassignid] = 0;
  805. $COURSE->iassign_list[$iassignid] = new stdClass();
  806. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  807. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  808. $COURSE->iassign_list[$iassignid]->enable = 1;
  809. } // foreach ($iassign_statement as $iassign)
  810. }
  811. $param->iassign_ilmid = 0;
  812. //echo "locallib.php: add_edit_iassign(): add<br/>";
  813. $param->file = 0;
  814. $param->fileold = 0;
  815. $param->filename = "";
  816. $param->grade = $iassign_data->grade;
  817. $param->timemodified = time();
  818. $param->timecreated = time();
  819. $param->timeavailable = $iassign_data->timeavailable;
  820. $param->timedue = $iassign_data->timedue;
  821. $param->preventlate = $iassign_data->preventlate;
  822. $param->test = $iassign_data->test;
  823. $param->special_param1 = 0;
  824. $param->visible = 1;
  825. $param->max_experiment = $iassign_data->max_experiment;
  826. $param->dependency = 0;
  827. $param->automatic_evaluate = 1;
  828. $param->show_answer = 1;
  829. } // if ($this->action == 'add')
  830. elseif ($this->action == 'edit') {
  831. $COURSE->iassign_list = array();
  832. $this_activity = $this->activity->get_activity();
  833. if ($this_activity != null) {
  834. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  835. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  836. $param->iassign_id = $iassign_statement_current->id; // oculto
  837. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  838. $param->name = $iassign_statement_current->name;
  839. $param->oldname = $iassign_statement_current->name;
  840. $param->type_iassign = $iassign_statement_current->type_iassign;
  841. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  842. //2019 $param->proposition = $iassign_statement_current->proposition;
  843. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  844. $param->author_name = $iassign_statement_current->author_name; // oculto
  845. $param->author = $iassign_statement_current->author_name;
  846. $author = $DB->get_record("user", array('id' => $USER->id));
  847. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  848. $param->author_modified = $param->author_modified_name;
  849. $dependency = explode(';', $iassign_statement_current->dependency);
  850. $param->iassign_list = array();
  851. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  852. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  853. $array_dependency = array();
  854. $subdependency = "";
  855. $sub_subdependency = "";
  856. // dependent on this exercise
  857. if ($iassign_statement_dependency) {
  858. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  859. // to whom this exercise depends
  860. foreach ($inter as $tmp)
  861. $sub_subdependency .= $this->search_sub_dependency($tmp);
  862. $list_dependency = $subdependency . $sub_subdependency;
  863. $array_dependency = explode(";", $list_dependency);
  864. }
  865. // Get all activity with the same iLM - iassignid
  866. $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";
  867. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  868. $total_of_activities = count($all_others_iassign_statement) + 1;
  869. $inter = array();
  870. if ($all_others_iassign_statement) {
  871. foreach ($all_others_iassign_statement as $iassign)
  872. if (in_array($iassign->id, $dependency))
  873. $inter[] = $iassign->id;
  874. }
  875. if ($all_others_iassign_statement) {
  876. foreach ($all_others_iassign_statement as $iassign) {
  877. $iassignid = $iassign->id;
  878. $COURSE->iassign_list[$iassignid] = new stdClass();
  879. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  880. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  881. if (in_array($iassignid, $dependency))
  882. $param->iassign_list[$iassignid] = 1;
  883. else
  884. $param->iassign_list[$iassignid] = 0;
  885. if (in_array($iassignid, $array_dependency))
  886. $COURSE->iassign_list[$iassignid]->enable = 0;
  887. else
  888. $COURSE->iassign_list[$iassignid]->enable = 1;
  889. } // foreach ($all_others_iassign_statement as $iassign)
  890. }
  891. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  892. $param->fileold = 0;
  893. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  894. $param->filename = '';
  895. $param->grade = $iassign_statement_current->grade;
  896. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  897. $param->timeavailable = $iassign_statement_current->timeavailable;
  898. $param->timedue = $iassign_statement_current->timedue;
  899. $param->preventlate = $iassign_statement_current->preventlate;
  900. $param->test = $iassign_statement_current->test;
  901. $param->special_param1 = $iassign_statement_current->special_param1;
  902. $param->position = $iassign_statement_current->position; // oculto
  903. $param->visible = $iassign_statement_current->visible;
  904. $param->max_experiment = $iassign_statement_current->max_experiment;
  905. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  906. $param->show_answer = $iassign_statement_current->show_answer;
  907. $fs = get_file_storage(); // Get reference to all files in Moodle data
  908. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  909. if ($files) {
  910. foreach ($files as $file) {
  911. if ($file->get_filename() != '.') {
  912. $param->filename = $file->get_filename();
  913. $param->file = $file->get_id();
  914. $param->fileold = $file->get_id();
  915. $COURSE->iassign_file_id = $file->get_id();
  916. }
  917. }
  918. }
  919. //TODO //MOOC2014 -- inicio
  920. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  921. //D if ($iassign_ilm_configs) {
  922. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  923. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  924. //D } //MOOC2014 -- fim
  925. } // if ($this_activity != null)
  926. } // elseif ($this->action == 'edit')
  927. // Get all iActivity in the iAssign block with id = $this->iassign->id
  928. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  929. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  930. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  931. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  932. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  933. $param->position = $total_of_activities;
  934. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  935. $mform->set_data($param);
  936. if ($mform->is_cancelled()) {
  937. $this->return_home_course('iassign_cancel');
  938. exit;
  939. }
  940. else { // if ($mform->is_cancelled())
  941. $result = $mform->get_data();
  942. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  943. if ($result) {
  944. $result->context = $context;
  945. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  946. $result->grade = 0;
  947. if ($result->type_iassign == 1) {
  948. $result->automatic_evaluate = 0;
  949. $result->show_answer = 0;
  950. }
  951. elseif ($result->automatic_evaluate == 0)
  952. $result->show_answer = 0;
  953. // $_POST['iassign_list']
  954. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  955. if ($result->iassign_list) {
  956. foreach ($result->iassign_list as $key => $value)
  957. $result->dependency .= $key . ';';
  958. }
  959. else
  960. $result->dependency = 0;
  961. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  962. //TODO Then get it directly from the form data $_POST!
  963. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  964. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  965. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  966. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  967. if ($this->action == 'add') {
  968. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  969. if ($iassign_statement_name) {
  970. $this->return_home_course('error_iassign_name');
  971. die();
  972. }
  973. // Really insert the new iActivity in table '*_iassign_statement'
  974. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  975. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  976. // Trigger module viewed event.
  977. $event = \mod_iassign\event\iassign_created::create(array(
  978. 'objectid' => $iassignid,
  979. 'context' => $context
  980. ));
  981. $event->add_record_snapshot('course', $this->course);
  982. $event->trigger();
  983. $this->return_home_course('iassign_add');
  984. } // if ($this->action == 'add')
  985. elseif ($this->action == 'edit') {
  986. $iassignid = $this->activity->update_iassign($result);
  987. $this->activity->update_calendar($iassignid, $result->oldname);
  988. // Trigger module viewed event.
  989. $event = \mod_iassign\event\iassign_updated::create(array(
  990. 'objectid' => $iassignid,
  991. 'context' => $context
  992. ));
  993. $event->add_record_snapshot('course', $this->course);
  994. $event->trigger();
  995. $this->return_home_course('iassign_update');
  996. } // elseif ($this->action == 'edit')
  997. die();
  998. } // if ($result)
  999. } // else if ($mform->is_cancelled())
  1000. print $OUTPUT->header();
  1001. $mform->display();
  1002. print $OUTPUT->footer();
  1003. die();
  1004. } // function add_edit_iassign()
  1005. /// Search for dependencies
  1006. function search_dependency ($search_iassing_id, $iassign_statement) {
  1007. global $DB, $OUTPUT;
  1008. $dependency = "";
  1009. if ($iassign_statement)
  1010. foreach ($iassign_statement as $iassign) {
  1011. $inter_dependency = explode(';', $iassign->dependency);
  1012. if (in_array($search_iassing_id, $inter_dependency)) {
  1013. $dependency .= $iassign->id . ";";
  1014. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1015. } // if (in_array($search_iassing_id, $inter_dependency))
  1016. } // foreach ($iassign_statement as $iassign)
  1017. return $dependency;
  1018. }
  1019. /// Search for "sub"dependency
  1020. function search_sub_dependency ($search_iassing_id) {
  1021. global $DB, $OUTPUT;
  1022. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1023. $dependency = "";
  1024. if ($iassign_statement) {
  1025. $inter_dependency = explode(';', $iassign_statement->dependency);
  1026. foreach ($inter_dependency as $tmp) {
  1027. if ($tmp != 0)
  1028. $dependency .= $tmp . ";";
  1029. $dependency .= $this->search_sub_dependency($tmp);
  1030. } // foreach ($inter_dependency as $tmp)
  1031. } // if ($iassign_statement)
  1032. return $dependency;
  1033. }
  1034. // Warning message
  1035. static function warning_message_iassign ($strcode) {
  1036. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1037. }
  1038. /// Update grade of iAssign
  1039. // Called always any iAssign activity is created
  1040. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1041. static function update_grade_iassign ($iassignid) {
  1042. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1043. require_once($CFG->libdir . '/gradelib.php');
  1044. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1045. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1046. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1047. // Each iAssign item is associated with one item on the "gradebook"
  1048. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1049. //$sum_grade = 0;
  1050. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1051. //foreach($grade as $tmp) {
  1052. // $sum_grade += $tmp->grade;
  1053. // }
  1054. //1 Solution 1
  1055. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1056. //1 $sum_grade = 0; //1
  1057. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1058. //2 Solution 2
  1059. $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
  1060. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1061. if (key($array_sum_grade))
  1062. $sum_grade = key($array_sum_grade); //2
  1063. else
  1064. $sum_grade = 0; //2
  1065. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1066. $grades = NULL;
  1067. $params = array('itemname' => $grade_iassign->name);
  1068. $params['iteminstance'] = $iassignid;
  1069. $params['gradetype'] = GRADE_TYPE_VALUE;
  1070. //2016 if ($sum_grade != 0) {
  1071. $params['grademax'] = $sum_grade;
  1072. $params['rawgrademax'] = $sum_grade;
  1073. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1074. $params['grademin'] = 0;
  1075. // @calls /lib/gradelib.php: call to grade_item->insert()
  1076. //TODO: is there any error here in Moodle version 3.0?
  1077. //TODO: Incorrect property 'grademax' found when inserting grade object
  1078. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1079. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1080. }
  1081. /// Update grade of student
  1082. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1083. global $CFG, $DB, $OUTPUT;
  1084. require_once($CFG->libdir . '/gradelib.php');
  1085. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1086. // Review all the student submission for this iAssign activity
  1087. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1088. $total_grade = 0;
  1089. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1090. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1091. if ($iassign_submission)
  1092. $total_grade += $iassign_submission->grade;
  1093. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1094. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1095. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1096. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1097. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1098. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1099. $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
  1100. if (key($array_sum_grade))
  1101. $sum_grade = key($array_sum_grade); //2
  1102. else
  1103. $sum_grade = 0; //2
  1104. $grades['userid'] = $userid;
  1105. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1106. $params = array('itemname' => $grade_iassign->name);
  1107. $params['iteminstance'] = $iassignid;
  1108. $params['gradetype'] = GRADE_TYPE_VALUE;
  1109. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1110. $params['grademax'] = $sum_grade;
  1111. $params['rawgrademax'] = $sum_grade;
  1112. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1113. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1114. }
  1115. /// Display caption of icons
  1116. function view_legend_icons () {
  1117. global $USER, $CFG, $DB, $OUTPUT;
  1118. $id = $this->cm->id;
  1119. if ($this->action == 'print')
  1120. print '<table border=1 width=100%><tr>';
  1121. else
  1122. print '<table width=100%><tr>';
  1123. print '<td >';
  1124. if ($this->action != 'print')
  1125. print $OUTPUT->help_icon('legend', 'iassign');
  1126. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1127. // $imagetext = '');
  1128. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1129. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1130. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1131. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1132. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1133. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1134. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1135. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1136. print '</td>' . "\n";
  1137. if ($this->action != 'print') {
  1138. $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>";
  1139. $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>";
  1140. $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>";
  1141. $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>";
  1142. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1143. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1144. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1145. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1146. } // if ($this->action != 'print')
  1147. print '</tr></table>' . "\n";
  1148. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1149. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1150. $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>";
  1151. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1152. print '</tr></table>' . "\n";
  1153. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1154. else
  1155. print '</td></tr></table>' . "\n";
  1156. } // function view_legend_icons()
  1157. /// Display activity current
  1158. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1159. function view_iassign_current () {
  1160. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1161. $id = $this->cm->id;
  1162. $iassignid = $this->iassign->id;
  1163. $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
  1164. // 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 ...
  1165. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1166. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1167. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1168. // 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
  1169. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1170. // log record
  1171. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1172. //Trigger module viewed event.
  1173. $event = \mod_iassign\event\submission_viewed::create(array(
  1174. 'objectid' => $iassign->id,
  1175. 'context' => $this->context,
  1176. 'other' => $info
  1177. ));
  1178. $event->add_record_snapshot('course', $this->course);
  1179. $event->trigger();
  1180. print $OUTPUT->header();
  1181. // Search of iLM data used in the current activity
  1182. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1183. if ($this->action == 'viewsubmission') {
  1184. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1185. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1186. else
  1187. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1188. } else {
  1189. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1190. }
  1191. if ($iassign_submission)
  1192. $this->update_comment($iassign_submission->id);
  1193. $file = $iassign_statement_activity_item->file;
  1194. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1195. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1196. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1197. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1198. $this->bottonPost = 0; // hide submit button
  1199. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1200. $this->view_iassign = false; // disable visualization of activity
  1201. $repeat = "";
  1202. $last_iassign = "";
  1203. $student_answer = "";
  1204. $comment = "";
  1205. // *** Teacher access (view learner's submission)
  1206. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1207. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1208. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1209. // ---> access teacher for test
  1210. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1211. $this->bottonPost = 1;
  1212. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1213. $this->activity->view_dates();
  1214. $USER->iassignEdit = $this->bottonPost;
  1215. $this->activity->show_info_iassign();
  1216. if ($iassign_submission) {
  1217. //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;
  1218. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1219. } else {
  1220. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1221. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1222. }
  1223. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1224. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1225. // Prepare tags to present the iLM
  1226. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1227. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1228. // *** (end) Teacher access (view the activity)
  1229. // *** Teacher access (view learner's submission to the activity)
  1230. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1231. // It is teacher or 'nonediting teacher' that can evaluate
  1232. // ----> area teacher evaluate
  1233. $row = optional_param('row', 0, PARAM_INT);
  1234. $column = optional_param('column', 0, PARAM_INT);
  1235. $link_next = iassign_icons::insert('right_disable');
  1236. $link_previous = iassign_icons::insert('left_disable');
  1237. $link_up = iassign_icons::insert('up_disable');
  1238. $link_down = iassign_icons::insert('down_disable');
  1239. // next_activity
  1240. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1241. $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);
  1242. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1243. }
  1244. // previous_activity
  1245. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1246. $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);
  1247. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1248. }
  1249. // previous_student
  1250. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1251. $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);
  1252. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1253. }
  1254. // next_student
  1255. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1256. $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);
  1257. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1258. }
  1259. if ($iassign_submission) {
  1260. $student_answer = $iassign_submission->answer;
  1261. }
  1262. $last_iassign = get_string('last_iassign', 'iassign');
  1263. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1264. // Messages related to due date (and user role)
  1265. $this->activity->view_dates();
  1266. print $OUTPUT->box_start();
  1267. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1268. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1269. print $OUTPUT->user_picture($user_data);
  1270. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1271. print '</td>' . "\n";
  1272. print '<td width=20% align=right>' . "\n";
  1273. print '<table width=50 cellpadding="0">';
  1274. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1275. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1276. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1277. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1278. print '</table>' . "\n";
  1279. print '</td></tr></table>' . "\n";
  1280. print $OUTPUT->box_end();
  1281. print $OUTPUT->box_start();
  1282. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1283. print '<td width=60% valign="top">' . "\n";
  1284. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1285. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1286. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1287. $resp = get_string('yes');
  1288. else
  1289. $resp = get_string('no');
  1290. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1291. if ($iassign_statement_activity_item->show_answer == 1)
  1292. $resp = get_string('yes');
  1293. else
  1294. $resp = get_string('no');
  1295. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1296. print '</td>';
  1297. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1298. print '<td width=40% valign="top" align="left">';
  1299. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1300. // check status of solution sent by the student
  1301. if ($iassign_submission) {
  1302. switch ($iassign_submission->status) {
  1303. case 3 :
  1304. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1305. break;
  1306. case 2 :
  1307. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1308. break;
  1309. case 1 :
  1310. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1311. break;
  1312. default :
  1313. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1314. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1315. } // switch ($iassign_submission->status)
  1316. }
  1317. else { // if ($iassign_submission)
  1318. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1319. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1320. }
  1321. // update_status
  1322. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1323. $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);
  1324. print " <script type='text/javascript'>
  1325. //<![CDATA[
  1326. function overwriteStatus (newstatus) {
  1327. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1328. document.formEditStatus.return_status.value=newstatus;
  1329. document.formEditStatus.submit();
  1330. }
  1331. else
  1332. document.formEditStatus.return_status.value=-1;
  1333. }
  1334. //]]>
  1335. </script>";
  1336. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1337. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1338. 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";
  1339. print " <input type='hidden' name='return_status'>\n";
  1340. print "</form>\n";
  1341. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1342. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1343. $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);
  1344. print "
  1345. <script type='text/javascript'>
  1346. //<![CDATA[
  1347. function overwriteGrade (newgrade,maxgrade) {
  1348. if (newgrade<0 || newgrade>maxgrade) {
  1349. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1350. document.formEditGrade.return_grade.value=-1;
  1351. document.formEditGrade.submit();
  1352. }
  1353. else {
  1354. document.formEditGrade.return_grade.value=newgrade;
  1355. document.formEditGrade.submit();
  1356. }
  1357. }
  1358. //]]>
  1359. </script>";
  1360. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1361. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1362. print " <input type='text' name='grade' size='6'>";
  1363. print " <input type='hidden' name='return_grade'> ";
  1364. 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";
  1365. print "</form>";
  1366. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1367. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1368. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1369. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1370. if ($teacher)
  1371. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1372. } // if ($iassign_submission->experiment > 0)
  1373. print '</td>';
  1374. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1375. print '</tr></table>';
  1376. print $OUTPUT->box_end();
  1377. $USER->iassignEdit = $this->bottonPost;
  1378. if ($iassign_submission && $allow_resubmission) {
  1379. // Put the iLM to
  1380. print $OUTPUT->box_start();
  1381. print '<p><strong>' . $last_iassign . '</strong></p>';
  1382. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1383. $enderecoPOST = "";
  1384. // Prepare tags to present the iLM
  1385. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1386. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1387. print $OUTPUT->box_end();
  1388. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1389. // ATTENTION: exception used by iGeom (exercise with "script")
  1390. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1391. if (substr($ilm_name, 0, 5)=="igeom") {
  1392. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1393. $loadTeacherActivity = true;
  1394. }
  1395. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1396. if (!$enderecoPOST) $enderecoPOST = "";
  1397. // Prepare tags to present the iLM
  1398. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1399. }
  1400. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1401. $output = '';
  1402. $history_comment = '';
  1403. if ($iassign_submission) {
  1404. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1405. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1406. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1407. }
  1408. else {
  1409. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1410. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1411. }
  1412. $output .= $OUTPUT->box_start();
  1413. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  1414. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  1415. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  1416. $output .= "</form></center>\n";
  1417. if (!empty($history_comment)) {
  1418. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  1419. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  1420. $output .= $history_comment;
  1421. $output .= "</table>";
  1422. }
  1423. $output .= $OUTPUT->box_end();
  1424. print $output;
  1425. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1426. } // elseif (($this->action == 'viewsubmission')
  1427. // *** (end) Teacher access (view learner's submission to the activity)
  1428. // *** Student access (view the activity)
  1429. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1430. // It could be the learner (he could send or resend the activity)
  1431. // ---> access student
  1432. $time_now = time();
  1433. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1434. // activity of type example - not submit button for submission
  1435. $this->view_iassign = true;
  1436. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1437. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1438. // activity of type test - iLM automatic evaluator - submit button for submission
  1439. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1440. $this->bottonPost = 1;
  1441. $this->view_iassign = true;
  1442. } else
  1443. $this->view_iassign = false;
  1444. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1445. // activity of type exercise (learner can send his answer, if yet open...)
  1446. $this->view_iassign = true;
  1447. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1448. $this->view_iassign = false;
  1449. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1450. $this->bottonPost = 1; // allow the submit button
  1451. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1452. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1453. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1454. if (!$iassign_submission) {
  1455. $str_iassign_submission_id = '';
  1456. $str_iassign_submission_answer = '';
  1457. }
  1458. else {
  1459. $str_iassign_submission_id = $iassign_submission->id;
  1460. $str_iassign_submission_answer = $iassign_submission->answer;
  1461. }
  1462. if ($this->action != 'repeat') {
  1463. $repeat = "<a href='view.php?action=repeat&id="
  1464. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1465. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1466. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1467. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1468. }
  1469. $this->bottonPost = 1;
  1470. $this->write_solution = 1; // can register his submission
  1471. $student_answer = $str_iassign_submission_answer;
  1472. }
  1473. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1474. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1475. $last_iassign = get_string('last_iassign', 'iassign');
  1476. if ($iassign_submission) {
  1477. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1478. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1479. $student_answer = $iassign_submission->answer;
  1480. } else {
  1481. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1482. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1483. }
  1484. }
  1485. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1486. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1487. $this->bottonPost = 1;
  1488. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1489. } else {
  1490. $last_iassign = get_string('last_iassign', 'iassign');
  1491. if ($iassign_submission) {
  1492. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1493. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1494. $student_answer = $iassign_submission->answer;
  1495. } else {
  1496. // Symbol of "redo activity"
  1497. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1498. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1499. }
  1500. }
  1501. } // elseif ($iassign_statement_activity_item->test == 1)
  1502. elseif ($iassign_statement_activity_item->test == 0)
  1503. $this->view_iassign = false;
  1504. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1505. if ($iassign_submission)
  1506. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1507. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1508. else
  1509. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1510. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1511. $this->view_legend_icons();
  1512. $this->activity->view_dates();
  1513. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1514. print $OUTPUT->box_start();
  1515. print '<table width=100% border=0 valign="top">' . "\n";
  1516. print '<tr><td width=60% valign="top">' . "\n";
  1517. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1518. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1519. $flag_dependency = true;
  1520. if ($iassign_statement_activity_item->type_iassign == 3) {
  1521. if ($iassign_statement_activity_item->dependency == 0) {
  1522. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1523. } else {
  1524. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1525. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1526. foreach ($dependencys as $dependency) {
  1527. if ($dependency) {
  1528. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1529. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1530. if ($dependencysubmissions) {
  1531. if ($dependencysubmissions->status == 3)
  1532. $icon = iassign_icons::insert('correct');
  1533. elseif ($dependencysubmissions->status == 2) {
  1534. $icon = iassign_icons::insert('incorrect');
  1535. $flag_dependency = false;
  1536. } elseif ($dependencysubmissions->status == 1) {
  1537. $icon = iassign_icons::insert('post');
  1538. $flag_dependency = false;
  1539. } elseif ($dependencysubmissions->status == 0) {
  1540. $icon = iassign_icons::insert('not_post');
  1541. $flag_dependency = false;
  1542. }
  1543. } else {
  1544. $icon = iassign_icons::insert('not_post');
  1545. $flag_dependency = false;
  1546. } // if ($dependencysubmissions)
  1547. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1548. } // if ($dependency)
  1549. } // foreach ($dependencys as $dependency)
  1550. } // if ($iassign_statement_activity_item->dependency == 0)
  1551. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1552. if ($flag_dependency == false) {
  1553. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1554. $this->view_iassign = false;
  1555. print '</tr></table>' . "\n";
  1556. }
  1557. else {
  1558. $this->view_iassign = true;
  1559. print '</td>' . "\n";
  1560. } // if ($flag_dependency == false)
  1561. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1562. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1563. // receiver=1 - message to teacher
  1564. // receiver=2 - message to student
  1565. if ($iassign_submission) {
  1566. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1567. if ($verify_message)
  1568. $comment = iassign_icons::insert('comment_unread');
  1569. }
  1570. print '<td width=40% valign="top" align="left">';
  1571. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1572. if ($iassign_statement_activity_item->show_answer == 1) {
  1573. // check status of solution sent by the student
  1574. if ($iassign_submission) {
  1575. switch ($iassign_submission->status) {
  1576. case 3 :
  1577. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1578. break;
  1579. case 2 :
  1580. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1581. break;
  1582. case 1 :
  1583. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1584. break;
  1585. default :
  1586. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1587. $repeat = "";
  1588. $last_iassign = "";
  1589. } // switch ($iassign_submission->status)
  1590. } else {
  1591. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1592. $repeat = "";
  1593. $last_iassign = "";
  1594. }
  1595. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1596. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  1597. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  1598. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  1599. if ($iassign_statement_activity_item->max_experiment == 0)
  1600. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  1601. else {
  1602. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  1603. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  1604. $repeat = "";
  1605. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  1606. $this->bottonPost = 0;
  1607. $this->write_solution = 0;
  1608. }
  1609. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  1610. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  1611. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1612. if ($teacher)
  1613. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  1614. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  1615. } // if ($iassign_statement_activity_item->show_answer==1)
  1616. else {
  1617. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  1618. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1619. $repeat = "";
  1620. $last_iassign = "";
  1621. } elseif ($iassign_submission->status == 1) {
  1622. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1623. }
  1624. }
  1625. print '</td>';
  1626. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1627. print '</tr></table>' . "\n";
  1628. // Presents the iLM
  1629. print '<table width=100% border=0 valign="top">' . "\n";
  1630. print '<td width=80% align="left">';
  1631. 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\".
  1632. print '<td width=20% align="rigth">';
  1633. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  1634. print $repeat; // symbol of "redo activity"
  1635. print '</td></tr></table>' . "\n";
  1636. //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)'
  1637. $output = '';
  1638. if (!$iassign_ilm) {
  1639. $iassign_ilm = new stdClass();
  1640. $iassign_ilm->file_jar = "";
  1641. }
  1642. $output .= $OUTPUT->box_start();
  1643. $USER->iassignEdit = $this->bottonPost;
  1644. // ---
  1645. // Presents the iLM
  1646. // Prepare tags to present the iLM
  1647. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  1648. $student_answer = ""; //?
  1649. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  1650. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  1651. $student_answer = "";
  1652. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  1653. } else {
  1654. // When student is redoing his activity
  1655. // ATTENTION: exception used by iGeom (exercise with "script")
  1656. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  1657. if (substr($ilm_name, 0, 5)=="igeom") {
  1658. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1659. $loadTeacherActivity = true;
  1660. }
  1661. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  1662. }
  1663. if ($iassign_statement_activity_item->type_iassign == 3) {
  1664. $history_comment = '';
  1665. if ($iassign_submission) {
  1666. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1667. }
  1668. if (!empty($history_comment)) {
  1669. $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  1670. " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  1671. $output .= $history_comment;
  1672. $output .= "</table>\n";
  1673. }
  1674. $output .= "</form></center>\n";
  1675. $output .= $OUTPUT->box_end();
  1676. print $output;
  1677. } else { // if ($iassign_statement_activity_item->type_iassign == 3)
  1678. $output .= $OUTPUT->box_end();
  1679. print $output;
  1680. }
  1681. } // if ($this->view_iassign)
  1682. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  1683. } // if ($this->view_iassign)
  1684. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1685. else
  1686. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1687. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  1688. print '<table width=100% border=0 valign="top">' . "\n";
  1689. print '<tr><td width=60% valign="top">' . "\n";
  1690. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1691. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1692. print '</tr></table>' . "\n";
  1693. $student_answer = "";
  1694. $enderecoPOST = "";
  1695. // Prepare tags to present the iLM
  1696. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  1697. print $output;
  1698. }
  1699. // final block 'studant'
  1700. print $OUTPUT->footer();
  1701. die();
  1702. } // function view_iassign_current()
  1703. /// Export the data from performance report into CSV file format
  1704. function export_csv () {
  1705. global $USER, $CFG, $DB, $OUTPUT;
  1706. $str = "";
  1707. $fields = "student_id, student_name";
  1708. // Finding all iassign activities for the iassign:
  1709. $id = $this->cm->id;
  1710. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1711. $c = 1;
  1712. foreach ($iassign_list as $iassign) {
  1713. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  1714. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  1715. $c ++;
  1716. }
  1717. // Finding enrolled students:
  1718. $params = array('shortname' => 'student');
  1719. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  1720. $context = context_course::instance($this->course->id);
  1721. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1722. $students = $DB->get_records_sql(
  1723. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1724. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1725. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1726. foreach ($students as $student) {
  1727. $str .= $student->userid . ',';
  1728. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  1729. foreach ($iassign_list as $iassign) {
  1730. $str .= ',' . $iassign->id . ',';
  1731. $str .= '"' . $iassign->name . '",';
  1732. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  1733. $str .= $student_submissions->experiment . ',';
  1734. $str .= $student_submissions->grade . ',';
  1735. switch ($student_submissions->status) {
  1736. case 3:
  1737. $str .= '"correct",';
  1738. break;
  1739. case 2:
  1740. $str .= '"incorrect",';
  1741. break;
  1742. case 1:
  1743. $str .= '"post",';
  1744. break;
  1745. case 0:
  1746. $str .= '"not_post",';
  1747. break;
  1748. }
  1749. $str .= $iassign->iassign_ilmid . ',';
  1750. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  1751. $str .= '"' . $ilm_activity->name . '"';
  1752. }
  1753. $str .= "\n";
  1754. }
  1755. $str = $fields . "\n" . $str;
  1756. header("Content-disposition: attachment; filename=report.csv");
  1757. header("Pragma: no-cache");
  1758. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  1759. header('Content-Length: ' . strlen($str));
  1760. header('Connection: close');
  1761. print $str;
  1762. flush();
  1763. } // function export_csv()
  1764. /// Display report of performance
  1765. function report () {
  1766. global $USER, $CFG, $DB, $OUTPUT;
  1767. $id = $this->cm->id;
  1768. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1769. if ($this->action != 'print') {
  1770. $title = get_string('report', 'iassign');
  1771. print $OUTPUT->header();
  1772. } // if ($this->action != 'print')
  1773. print $OUTPUT->box_start();
  1774. $this->view_legend_icons();
  1775. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  1776. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  1777. print $OUTPUT->box_end();
  1778. if ($this->action == 'print')
  1779. print '<table border=1 width="100%">' . "\n";
  1780. else
  1781. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1782. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  1783. // $num = array();
  1784. $i = 1;
  1785. $num = array();
  1786. foreach ($iassign_list as $iassign) {
  1787. $test_exercise = "";
  1788. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  1789. if (($iassign_submission) && $iassign->type_iassign < 3) {
  1790. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  1791. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  1792. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  1793. $num[$i] = new stdClass();
  1794. $num[$i]->name = $iassign->name;
  1795. $num[$i]->id = $i;
  1796. $num[$i]->iassignid = $iassign->id;
  1797. print ' <tr >' . "\n";
  1798. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  1799. print "<td class=\"cell c0 actvity\">";
  1800. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  1801. print ' </tr>' . "\n";
  1802. $i ++;
  1803. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  1804. } // foreach ($iassign_list as $iassign)
  1805. print "</table>";
  1806. print "<p></p>";
  1807. if ($this->action == 'print')
  1808. print '<table border=1 width="100%">' . "\n";
  1809. else
  1810. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1811. $context = context_course::instance($this->course->id);
  1812. if ($i > 1) {
  1813. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  1814. $params = array('shortname' => 'student');
  1815. $role = $DB->get_record_sql(
  1816. "SELECT s.id, s.shortname FROM {role} s " .
  1817. " WHERE s.shortname = :shortname", $params);
  1818. // $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");
  1819. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1820. $students = $DB->get_records_sql(
  1821. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1822. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1823. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1824. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  1825. for ($j = 1; $j < $i; $j ++) {
  1826. $sum_iassign_correct[$j] = 0;
  1827. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  1828. }
  1829. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  1830. $sum_iassign = $j - 1;
  1831. print '</tr>' . "\n";
  1832. $total = 0;
  1833. $sum_student = 0;
  1834. $comment = iassign_icons::insert('comment_read');
  1835. $sum_comment = 0;
  1836. $sum_correct_iassign = array();
  1837. $sum_correct_student = array();
  1838. $USER->matrix_iassign = array();
  1839. if ($students) {
  1840. $w = 0;
  1841. foreach ($students as $tmp) {
  1842. $users_array[$w] = $tmp;
  1843. $w ++;
  1844. }
  1845. for ($x = 0; $x < $w; $x ++) {
  1846. print '<tr>' . "\n";
  1847. $sum_student ++;
  1848. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  1849. print ' <td >' . $name . '</td>' . "\n";
  1850. $total_student = 0;
  1851. $tentativas = 0;
  1852. for ($j = 1; $j < $i; $j ++) {
  1853. $sum_comment = 0;
  1854. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  1855. print ' <td valign="bottom" align="center">' . "\n";
  1856. if ($student_submissions) {
  1857. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  1858. $tentativas = $student_submissions->experiment;
  1859. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  1860. $params = array('iassign_submissionid' => $student_submissions->id);
  1861. $student_submissions_comment = $DB->get_record_sql(
  1862. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1863. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  1864. if ($student_submissions_comment)
  1865. foreach ($student_submissions_comment as $tmp)
  1866. $sum_comment = $tmp;
  1867. // informations to previous activities
  1868. if ($j - 1 < 1 || $j == $i)
  1869. $iassign_previous = "-1";
  1870. else
  1871. $iassign_previous = $num[$j - 1]->iassignid;
  1872. if ($x - 1 < 0 || $x == $w)
  1873. $user_previous = "-1";
  1874. else
  1875. $user_previous = $users_array[$x - 1]->userid;
  1876. // next
  1877. if ($i - 1 > $j)
  1878. $iassign_next = $num[$j + 1]->iassignid;
  1879. else
  1880. $iassign_next = "-1";
  1881. if ($w - 1 > $x)
  1882. $user_next = $users_array[$x + 1]->userid;
  1883. else
  1884. $user_next = "-1";
  1885. $position = "&row= $x&column=$j";
  1886. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  1887. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1888. $url .= $position;
  1889. // receiver=1 - message to teacher
  1890. // receiver=2 - message to student
  1891. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  1892. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  1893. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  1894. $verify_message = $DB->get_record_sql(
  1895. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1896. "WHERE iassign_submissionid = :iassign_submissionid " .
  1897. " AND return_status= :return_status " .
  1898. " AND receiver= :receiver", $params);
  1899. if ($verify_message)
  1900. foreach ($verify_message as $tmp)
  1901. $sum_verify_message = $tmp;
  1902. if ($sum_verify_message > 0)
  1903. $comment = iassign_icons::insert('comment_unread');
  1904. else
  1905. $comment = iassign_icons::insert('comment_read');
  1906. if ($student_submissions->status == 3) {
  1907. $sum_iassign_correct[$j] ++;
  1908. $total_student ++;
  1909. $feedback = iassign_icons::insert('correct');
  1910. }
  1911. elseif ($student_submissions->status == 2) {
  1912. $feedback = iassign_icons::insert('incorrect');
  1913. }
  1914. elseif ($student_submissions->status == 1) {
  1915. $feedback = iassign_icons::insert('post');
  1916. }
  1917. elseif ($student_submissions->status == 0) {
  1918. $feedback = iassign_icons::insert('not_post');
  1919. }
  1920. if ($this->action != 'print') {
  1921. print '<table><tr>';
  1922. if ($tentativas > 0)
  1923. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  1924. else
  1925. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  1926. print '<td> &nbsp; </td>';
  1927. print '</tr>' . "\n";
  1928. if ($sum_comment > 0 && $sum_verify_message > 0)
  1929. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  1930. else if ($sum_comment > 0)
  1931. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  1932. print '</table>' . "\n";
  1933. }
  1934. if ($this->action == 'print')
  1935. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1936. } // if ($student_submissions)
  1937. else { // if ($student_submissions)
  1938. // informations to browse previous activities
  1939. if ($j - 1 < 1 || $j == $i)
  1940. $iassign_previous = "-1";
  1941. else
  1942. $iassign_previous = $num[$j - 1]->iassignid;
  1943. if ($x - 1 < 0 || $x == $w)
  1944. $user_previous = "-1";
  1945. else
  1946. $user_previous = $users_array[$x - 1]->userid;
  1947. // next
  1948. if ($i - 1 > $j)
  1949. $iassign_next = $num[$j + 1]->iassignid;
  1950. else
  1951. $iassign_next = "-1";
  1952. if ($w - 1 > $x)
  1953. $user_next = $users_array[$x + 1]->userid;
  1954. else
  1955. $user_next = "-1";
  1956. $position = "&row= $x&column=$j";
  1957. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  1958. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1959. $url .= $position;
  1960. $feedback = iassign_icons::insert('not_post');
  1961. if ($this->action == 'print')
  1962. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1963. else {
  1964. print '<table><tr>';
  1965. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  1966. print '<td> &nbsp; </td>';
  1967. print '</tr><tr>' . "\n";
  1968. print '<td> &nbsp;</td>';
  1969. if ($sum_comment > 0)
  1970. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  1971. else
  1972. print '<td> &nbsp;</td>';
  1973. print '</tr></table>';
  1974. }
  1975. } // else if ($student_submissions)
  1976. $USER->matrix_iassign[$x][$j] = new stdClass();
  1977. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  1978. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  1979. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  1980. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  1981. if ($student_submissions)
  1982. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  1983. else
  1984. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  1985. print '</td>' . "\n";
  1986. } // for ($j=1; $j<$i; $j++)
  1987. $total = $total + $total_student;
  1988. $porcentagem = ($total_student / ($j - 1)) * 100;
  1989. if ($tentativas != 0 && $tentativas != null) {
  1990. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  1991. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  1992. }
  1993. else {
  1994. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  1995. }
  1996. print '</tr>' . "\n";
  1997. $sum_correct_student[$sum_student] = new stdClass();
  1998. $sum_correct_student[$sum_student]->name = $name;
  1999. $sum_correct_student[$sum_student]->sum = $total_student;
  2000. } // for ($x = 0; $x < $w; $x ++)
  2001. for ($i = 1; $i < $j; $i ++) {
  2002. if (is_null($sum_iassign_correct[$i]))
  2003. $sum_iassign_correct[$i] = 0;
  2004. $sum_correct_iassign[$i] = new stdClass();
  2005. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2006. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2007. }
  2008. // print '</tr></table>' . "\n";
  2009. }
  2010. } // if ($i>1)
  2011. else {
  2012. print_string('no_activity', 'iassign');
  2013. }
  2014. print "</table>\n";
  2015. if ($this->action != 'print')
  2016. print $OUTPUT->footer();
  2017. die();
  2018. } // function report()
  2019. /// Display graphics of performance
  2020. function stats () {
  2021. global $USER, $CFG, $DB, $OUTPUT;
  2022. $id = $this->cm->id;
  2023. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2024. if ($this->action != 'printstats')
  2025. $title = get_string('graphic', 'iassign');
  2026. $num = array();
  2027. $sum_correct_iassign = array();
  2028. $sum_correct_student = array();
  2029. $sum_student = 0;
  2030. $i = 1;
  2031. foreach ($iassign_list as $iassign) {
  2032. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2033. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2034. $sum_iassign_correct[$i] = 0;
  2035. $num[$i] = new stdClass();
  2036. $num[$i]->name = $iassign->name;
  2037. $num[$i]->id = $i;
  2038. $num[$i]->iassignid = $iassign->id;
  2039. $i ++;
  2040. } // if ($iassign->type_iassign == 3)
  2041. } // foreach ($iassign_list as $iassign)
  2042. $sum_iassign = $i - 1;
  2043. $context = context_course::instance($this->course->id);
  2044. if ($i > 1) {
  2045. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2046. $params = array('shortname' => 'student');
  2047. $role = $DB->get_record_sql(
  2048. "SELECT s.id, s.shortname FROM {role} s " .
  2049. " WHERE s.shortname = :shortname", $params);
  2050. // $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");
  2051. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2052. $students = $DB->get_records_sql(
  2053. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2054. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2055. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2056. $total = 0;
  2057. $sum_student = 0;
  2058. $j = 0;
  2059. $sum_correct_iassign = array();
  2060. $sum_correct_student = array();
  2061. $sum_experiment = array();
  2062. if ($students) {
  2063. foreach ($students as $users) {
  2064. $sum_student ++;
  2065. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2066. // rows
  2067. $total_student = 0;
  2068. for ($j = 1; $j < $i; $j ++) {
  2069. $total_experiment = 0;
  2070. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2071. if ($student_submissions) {
  2072. if ($student_submissions->status == 3) {
  2073. $sum_iassign_correct[$j] ++;
  2074. $total_student ++;
  2075. } // if ($student_submissions->status == 3)
  2076. $total_experiment += $student_submissions->experiment;
  2077. }
  2078. $sum_experiment[$j] = $total_experiment;
  2079. } // for ($j=1; $j<$i; $j++)
  2080. $total = $total + $total_student;
  2081. $sum_correct_student[$sum_student] = new stdClass();
  2082. $sum_correct_student[$sum_student]->name = $name;
  2083. $sum_correct_student[$sum_student]->sum = $total_student;
  2084. } // foreach ($students as $users)
  2085. }
  2086. for ($i = 1; $i < $j; $i ++) {
  2087. if (is_null($sum_iassign_correct[$i]))
  2088. $sum_iassign_correct[$i] = 0;
  2089. $sum_correct_iassign[$i] = new stdClass();
  2090. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2091. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2092. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2093. } // for ($i = 1; $i < $j; $i++)
  2094. } // if ($i > 1)
  2095. if ($this->action != 'printstats') {
  2096. $title = get_string('graphic', 'iassign');
  2097. print $OUTPUT->header();
  2098. $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>";
  2099. $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>";
  2100. print '<table width=100%><tr>';
  2101. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2102. print '<td width=15% align="right">' . $link_report . '</td>';
  2103. print '</td></tr></table>' . "\n";
  2104. print "<br><br>";
  2105. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2106. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2107. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2108. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2109. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2110. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2111. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2112. print '</tr>' . "\n";
  2113. $sum_correct = 0;
  2114. if ($sum_correct_iassign) {
  2115. foreach ($sum_correct_iassign as $iassign) {
  2116. if (is_null($iassign->experiment))
  2117. $iassign->experiment = 0;
  2118. $bar = "";
  2119. $sum = $iassign->sum;
  2120. $percent = ($sum / $sum_student) * 100;
  2121. $text = number_format($percent, 1) . '%';
  2122. $sum_correct += $sum;
  2123. if ($sum > 0) {
  2124. for ($i = 1; $i < $percent * 2; $i ++)
  2125. $bar .= iassign_icons::insert('hbar_blue');
  2126. $bar .= iassign_icons::insert('hbar_blue_r');
  2127. } // if ($sum > 0)
  2128. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2129. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2130. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2131. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2132. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2133. print '</tr>' . "\n";
  2134. } // foreach ($sum_correct_iassign as $iassign)
  2135. }
  2136. print "</table>";
  2137. print "<br><br>";
  2138. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2139. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2140. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2141. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2142. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2143. print '</tr>' . "\n";
  2144. $sum_correct = 0;
  2145. foreach ($sum_correct_student as $student) {
  2146. $bar = "";
  2147. $sum = $student->sum;
  2148. $percent = ($sum / $sum_iassign) * 100;
  2149. $text = number_format($percent, 1) . '%';
  2150. $sum_correct += $sum;
  2151. if ($sum > 0) {
  2152. for ($i = 1; $i < $percent * 2; $i ++)
  2153. $bar .= iassign_icons::insert('hbar_blue');
  2154. $bar .= iassign_icons::insert('hbar_blue_r');
  2155. } // if ($sum > 0)
  2156. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2157. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2158. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2159. print '</tr>' . "\n";
  2160. } // foreach ($sum_correct_student as $student)
  2161. print "</table>\n";
  2162. print "<br><br>\n";
  2163. $var = 0;
  2164. $cv = 0;
  2165. $dv = 0;
  2166. $avg = 0;
  2167. if ($sum_correct_student) {
  2168. $avg = $sum_correct / $sum_student;
  2169. if ($avg > 0) {
  2170. foreach ($sum_correct_student as $student)
  2171. $var += pow($student->sum - $avg, 2);
  2172. $var = $var / $sum_student;
  2173. $dv = sqrt($var);
  2174. $cv = ($dv / $avg) * 100;
  2175. }
  2176. }
  2177. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2178. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2179. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2180. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2181. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2182. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2183. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2184. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2185. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2186. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2187. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2188. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2189. print "</table>\n";
  2190. print $OUTPUT->footer();
  2191. } else {
  2192. print "<STYLE TYPE='text/css'>
  2193. <!--
  2194. .boldtable {
  2195. font-family:sans-serif;
  2196. font-size:10pt;
  2197. }
  2198. -->
  2199. </STYLE>\n";
  2200. print '<table border=1 width=100%>' . "\n";
  2201. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2202. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2203. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2204. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2205. print '</tr>' . "\n";
  2206. $sum_correct = 0;
  2207. foreach ($sum_correct_iassign as $iassign) {
  2208. $bar = "";
  2209. $sum = $iassign->sum;
  2210. $percent = ($sum / $sum_student) * 100;
  2211. $text = number_format($percent, 1) . '%';
  2212. $sum_correct += $sum;
  2213. if ($sum > 0) {
  2214. for ($i = 1; $i < $percent * 2; $i ++)
  2215. $bar .= iassign_icons::insert('hbar_blue');
  2216. $bar .= iassign_icons::insert('hbar_blue_r');
  2217. } // if ($sum > 0)
  2218. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2219. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2220. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2221. print '</tr>' . "\n";
  2222. } // foreach ($sum_correct_iassign as $iassign)
  2223. print "</table>";
  2224. print "<br><br>";
  2225. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2226. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2227. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2228. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2229. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2230. print '</tr>' . "\n";
  2231. $sum_correct = 0;
  2232. foreach ($sum_correct_student as $student) {
  2233. $bar = "";
  2234. $sum = $student->sum;
  2235. $percent = ($sum / $sum_iassign) * 100;
  2236. $text = number_format($percent, 1) . '%';
  2237. $sum_correct += $sum;
  2238. if ($sum > 0) {
  2239. for ($i = 1; $i < $percent * 2; $i ++)
  2240. $bar .= iassign_icons::insert('hbar_blue');
  2241. $bar .= iassign_icons::insert('hbar_blue_r');
  2242. } // if ($sum > 0)
  2243. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2244. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2245. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2246. print '</tr>' . "\n";
  2247. } // foreach ($sum_correct_student as $student)
  2248. print "</table>\n";
  2249. print "<br/><br/>\n";
  2250. $var = 0;
  2251. $cv = 0;
  2252. $dv = 0;
  2253. $avg = 0;
  2254. if ($sum_correct_student) {
  2255. $avg = $sum_correct / $sum_student;
  2256. if ($avg > 0) {
  2257. foreach ($sum_correct_student as $student)
  2258. $var += pow($student->sum - $avg, 2);
  2259. $var = $var / $sum_student;
  2260. $dv = sqrt($var);
  2261. $cv = ($dv / $avg) * 100;
  2262. }
  2263. }
  2264. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2265. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2266. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2267. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2268. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2269. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2270. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2271. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2272. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2273. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2274. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2275. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2276. print "</table>\n";
  2277. } // if ($this->action != 'printstats')
  2278. die();
  2279. }
  2280. /// Display graphics of performance for students
  2281. function stats_students () {
  2282. global $USER, $CFG, $DB, $OUTPUT;
  2283. $id = $this->cm->id;
  2284. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2285. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2286. $title = get_string('results', 'iassign');
  2287. $sum_correct = 0;
  2288. $sum_incorrect = 0;
  2289. $sum_post = 0;
  2290. $sum_nopost = 0;
  2291. $sum_iassign = count($iassign_statement_list);
  2292. $bar_nopost = "";
  2293. $bar_correct = "";
  2294. $bar_incorrect = "";
  2295. $bar_post = "";
  2296. $text_nopost = "";
  2297. $text_correct = "";
  2298. $text_incorrect = "";
  2299. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2300. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2301. if ($iassign_submission) {
  2302. if ($iassign_submission->status == 3)
  2303. $sum_correct ++;
  2304. elseif ($iassign_submission->status == 2)
  2305. $sum_incorrect ++;
  2306. elseif ($iassign_submission->status == 1)
  2307. $sum_post ++;
  2308. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2309. $sum_nopost ++;
  2310. } // if ($iassign_submission)
  2311. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2312. if ($sum_iassign > 0) {
  2313. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2314. $text_correct = number_format($percent_correct, 1) . '%';
  2315. }
  2316. if ($sum_correct > 0) {
  2317. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2318. $bar_correct .= iassign_icons::insert('hbar_green');
  2319. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2320. } // if ($sum_correct > 0)
  2321. if ($sum_iassign > 0) {
  2322. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2323. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2324. }
  2325. if ($sum_incorrect > 0) {
  2326. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2327. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2328. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2329. } // if ($sum_incorrect > 0)
  2330. if ($sum_iassign > 0) {
  2331. $percent_post = ($sum_post / $sum_iassign) * 100;
  2332. $text_post = number_format($percent_post, 1) . '%';
  2333. }
  2334. if ($sum_post > 0) {
  2335. for ($i = 1; $i < $percent_post * 2; $i ++)
  2336. $bar_post .= iassign_icons::insert('hbar_blue');
  2337. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2338. } // if ($sum_post > 0)
  2339. if ($sum_iassign > 0) {
  2340. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2341. $text_nopost = number_format($percent_nopost, 1) . '%';
  2342. }
  2343. if ($sum_nopost > 0) {
  2344. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2345. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2346. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2347. } // if ($sum_nopost > 0)
  2348. print $OUTPUT->header();
  2349. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2350. print '<table width=100%><tr>';
  2351. print '<td align="right">' . $link_return . '</td>' . "\n";
  2352. print '</td></tr></table>' . "\n";
  2353. print "<br/><br/>\n";
  2354. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2355. print '<tr><th colspan=3 class="header c1">' . "\n";
  2356. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2357. // $imagetext = '');
  2358. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2359. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2360. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2361. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2362. print '</tr>' . "\n";
  2363. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2364. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2365. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2366. print '</tr>' . "\n";
  2367. if ($sum_post) {
  2368. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2369. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2370. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2371. print '</tr>' . "\n";
  2372. } // if ($sum_post)
  2373. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2374. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2375. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2376. print '</tr>' . "\n";
  2377. print "</table>";
  2378. print "<br><br>";
  2379. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2380. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2381. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2382. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2383. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2384. $sum_grade = 0;
  2385. $sum_grade_student = 0;
  2386. $avg = 0;
  2387. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2388. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2389. if (!$iassign_submission) {
  2390. $iassign_submission = new stdClass();
  2391. $iassign_submission->grade = 0;
  2392. }
  2393. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2394. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2395. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2396. print '</tr>' . "\n";
  2397. $sum_grade += $iassign_statement_activity_item->grade;
  2398. $sum_grade_student += $iassign_submission->grade;
  2399. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2400. if ($sum_grade > 0)
  2401. $avg = $sum_grade_student / $sum_grade * 100;
  2402. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2403. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2404. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2405. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2406. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2407. print "</table>";
  2408. print $OUTPUT->footer();
  2409. die();
  2410. } // function stats_students()
  2411. /// Display page of iAssign's activity
  2412. function view_iassigns () {
  2413. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2414. $id = $this->cm->id;
  2415. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2416. $notice = optional_param('notice', '', PARAM_TEXT);
  2417. if (strpos($notice, 'error'))
  2418. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2419. else if ($notice != '')
  2420. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2421. print $OUTPUT->box_start();
  2422. print '<table width=100% border=0><tr>' . "\n";
  2423. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2424. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2425. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2426. $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>";
  2427. $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>";
  2428. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2429. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2430. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2431. // Has capability to see "report": teacher or up
  2432. print '<td width=10% align="left">' . "\n";
  2433. print $link_help;
  2434. print '</td>' . "\n";
  2435. print '<td width=10% align="left">' . "\n";
  2436. print $link_report;
  2437. print '</td>' . "\n";
  2438. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2439. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2440. print '<td width=15% align="left">' . "\n";
  2441. print $link_add;
  2442. print "</td>\n";
  2443. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2444. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2445. if ($iassign_list) {
  2446. print '<td align="right">' . "\n";
  2447. // $USER->iassignEdit == 0 view 'Turn editing off'
  2448. // $USER->iassignEdit == 1 view 'Turn editing on'
  2449. if (!isset($USER->iassignEdit))
  2450. $USER->iassignEdit = 0;
  2451. if ($USER->iassignEdit == 0) {
  2452. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2453. $botton = 1;
  2454. } // if ($USER->iassignEdit == 0)
  2455. elseif ($USER->iassignEdit == 1) {
  2456. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2457. $botton = 0;
  2458. } // elseif ($USER->iassignEdit == 1)
  2459. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2460. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2461. print " <input type=submit value='$bottonEdit_message'/>\n";
  2462. print "</form>\n";
  2463. print "</td>\n";
  2464. } // if ($iassign_list)
  2465. }
  2466. print '</tr></table>' . "\n";
  2467. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2468. $this->view_legend_icons();
  2469. print $OUTPUT->box_end();
  2470. $iassign_array_exercise = array();
  2471. $i_exercise = 0;
  2472. $iassign_array_test = array();
  2473. $i_test = 0;
  2474. $iassign_array_example = array();
  2475. $i_example = 0;
  2476. $iassign_array_general = array();
  2477. $i_general = 0;
  2478. if ($iassign_list) {
  2479. if ($this->iassign->activity_group == 0) {
  2480. foreach ($iassign_list as $iassign) {
  2481. $iassign_array_general[$i_general] = $iassign;
  2482. $i_general ++;
  2483. }
  2484. } // if ($this->iassign->activity_group == 0)
  2485. else {
  2486. foreach ($iassign_list as $iassign) {
  2487. if ($iassign->type_iassign == 3) {
  2488. $iassign_array_exercise[$i_exercise] = $iassign;
  2489. $i_exercise ++;
  2490. } // if ($iassign->type_iassign == 3)
  2491. if ($iassign->type_iassign == 2) {
  2492. $iassign_array_test[$i_test] = $iassign;
  2493. $i_test ++;
  2494. } // if ($iassign->type_iassign == 2)
  2495. if ($iassign->type_iassign == 1) {
  2496. $iassign_array_example[$i_example] = $iassign;
  2497. $i_example ++;
  2498. } // if ($iassign->type_iassign == 1)
  2499. }
  2500. }
  2501. if ($iassign_array_exercise) {
  2502. $title = get_string('exercise', 'iassign');
  2503. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2504. }
  2505. if ($iassign_array_test) {
  2506. $title = get_string('test', 'iassign');
  2507. $this->show_iassign($title, $iassign_array_test, $i_test);
  2508. }
  2509. if ($iassign_array_example) {
  2510. $title = get_string('example', 'iassign');
  2511. $this->show_iassign($title, $iassign_array_example, $i_example);
  2512. }
  2513. if ($iassign_array_general) {
  2514. $title = "";
  2515. $this->show_iassign($title, $iassign_array_general, $i_general);
  2516. }
  2517. } else { // if ($iassign_list)
  2518. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2519. }
  2520. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2521. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2522. print $OUTPUT->box_start();
  2523. print '<table width=100% border=0><tr>' . "\n";
  2524. print '<td width=10% align="left">' . "\n";
  2525. print $link_report;
  2526. print '</td>' . "\n";
  2527. print '</tr></table>' . "\n";
  2528. print $OUTPUT->box_end();
  2529. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2530. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2531. print $OUTPUT->box_start();
  2532. print '<table width=100% border=0><tr>' . "\n";
  2533. print '<td align="left">' . "\n";
  2534. print $link_add;
  2535. print '</td>' . "\n";
  2536. print '</tr></table>' . "\n";
  2537. print $OUTPUT->box_end();
  2538. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2539. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2540. } // function view_iassigns()
  2541. /// Display all iAssigns
  2542. function show_iassign ($title, $iassign_array, $i) {
  2543. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  2544. $id = $this->cm->id;
  2545. print $OUTPUT->box_start();
  2546. print " <script type='text/javascript'>
  2547. //<![CDATA[
  2548. function validate_move () {
  2549. var radios = document.getElementsByName('iassign_destiny');
  2550. var formValid = false;
  2551. //alert('aqui validate_move()');
  2552. var i = 0;
  2553. while (!formValid && i < radios.length) {
  2554. if (radios[i].checked) formValid = true;
  2555. i++;
  2556. }
  2557. if (!formValid) {
  2558. document.getElementById('move_dest').classList.add('alert-danger');
  2559. }
  2560. return formValid;
  2561. }
  2562. var modal;
  2563. function load_move(id_ias) {
  2564. document.form_move_activity.iassign_current.value = id_ias;
  2565. modal.style.display = 'block';
  2566. var radios = document.getElementsByName('iassign_destiny');
  2567. var i = 0;
  2568. while (i < radios.length) {
  2569. radios[i].checked = false;
  2570. i++;
  2571. }
  2572. document.getElementById('move_dest').classList.remove('alert-danger');
  2573. }
  2574. function load_modal_elements() {
  2575. modal = document.getElementById('myModal');
  2576. var span = document.getElementById('close_modal');
  2577. span.onclick = function() {
  2578. modal.style.display = 'none';
  2579. }
  2580. window.onclick = function(event) {
  2581. if (event.target == modal) {
  2582. modal.style.display = 'none';
  2583. }
  2584. }
  2585. }
  2586. window.onload = load_modal_elements;
  2587. //]]>
  2588. </script>\n";
  2589. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  2590. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  2591. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  2592. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  2593. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  2594. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  2595. <input type='hidden' name='iassign_current' value='' />";
  2596. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  2597. $section = $course_sections[0];
  2598. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  2599. for ($k = 0; $k < count($ids_sections); $k++) {
  2600. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  2601. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  2602. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  2603. if ($c_cm) {
  2604. if ($ccm->instance == $c_cm->instance) {
  2605. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2606. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2607. }
  2608. else {
  2609. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2610. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2611. }
  2612. }
  2613. }
  2614. $radio_buttons .= "</ul>";
  2615. }
  2616. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  2617. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  2618. </form>
  2619. </div></div> </div></div>\n";
  2620. print " <style>.modal {
  2621. display: none;
  2622. position: fixed;
  2623. z-index: 1;
  2624. left: 0;
  2625. top: 0;
  2626. width: 100%;
  2627. height: 100%;
  2628. overflow: scroll;
  2629. background-color: rgb(0,0,0);
  2630. background-color: rgba(0,0,0,0.4);
  2631. }
  2632. .modal-content {
  2633. background-color: #fefefe;
  2634. margin: 15% auto;
  2635. padding: 10px 10px;
  2636. border: 1px solid #888;
  2637. width: 50%;
  2638. }
  2639. #close_modal {
  2640. color: #aaa;
  2641. float: right;
  2642. font-size: 28px;
  2643. font-weight: bold;
  2644. margin-top: -15px;
  2645. margin-right: -3px;
  2646. }
  2647. #close_modal:hover,
  2648. #close_modal:focus {
  2649. color: black;
  2650. text-decoration: none;
  2651. cursor: pointer;
  2652. }
  2653. #modal_title {
  2654. min-height: 3rem;
  2655. color: initial;
  2656. background: initial;
  2657. font-size: 1.5rem;
  2658. line-height: 1.5;
  2659. padding: 15px;
  2660. border-bottom: 1px solid #e5e5e5;
  2661. }
  2662. .input_move {
  2663. width: 90%;
  2664. padding: 2px;
  2665. }
  2666. .input_move:hover {
  2667. background: #eff0ef;
  2668. }
  2669. </style>";
  2670. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2671. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  2672. for ($j = 0; $j < $i; $j ++) {
  2673. $iassign_current = $iassign_array[$j]->id;
  2674. // receiver=1 - message to teacher
  2675. // receiver=2 - message to student
  2676. $sum_comment = 0;
  2677. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  2678. foreach ($iassign_submissions as $iassign_submission) {
  2679. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  2680. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2681. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2682. if ($verify_message)
  2683. foreach ($verify_message as $tmp)
  2684. $sum_comment += $tmp;
  2685. } // foreach ($iassign_submissions as $iassign_submission)
  2686. if ($sum_comment == 0)
  2687. $comment_unread = "";
  2688. else {
  2689. $comment_unread_message = get_string('comment_unread', 'iassign');
  2690. if ($sum_comment == 1)
  2691. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2692. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  2693. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  2694. }
  2695. if ($j == $i - 1)
  2696. $iassign_down = $iassign_array[$j]->id;
  2697. else
  2698. $iassign_down = $iassign_array[$j + 1]->id;
  2699. if ($j > 0)
  2700. $iassign_up = $iassign_array[$j - 1]->id;
  2701. else
  2702. $iassign_up = $iassign_array[$j]->id;
  2703. if ($iassign_array[$j]->visible == 0)
  2704. $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>";
  2705. else
  2706. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2707. $links .= $comment_unread;
  2708. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  2709. $aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  2710. $link_up = "&nbsp;<a href='view.php?action=up$aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  2711. $link_down = "&nbsp;<a href='view.php?action=down$aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2712. $link_delete = "&nbsp;<a href='view.php?action=delete$aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  2713. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  2714. $link_visible_show = "&nbsp;<a href='view.php?action=visible$aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  2715. $link_edit = "&nbsp;<a href='view.php?action=edit$aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  2716. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  2717. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  2718. if (count($iassign_array) > 1) {
  2719. if ($j == 0)
  2720. $links .= $link_down;
  2721. elseif ($j == $i - 1)
  2722. $links .= $link_up;
  2723. else
  2724. $links .= $link_up . $link_down;
  2725. } // if (count($iassign_array) > 1)
  2726. $links .= $link_edit . $link_delete;
  2727. if ($iassign_array[$j]->visible == 0)
  2728. $links .= $link_visible_show;
  2729. else
  2730. $links .= $link_visible_hide;
  2731. $links .= $link_duplicate_activity . $link_move_activity;
  2732. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2733. print '<p>' . $links . '</p>' . "\n";
  2734. }
  2735. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2736. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  2737. print '<table width=100% ><tr>' . "\n";
  2738. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2739. print '</tr></table>' . "\n";
  2740. for ($j = 0; $j < $i; $j ++) {
  2741. $icon_status = "";
  2742. $icon_comment = "";
  2743. if ($iassign_array[$j]->visible == 1) {
  2744. $iassign_current = $iassign_array[$j]->id;
  2745. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  2746. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2747. $icon_status = "";
  2748. $icon_comment = "";
  2749. if ($iassign_submission) {
  2750. // receiver=1 - message to teacher
  2751. // receiver=2 - message to student
  2752. // $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");
  2753. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  2754. $verify_message = $DB->get_record_sql(
  2755. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2756. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2757. if ($verify_message)
  2758. foreach ($verify_message as $tmp)
  2759. $sum_comment = $tmp;
  2760. if ($sum_comment > 0) {
  2761. $comment_unread_message = get_string('comment_unread', 'iassign');
  2762. if ($sum_comment == 1)
  2763. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2764. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  2765. }
  2766. // $icon_comment = iassign_icons::insert('comment_unread');
  2767. if ($iassign_array[$j]->type_iassign == 3) {
  2768. if ($iassign_array[$j]->show_answer == 1) {
  2769. if ($iassign_submission->status == 3)
  2770. $icon_status = iassign_icons::insert('correct');
  2771. elseif ($iassign_submission->status == 2)
  2772. $icon_status = iassign_icons::insert('incorrect');
  2773. elseif ($iassign_submission->status == 1)
  2774. $icon_status = iassign_icons::insert('post');
  2775. elseif ($iassign_submission->status == 0)
  2776. $icon_status = iassign_icons::insert('not_post');
  2777. } // if ($iassign_array[$j]->show_answer==1)
  2778. else {
  2779. if ($iassign_submission->status == 0)
  2780. $icon_status = iassign_icons::insert('not_post');
  2781. else
  2782. $icon_status = iassign_icons::insert('post');
  2783. }
  2784. } // if ($iassign_array[$j]->type_iassign == 3)
  2785. } // if ($iassign_submission)
  2786. elseif ($iassign_array[$j]->type_iassign == 3) {
  2787. $icon_status = iassign_icons::insert('not_post');
  2788. } // if ($iassign_array[$j]->type_iassign == 3)
  2789. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  2790. } // if ($iassign_array[$j]->visible == 1)
  2791. } // for ($j = 0; $j < $i; $j++)
  2792. } else if (isguestuser()) {
  2793. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2794. print '<table width=100% ><tr>' . "\n";
  2795. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2796. print '</tr></table>' . "\n";
  2797. for ($j = 0; $j < $i; $j ++) {
  2798. $icon_status = "";
  2799. $icon_comment = "";
  2800. if ($iassign_array[$j]->visible == 1) {
  2801. $iassign_current = $iassign_array[$j]->id;
  2802. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2803. print '<p>' . $links . '</p>' . "\n";
  2804. } // if ($iassign_array[$j]->visible == 1)
  2805. }
  2806. }
  2807. print $OUTPUT->box_end();
  2808. } // function show_iassign($title, $iassign_array, $i)
  2809. /// Show message of return
  2810. function return_home_course ($message) {
  2811. //D global $DB, $OUTPUT;
  2812. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2813. //D echo $OUTPUT->box_start();
  2814. //D echo '<table width=100% border=0 valign="top">' . "\n";
  2815. //D echo '<tr><td align="left"><strong>' . "\n";
  2816. //D print_string($message, 'iassign');
  2817. //D echo '</strong></td>' . "\n";
  2818. //D echo '<td width=20% align="right">' . "\n";
  2819. //D echo $link_return;
  2820. //D echo '</td></tr></table>' . "\n";
  2821. //D echo $OUTPUT->box_end();
  2822. //D // echo $OUTPUT->footer();
  2823. redirect(new moodle_url($this->return . '&notice=' . $message));
  2824. exit;
  2825. }
  2826. /// Search comment of activity
  2827. function search_comment_submission ($iassign_submissionid) {
  2828. global $USER, $DB, $OUTPUT, $COURSE;
  2829. $context = context_course::instance($COURSE->id);
  2830. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  2831. $text = "";
  2832. if ($comments) {
  2833. foreach ($comments as $tmp) {
  2834. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  2835. if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  2836. $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2837. $text .= "$tmp->comment</td></tr>";
  2838. } else {
  2839. $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2840. $text .= $tmp->comment . "</td></tr>\n";
  2841. }
  2842. } // foreach ($comments as $tmp)
  2843. }
  2844. return $text;
  2845. }
  2846. /// Update comment of activity
  2847. function update_comment ($iassign_submissionid) {
  2848. global $USER, $DB, $OUTPUT;
  2849. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  2850. $receiver = 1; // student message to teacher
  2851. else
  2852. $receiver = 2; // teacher message to student
  2853. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  2854. if ($verify_message) {
  2855. foreach ($verify_message as $message) {
  2856. if ($message->receiver == $receiver) {
  2857. $newentry = new stdClass();
  2858. $newentry->id = $message->id;
  2859. $newentry->return_status = 1;
  2860. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  2861. print_error('error_update', 'iassign');
  2862. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  2863. } // if ($message->receiver == $receiver)
  2864. // Trigger module viewed event.
  2865. $event = \mod_iassign\event\submission_comment_updated::create(array(
  2866. 'objectid' => $this->iassign->id,
  2867. 'context' => $this->context
  2868. ));
  2869. $event->add_record_snapshot('course', $this->course);
  2870. $event->trigger();
  2871. } // foreach ($verify_message as $message)
  2872. }
  2873. }
  2874. /// Record comment of activity
  2875. function write_comment_submission () {
  2876. global $USER, $CFG, $DB;
  2877. $id = $this->cm->id;
  2878. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  2879. $row = optional_param('row', 0, PARAM_INT);
  2880. $column = optional_param('column', 0, PARAM_INT);
  2881. $sum_comment = 0;
  2882. $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);
  2883. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  2884. $str1 = trim($submission_comment);
  2885. $str2 = trim(get_string('box_comment_message', 'iassign'));
  2886. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  2887. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  2888. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  2889. $receiver = 1; // student message to teacher
  2890. $this->action = 'view';
  2891. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  2892. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  2893. } else {
  2894. $receiver = 2; // teacher message to student
  2895. $this->action = 'viewsubmission';
  2896. //D $tousers = array(); //MOOC 2016
  2897. //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
  2898. }
  2899. //MOOC 2016: foi p/ 15 linhas acima:
  2900. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  2901. if (!$iassign_submission) {
  2902. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  2903. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  2904. $this->iassign_submission_current = $id_submission;
  2905. } else {
  2906. $id_submission = $iassign_submission->id;
  2907. } // if (!$iassign_submission)
  2908. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  2909. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  2910. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  2911. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  2912. $comments = $DB->get_record_sql(
  2913. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2914. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  2915. if ($comments)
  2916. foreach ($comments as $tmp)
  2917. $sum_comment = $tmp;
  2918. if ($sum_comment == 0) {
  2919. $newentry = new stdClass();
  2920. $newentry->iassign_submissionid = $id_submission;
  2921. $newentry->comment_authorid = $USER->id;
  2922. $newentry->timecreated = time();
  2923. $newentry->comment = $submission_comment;
  2924. $newentry->receiver = $receiver;
  2925. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  2926. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  2927. //T $eventdata = new stdClass();
  2928. //T $eventdata->component = 'mod_iassign'; //your component name
  2929. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  2930. //T $eventdata->userfrom = $USER;
  2931. //T $eventdata->userto = $touser;
  2932. //T $eventdata->subject = "Teste de Subject";
  2933. //T $eventdata->fullmessage = "Teste de Mensagem...";
  2934. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  2935. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  2936. //T $eventdata->smallmessage = "Teste de Mensagem";
  2937. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  2938. //T // alteracao tulio faria
  2939. //T //message_send($eventdata);
  2940. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  2941. // Trigger module viewed event.
  2942. $event = \mod_iassign\event\submission_comment_created::create(array(
  2943. 'objectid' => $this->iassign->id,
  2944. 'context' => $this->context
  2945. ));
  2946. $event->add_record_snapshot('course', $this->course);
  2947. $event->trigger();
  2948. }
  2949. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  2950. // if ($this->action=='viewsubmission') {
  2951. // echo $OUTPUT->header();
  2952. // $this->return_last('confirm_add_comment', $link_return);
  2953. // die;
  2954. // }
  2955. return true;
  2956. } // function write_comment_submission()
  2957. /// Writes a new submission
  2958. // The first student answer is under 'function get_answer()'
  2959. function new_submission ($iassignid, $id_user, $receiver) {
  2960. global $USER, $DB, $OUTPUT;
  2961. $newentry = new stdClass();
  2962. $newentry->iassign_statementid = $iassignid;
  2963. $newentry->userid = $id_user;
  2964. $newentry->timecreated = time();
  2965. $newentry->timemodified = time();
  2966. $newentry->answer = 0; // student only submit message
  2967. if ($receiver == 2) // teacher message to student (write id teacher)
  2968. $newentry->teacher = $USER->id;
  2969. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  2970. return_home_course('error_insert_submissions');
  2971. else {
  2972. // Trigger module view event
  2973. $event = \mod_iassign\event\submission_created::create(array(
  2974. 'objectid' => $this->iassign->id,
  2975. 'context' => $this->context
  2976. ));
  2977. $event->add_record_snapshot('course', $this->course);
  2978. $event->trigger();
  2979. }
  2980. return $newentry->id;
  2981. }
  2982. /// Return to a specific address of page
  2983. function return_last ($message, $link_return) {
  2984. global $DB, $OUTPUT;
  2985. print $OUTPUT->box_start();
  2986. print '<table width=100% border=0 valign="top">' . "\n";
  2987. print '<tr><td align="left"><strong>' . "\n";
  2988. print_string($message, 'iassign');
  2989. print '</strong></td>' . "\n";
  2990. print '<td width=20% align="right">' . "\n";
  2991. print $link_return;
  2992. print '</td></tr></table>' . "\n";
  2993. print $OUTPUT->box_end();
  2994. print $OUTPUT->footer();
  2995. die();
  2996. } // function return_last($message, $link_return)
  2997. } // class iassign
  2998. /// Class for manage activities
  2999. class activity {
  3000. var $activity;
  3001. /// Constructor of class.
  3002. // @param int $id Id of activity
  3003. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3004. //D public function activity($id) { self::__construct($id); }
  3005. function __construct ($id) {
  3006. global $DB;
  3007. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3008. if (empty($this->activity))
  3009. $this->activity = null;
  3010. }
  3011. /// Get an activity
  3012. // @return NULL
  3013. function get_activity () {
  3014. if ($this->activity != null)
  3015. return $this->activity;
  3016. else
  3017. return null;
  3018. }
  3019. /// Delete interactive activities
  3020. function delete ($return) {
  3021. global $USER, $CFG, $DB, $OUTPUT;
  3022. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3023. $output = $OUTPUT->header();
  3024. $output .= $OUTPUT->box_start();
  3025. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3026. if ($iassign_submission_currents) {
  3027. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3028. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3029. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3030. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3031. $output .= $OUTPUT->box_end();
  3032. $output .= $OUTPUT->footer();
  3033. print $output;
  3034. die();
  3035. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3036. } // if ($iassign_submission_currents)
  3037. else
  3038. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3039. $output .= '<table width=50% border=0>';
  3040. $output .= '<tr valign="top"><td>';
  3041. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3042. $output .= '</td><td>';
  3043. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3044. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3045. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3046. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3047. $output .= "</form>\n";
  3048. $output .= '</td><td>';
  3049. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3050. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3051. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3052. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3053. $output .= "</form>\n";
  3054. $output .= '</td></tr></table>' . "\n";
  3055. $output .= $OUTPUT->box_end();
  3056. $output .= $OUTPUT->footer();
  3057. print $output;
  3058. } // function delete($return)
  3059. /// Function for confirm the delete of activity
  3060. // @param String $return Url of return
  3061. // @param Object $iassign Object content an activity
  3062. function deleteyes ($return, $iassign) {
  3063. global $USER, $CFG, $DB, $OUTPUT;
  3064. $msg = '';
  3065. if (!empty($this->activity->id)) {
  3066. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3067. if ($iassign_submission_currents) {
  3068. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3069. foreach ($iassign_submission_currents as $iassign_submission)
  3070. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3071. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3072. } // if ($iassign_submission_currents)
  3073. }
  3074. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3075. $this->delete_calendar($this->activity->id);
  3076. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3077. iassign::update_grade_iassign($this->activity->iassignid);
  3078. if ($delete_iassign_current) {
  3079. $iassign->return_home_course('confirm_delete_iassign');
  3080. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3081. } else {
  3082. $iassign->return_home_course('error_confirm_delete_iassign');
  3083. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3084. }
  3085. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3086. }
  3087. }
  3088. /// Changes position within of interactive group activity
  3089. function move_iassign ($target, $return) {
  3090. global $DB, $OUTPUT;
  3091. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target));
  3092. $aux = $this->activity->position;
  3093. $newentry = new stdClass();
  3094. $newentry->id = $this->activity->id;
  3095. $newentry->position = $iassign_target->position;
  3096. if (!$DB->update_record('iassign_statement', $newentry)) {
  3097. print_error('error_update_move_iassign', 'iassign');
  3098. }
  3099. $newentry->id = $iassign_target->id;
  3100. $newentry->position = $aux;
  3101. if (!$DB->update_record('iassign_statement', $newentry))
  3102. print_error('error_update_move_iassign', 'iassign');
  3103. redirect($return);
  3104. }
  3105. /// Enable or disable the display of interactive activities
  3106. function visible_iassign ($return) {
  3107. global $DB;
  3108. $newentry = new stdClass();
  3109. $newentry->id = $this->activity->id;
  3110. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3111. if (!$DB->update_record('iassign_statement', $newentry))
  3112. print_error('error_update_visible_iassign', 'iassign');
  3113. redirect($return);
  3114. }
  3115. /// Add news interactive activities (register in table 'iassign_statement')
  3116. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3117. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3118. function new_iassign ($param) {
  3119. global $DB;
  3120. $newentry = new stdClass();
  3121. $newentry->iassignid = $param->iassignid;
  3122. $newentry->name = $param->name;
  3123. $newentry->type_iassign = $param->type_iassign;
  3124. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3125. $proposition = $param->proposition;
  3126. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3127. else $proposition_text = $proposition;
  3128. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3129. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3130. //TODO Then get it directly from the form data $_POST!
  3131. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3132. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3133. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3134. $newentry->author_name = $param->author_name;
  3135. $newentry->author_modified_name = $param->author_modified_name;
  3136. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3137. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3138. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3139. $newentry->grade = $param->grade;
  3140. $newentry->timemodified = time();
  3141. $newentry->timecreated = time();
  3142. if ($param->type_iassign == 1) {
  3143. $newentry->timedue = 0;
  3144. $newentry->timeavailable = 0;
  3145. } // if ($param->type_iassign == 1)
  3146. else {
  3147. $newentry->timedue = $param->timedue;
  3148. $newentry->timeavailable = $param->timeavailable;
  3149. }
  3150. $newentry->preventlate = $param->preventlate;
  3151. $newentry->test = $param->test;
  3152. $newentry->special_param1 = $param->special_param1;
  3153. $newentry->visible = $param->visible;
  3154. $newentry->position = $param->position;
  3155. $newentry->max_experiment = $param->max_experiment;
  3156. $newentry->dependency = $param->dependency;
  3157. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3158. $newentry->show_answer = $param->show_answer;
  3159. $id = $DB->insert_record("iassign_statement", $newentry);
  3160. if ($id) {
  3161. $component = 'mod_iassign';
  3162. $filearea = 'exercise';
  3163. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3164. $file = $fs->get_file_by_id($param->file);
  3165. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3166. // File already inserted in other context!
  3167. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3168. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3169. $updateentry = new stdClass();
  3170. $updateentry->id = $id;
  3171. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3172. $updateentry->file = $newfile->get_itemid();
  3173. if (!$DB->update_record("iassign_statement", $updateentry))
  3174. print_error('error_add', 'iassign');
  3175. if ($param->type_iassign == 3)
  3176. iassign::update_grade_iassign($param->iassignid);
  3177. //TODO iLM_HTML5 :: //MOOC2014
  3178. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3179. //D if ($iassign_ilm_configs) {
  3180. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3181. //D if ($iassign_ilm_config->param_type != 'static') {
  3182. //D $newentry = new stdClass();
  3183. //D $newentry->iassign_statementid = $id;
  3184. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3185. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3186. //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});
  3187. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3188. //D print_error('error_add_param', 'iassign');
  3189. //D }
  3190. //D }
  3191. //D }
  3192. // log event --------------------------------------------------------------------------------------
  3193. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3194. // log event --------------------------------------------------------------------------------------
  3195. return $id;
  3196. }
  3197. else
  3198. print_error('error_add', 'iassign');
  3199. } // function new_iassign($param)
  3200. /// Add the calendar entries for this iassign
  3201. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3202. // @return bool
  3203. static function add_calendar ($iassignid) {
  3204. global $DB, $CFG;
  3205. require_once($CFG->dirroot . '/calendar/lib.php');
  3206. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3207. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3208. $event = new stdClass();
  3209. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3210. $event->description = $iassign_statement_activity_item->name;
  3211. $event->courseid = $iassign->course;
  3212. $event->groupid = 0;
  3213. $event->userid = 0;
  3214. $event->modulename = 'iassign';
  3215. $event->instance = $iassign->id;
  3216. $event->eventtype = 'due';
  3217. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3218. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3219. calendar_event::create($event);
  3220. }
  3221. /// Update the calendar entries for this iassign
  3222. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3223. // @return bool
  3224. function update_calendar ($iassignid, $olddescription) {
  3225. global $DB, $CFG;
  3226. require_once($CFG->dirroot . '/calendar/lib.php');
  3227. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3228. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3229. $event = new stdClass();
  3230. $event->id = 0;
  3231. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3232. if ($events) {
  3233. foreach ($events as $value) {
  3234. if ($value->description == $olddescription) {
  3235. $event->id = $value->id;
  3236. }
  3237. }
  3238. }
  3239. if ($event->id != 0) {
  3240. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3241. $event->description = $iassign_statement_activity_item->name;
  3242. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3243. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3244. $calendarevent = calendar_event::load($event->id);
  3245. $calendarevent->update($event);
  3246. } else
  3247. $this->add_calendar($iassignid);
  3248. }
  3249. /// Update the calendar entries for this iassign
  3250. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3251. // @return bool
  3252. function delete_calendar ($iassignid) {
  3253. global $DB, $CFG;
  3254. require_once($CFG->dirroot . '/calendar/lib.php');
  3255. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3256. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3257. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3258. if ($events) {
  3259. foreach ($events as $value) {
  3260. if ($value->description == $iassign_statement_activity_item->name) {
  3261. $DB->delete_records('event', array('id' => $value->id));
  3262. }
  3263. }
  3264. }
  3265. }
  3266. /// Update interactive activities
  3267. function update_iassign ($param) {
  3268. global $DB;
  3269. $component = 'mod_iassign';
  3270. $filearea = 'exercise';
  3271. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3272. $file = $fs->get_file_by_id($param->file);
  3273. $fileold = $fs->get_file_by_id($param->fileold);
  3274. if ($param->file != $param->fileold) {
  3275. if ($fileold) {
  3276. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3277. foreach ($fileoldarea as $value) {
  3278. $value->delete();
  3279. }
  3280. }
  3281. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3282. $itemid = $file->get_itemid() + $param->iassign_id;
  3283. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3284. $param->file = $newfile->get_itemid();
  3285. } else
  3286. $param->file = $file->get_itemid();
  3287. } else {
  3288. $param->file = $file->get_itemid();
  3289. }
  3290. $newentry = new stdClass();
  3291. $newentry->id = $param->iassign_id;
  3292. $newentry->name = $param->name;
  3293. $newentry->type_iassign = $param->type_iassign;
  3294. //2019 $newentry->proposition = $param->proposition;
  3295. $proposition = $param->proposition;
  3296. if (is_array($proposition))
  3297. $proposition_text = $proposition['text'];
  3298. else
  3299. $proposition_text = $proposition;
  3300. $newentry->proposition = $proposition_text;
  3301. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3302. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3303. $newentry->grade = $param->grade;
  3304. $newentry->author_modified_name = $param->author_modified_name;
  3305. $newentry->timemodified = time();
  3306. if ($param->type_iassign == 1) {
  3307. $newentry->timedue = 0;
  3308. $newentry->timeavailable = 0;
  3309. } // if ($param->type_iassign == 1)
  3310. else {
  3311. $newentry->timedue = $param->timedue;
  3312. $newentry->timeavailable = $param->timeavailable;
  3313. }
  3314. $newentry->preventlate = $param->preventlate;
  3315. $newentry->test = $param->test;
  3316. $newentry->special_param1 = $param->special_param1;
  3317. $newentry->visible = $param->visible;
  3318. $newentry->max_experiment = $param->max_experiment;
  3319. $newentry->dependency = $param->dependency;
  3320. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3321. $newentry->show_answer = $param->show_answer;
  3322. if (!$DB->update_record("iassign_statement", $newentry))
  3323. print_error('error_update', 'iassign');
  3324. if ($param->type_iassign == 3) {
  3325. iassign::update_grade_iassign($param->iassignid);
  3326. }
  3327. //$id = $newentry->id; // MOOC 2016 --- inicio
  3328. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3329. //if ($iassign_activity_item_configs) {
  3330. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3331. // $newentry = new stdClass();
  3332. // $newentry->id = $iassign_activity_item_config->id;
  3333. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3334. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3335. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3336. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3337. // print_error('error_edit_param', 'iassign');
  3338. // }
  3339. // } // MOOC 2016 --- final
  3340. // log event --------------------------------------------------------------------------------------
  3341. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3342. // log event --------------------------------------------------------------------------------------
  3343. return $newentry->id;
  3344. // if ($param->type_iassign==3)
  3345. // $this->update_grade_iassign($param->iassignid);
  3346. } // function update_iassign($param)
  3347. /// Show information of activity
  3348. function show_info_iassign () {
  3349. global $DB, $OUTPUT;
  3350. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3351. if ($this->activity->type_iassign == 3) {
  3352. if ($this->activity->dependency == 0) {
  3353. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3354. } else {
  3355. $dependencys = explode(';', $this->activity->dependency);
  3356. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3357. foreach ($dependencys as $dependency) {
  3358. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3359. if ($dependencyiassign)
  3360. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3361. } // foreach ($dependencys as $dependency)
  3362. } // if ($iassign_statement_activity_item->dependency == 0)
  3363. if ($this->activity->max_experiment == 0)
  3364. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3365. else
  3366. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3367. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3368. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3369. print $OUTPUT->box($output);
  3370. } // function show_info_iassign()
  3371. /// Shows date of opening and closing activities
  3372. function view_dates () {
  3373. global $USER, $CFG, $DB, $OUTPUT;
  3374. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3375. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3376. $status_iassign = "";
  3377. $status_iassign1 = "";
  3378. $status_iassign2 = "";
  3379. if ($this->activity->type_iassign == 1) // activity of type example
  3380. $type_iassign = get_string('example_iassign', 'iassign');
  3381. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3382. $type_iassign = get_string('test_iassign', 'iassign');
  3383. if ($this->activity->timeavailable > time()) {
  3384. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3385. } elseif ($this->activity->timedue < time()) {
  3386. $status_iassign = get_string('last_timedue', 'iassign');
  3387. }
  3388. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3389. $type_iassign = get_string('exercise_iassign', 'iassign');
  3390. if ($this->activity->timeavailable > time()) {
  3391. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3392. } elseif ($this->activity->timedue < time()) { // after delivery
  3393. $status_iassign = get_string('last_timedue', 'iassign');
  3394. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3395. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3396. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3397. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3398. if ($this->activity->test == 1) // allowed to test after of deadline
  3399. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3400. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3401. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3402. } // elseif ($iassign_statement_activity_item->test == 0)
  3403. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3404. } // elseif ($iassign_statement_activity_item->timedue < time())
  3405. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3406. $output = '<table width=100% >' . "\n";
  3407. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3408. $output .= '<tr>' . "\n";
  3409. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3410. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3411. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3412. // leo $output .= '<td width=80%>' . $type_iassign;
  3413. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3414. // $output .= '</td>' . "\n";
  3415. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3416. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3417. $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>";
  3418. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3419. } else {
  3420. $link_next = "";
  3421. $link_previous = "";
  3422. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3423. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3424. // previous_activity
  3425. if ($iassign_previous) {
  3426. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3427. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3428. } // next_activity
  3429. if ($iassign_next) {
  3430. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3431. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3432. }
  3433. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3434. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3435. $output .= '</tr></table>' . "\n";
  3436. $output .= '<table width=100% >' . "\n";
  3437. if ($this->activity->type_iassign > 1) {
  3438. if ($this->activity->timeavailable)
  3439. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3440. if ($this->activity->timedue)
  3441. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3442. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3443. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3444. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3445. $output .= '</table>' . "\n";
  3446. print $OUTPUT->box($output);
  3447. } // function view_dates()
  3448. } // class activity
  3449. /// Class to manage Interactive Learning Module (iLM)
  3450. class ilm {
  3451. var $ilm;
  3452. /// Constructor of class
  3453. // @param int $id Id of iLM
  3454. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3455. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3456. function __construct ($id) {
  3457. global $DB;
  3458. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3459. if (empty($this->ilm))
  3460. $this->ilm = null;
  3461. }
  3462. /// Shows activity in iLM
  3463. // @calledby view_iassign_current()
  3464. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3465. global $USER, $CFG, $DB;
  3466. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3467. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3468. $typec = strtolower($iassign_ilm->type);
  3469. require_once 'ilm_handlers/' . $typec . '.php';
  3470. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3471. return $retorno;
  3472. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3473. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3474. // @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);
  3475. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3476. // @param Object $file File in use in activity
  3477. // @return int Return the id of log
  3478. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3479. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3480. $newentry = new stdClass();
  3481. $newentry->iassign_statementid = $iassign_activity_itemid;
  3482. $newentry->userid = $USER->id;
  3483. $newentry->file = $content_or_id_from_ilm_security;
  3484. $newentry->timecreated = time();
  3485. $newentry->view = 1;
  3486. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3487. if (!$id_iLM_security) {
  3488. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3489. } // from (!$DB->insert_record("iassign_security", $newentry))
  3490. return $id_iLM_security;
  3491. }
  3492. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3493. // @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);
  3494. // @param int $userid
  3495. // @param int $iassign_activity_itemid Id of iassign statement
  3496. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3497. global $DB;
  3498. // 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")
  3499. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3500. }
  3501. } // class ilm
  3502. /// Class to manage settings of iLM.
  3503. class ilm_settings {
  3504. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  3505. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3506. // @param int $ilm_id Id of iLM
  3507. // @param array $options An array with options for create dynamic tag html APPLET
  3508. // @return string Return with a tag html APPLET created
  3509. static function build_ilm_tags ($ilm_id, $options = array()) {
  3510. global $DB;
  3511. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3512. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3513. $typec = strtolower($iassign_ilm->type);
  3514. require_once 'ilm_handlers/' . $typec . '.php';
  3515. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3516. return $retorno;
  3517. } // static function build_ilm_tags($ilm_id, $options = array())
  3518. /// Function for get modified date of iLM file
  3519. // @param string $file_jar String with Ids of iLM files
  3520. // @return string Return with the filenames and modified date
  3521. static function applet_filetime ($file_jar) {
  3522. $filetime = "";
  3523. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3524. $files_jar = explode(",", $file_jar);
  3525. foreach ($files_jar as $one_file) {
  3526. $file = $fs->get_file_by_id($one_file);
  3527. if ($file)
  3528. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3529. }
  3530. return $filetime;
  3531. }
  3532. /// Function for verify an default applet
  3533. // @param String $file_jar String containing an list de ids of applet files
  3534. // @return boolean Return true or fale if applet is default
  3535. static function applet_default ($file_jar) {
  3536. $is_default = true;
  3537. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3538. $files_jar = explode(",", $file_jar);
  3539. foreach ($files_jar as $one_file) {
  3540. $file = $fs->get_file_by_id($one_file);
  3541. if ($file)
  3542. $is_default &= ($file->get_itemid() == 0);
  3543. }
  3544. return $is_default;
  3545. }
  3546. /// Function for get form variables for add, edit, or copy iLM
  3547. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  3548. // @see settings_form.php
  3549. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  3550. // @param int $ilm_id Id of iLM
  3551. // @param string $action String with the action
  3552. // @return object Return an object with forms variables
  3553. static function add_edit_copy_ilm ($ilm_id, $action) {
  3554. global $USER, $DB, $CFG;
  3555. require_once('settings_form.php'); // put the form
  3556. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3557. $param = new stdClass();
  3558. $param->action = $action;
  3559. $param->ilm_id = $ilm_id;
  3560. $CFG->action_ilm = $action;
  3561. $CFG->ilm_id = $ilm_id;
  3562. if ($action == 'add') {
  3563. $param->title = get_string('add_ilm', 'iassign');
  3564. $param->name = "";
  3565. $param->version = "";
  3566. $param->url = "";
  3567. $param->description = "";
  3568. $param->extension = "";
  3569. $param->author = $USER->id;
  3570. $param->file_jar = "";
  3571. $param->file_jar_static = "";
  3572. $param->file_class = "";
  3573. $param->width = 800;
  3574. $param->height = 600;
  3575. $param->enable = 0; // 0 - hide / 1 - show
  3576. $param->timecreated = time();
  3577. $param->timemodified = time();
  3578. $param->evaluate = 0;
  3579. $param->parent = 0;
  3580. }
  3581. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  3582. if ($iassign_ilm) {
  3583. $description = json_decode($iassign_ilm->description);
  3584. $param->title = get_string('edit_ilm', 'iassign');
  3585. $param->id = $iassign_ilm->id;
  3586. $param->name_ilm = $iassign_ilm->name;
  3587. $param->name = $iassign_ilm->name;
  3588. $param->version = $iassign_ilm->version;
  3589. $param->ilm_type = $iassign_ilm->type;
  3590. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3591. $param->url = $iassign_ilm->url;
  3592. $param->description = $description->{current_language()};
  3593. $param->description_lang = $iassign_ilm->description;
  3594. $param->extension = $iassign_ilm->extension;
  3595. $param->author = $iassign_ilm->author;
  3596. $param->file_jar = $iassign_ilm->file_jar;
  3597. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  3598. $param->file_class = $iassign_ilm->file_class;
  3599. $param->width = $iassign_ilm->width;
  3600. $param->height = $iassign_ilm->height;
  3601. $param->enable = $iassign_ilm->enable;
  3602. $param->timecreated = $iassign_ilm->timecreated;
  3603. $param->timemodified = time();
  3604. $param->evaluate = $iassign_ilm->evaluate;
  3605. $param->parent = $iassign_ilm->parent;
  3606. }
  3607. }
  3608. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  3609. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  3610. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3611. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  3612. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  3613. // echo "Sem dados<br/>"; exit;
  3614. return;
  3615. }
  3616. $description = json_decode($iassign_ilm->description);
  3617. if ($iassign_ilm) {
  3618. if ($iassign_ilm->parent == 0)
  3619. $iassign_ilm->parent = $ilm_id;
  3620. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  3621. $param->title = get_string('new_version_ilm', 'iassign');
  3622. $param->name_ilm = $iassign_ilm->name;
  3623. $param->name = $iassign_ilm->name;
  3624. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  3625. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  3626. $param->version = $iassign_ilm->version; // do not erase field 'version'
  3627. $param->ilm_type = $iassign_ilm->type;
  3628. $param->url = $iassign_ilm->url;
  3629. $param->description = $description->{current_language()};
  3630. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  3631. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3632. $param->extension = $iassign_ilm->extension;
  3633. $param->author = $USER->id;
  3634. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  3635. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  3636. $param->file_jar_static = '';
  3637. $param->file_class = $iassign_ilm->file_class;
  3638. $param->width = $iassign_ilm->width;
  3639. $param->height = $iassign_ilm->height;
  3640. $param->enable = 0;
  3641. $param->timecreated = time();
  3642. $param->timemodified = time();
  3643. $param->evaluate = $iassign_ilm->evaluate;
  3644. $param->parent = $iassign_ilm->parent;
  3645. }
  3646. }
  3647. elseif ($action == 'copy') {
  3648. $description = json_decode($iassign_ilm->description);
  3649. if ($iassign_ilm) {
  3650. if ($iassign_ilm->parent == 0)
  3651. $iassign_ilm->parent = $ilm_id;
  3652. $param->title = get_string('copy_ilm', 'iassign');
  3653. $param->id = $iassign_ilm->id;
  3654. $param->name_ilm = $iassign_ilm->name;
  3655. $param->name = $iassign_ilm->name;
  3656. $param->version = "";
  3657. $param->ilm_type = $iassign_ilm->type;
  3658. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3659. $param->url = $iassign_ilm->url;
  3660. $param->description = $description->{current_language()};
  3661. $param->description_lang = $iassign_ilm->description;
  3662. $param->extension = $iassign_ilm->extension;
  3663. $param->author = $USER->id;
  3664. $param->file_jar = '';
  3665. $param->file_jar_static = '';
  3666. $param->file_class = $iassign_ilm->file_class;
  3667. $param->width = $iassign_ilm->width;
  3668. $param->height = $iassign_ilm->height;
  3669. $param->enable = 0;
  3670. $param->timecreated = time();
  3671. $param->timemodified = time();
  3672. $param->evaluate = $iassign_ilm->evaluate;
  3673. $param->parent = $iassign_ilm->parent;
  3674. }
  3675. }
  3676. return $param;
  3677. } // static function add_edit_copy_ilm($ilm_id, $action)
  3678. /// Function for save iLM file in moodledata
  3679. // @param int $itemid Itemid of file save in draft (upload file)
  3680. // @param int $ilm_id Id of iLM
  3681. // @return string Return an string with ids of iLM files
  3682. static function new_file_ilm ($itemid, $iassign_ilm) {
  3683. global $CFG, $USER, $DB;
  3684. $return = null;
  3685. $file_jar = array();
  3686. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3687. $contextuser = context_user::instance($USER->id);
  3688. $contextsystem = context_system::instance();
  3689. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  3690. if ($files_ilm) {
  3691. foreach ($files_ilm as $value) {
  3692. // CHECK IF file is HTML type
  3693. if ($iassign_ilm->type == 1) {
  3694. // Check if the file extension is ZIP
  3695. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  3696. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  3697. if ((strtolower($ext) == 'zip')) {
  3698. // Coping...:
  3699. $destination = 'ilm_debug/' . $value->get_filename();
  3700. $value->copy_content_to($destination);
  3701. // Extracting content...:
  3702. $zip = new ZipArchive();
  3703. $extracted = './ilm';
  3704. $dir = "";
  3705. if ($zip->open($destination) === TRUE) {
  3706. $dir = './ilm/' . trim($zip->getNameIndex(0));
  3707. if (is_dir($dir)) {
  3708. $i = 1;
  3709. $previous = str_replace("/", "", $zip->getNameIndex(0));
  3710. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  3711. $i ++;
  3712. }
  3713. $name = $previous . "_" . $i;
  3714. $dir = './ilm/' . $name . "/";
  3715. $j = 0;
  3716. while ($item_name = $zip->getNameIndex($j)) {
  3717. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  3718. $j++;
  3719. }
  3720. $zip->close();
  3721. }
  3722. $zip->open($destination);
  3723. $zip->extractTo($extracted);
  3724. $zip->close();
  3725. // After the extraction, remove it from DEBUG
  3726. unlink($destination);
  3727. } else { // Error trying to open destination...
  3728. // After the extraction error, also remove it from DEBUG
  3729. unlink($destination);
  3730. print_error('error_add_ilm_zip', 'iassign');
  3731. }
  3732. return $dir;
  3733. }
  3734. } // if ($iassign_ilm->type == 1)
  3735. if ($value->get_filename() != '.') {
  3736. $file_ilm = array(
  3737. 'userid' => $USER->id,
  3738. 'contextid' => $contextsystem->id,
  3739. 'component' => 'mod_iassign',
  3740. 'filearea' => 'ilm',
  3741. 'itemid' => rand(1, 999999999),
  3742. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  3743. 'filename' => $value->get_filename());
  3744. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  3745. array_push($file_jar, $file_ilm->get_id());
  3746. }
  3747. }
  3748. if (!empty($file_jar)) {
  3749. $return = implode(",", $file_jar);
  3750. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  3751. foreach ($old_file_jar as $value) {
  3752. $file = $fs->get_file_by_id($value);
  3753. if ($file)
  3754. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  3755. }
  3756. }
  3757. }
  3758. else // if ($files_ilm)
  3759. $return = $iassign_ilm->file_jar;
  3760. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  3761. return $return;
  3762. } // static function new_file_ilm($itemid, $iassign_ilm)
  3763. /// Function for save in database an new iLM
  3764. // @param object $param An object with iLM params
  3765. static function new_ilm ($itemid) {
  3766. global $CFG, $USER, $OUTPUT;
  3767. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3768. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3769. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3770. }
  3771. $pathtemp = $CFG->dataroot . '/temp/';
  3772. $contextuser = context_user::instance($USER->id);
  3773. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3774. $zip = new zip_packer();
  3775. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3776. foreach ($files as $file) {
  3777. if (!$file->is_directory())
  3778. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3779. }
  3780. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3781. // Verifica se o pacote possui o XML
  3782. if (!$application_xml) {
  3783. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3784. return;
  3785. } else {
  3786. $missing = "";
  3787. if (!isset($application_xml->name)) {
  3788. $missing .= "name";
  3789. }
  3790. if (!isset($application_xml->version)) {
  3791. $missing .= ", version";
  3792. }
  3793. if (!isset($application_xml->type)) {
  3794. $missing .= ", type";
  3795. }
  3796. if (!isset($application_xml->extension)) {
  3797. $missing .= ", extension";
  3798. }
  3799. if (!isset($application_xml->file_jar)) {
  3800. $missing .= ", file_jar";
  3801. }
  3802. if (!isset($application_xml->file_class)) {
  3803. $missing .= ", file_class";
  3804. }
  3805. if (!isset($application_xml->width)) {
  3806. $missing .= ", width";
  3807. }
  3808. if (!isset($application_xml->height)) {
  3809. $missing .= ", height";
  3810. }
  3811. if (!isset($application_xml->evaluate)) {
  3812. $missing .= ", evaluate";
  3813. }
  3814. if (strlen($missing) > 2) {
  3815. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3816. return;
  3817. }
  3818. }
  3819. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3820. $typec = strtolower($application_xml->type);
  3821. require_once 'ilm_handlers/' . $typec . '.php';
  3822. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3823. return $retorno;
  3824. } // static function new_ilm($itemid)
  3825. /// Function for save in database an iLM edit
  3826. // @param object $param An object with iLM params
  3827. static function edit_ilm ($param, $itemid) {
  3828. // Descobrir o tipo de iLM:
  3829. global $DB, $USER, $CFG;
  3830. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  3831. $pathtemp = $CFG->dataroot . '/temp/';
  3832. $contextuser = context_user::instance($USER->id);
  3833. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3834. $zip = new zip_packer();
  3835. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3836. $files_extract = null;
  3837. foreach ($files as $file) {
  3838. if (!$file->is_directory())
  3839. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3840. }
  3841. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  3842. $typec = strtolower($iassign_t->type);
  3843. require_once 'ilm_handlers/' . $typec . '.php';
  3844. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  3845. }
  3846. /// Function for register the new iLM (in database and in the directory)
  3847. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  3848. // @param object $param An object with iLM params
  3849. static function copy_new_version_ilm ($param) {
  3850. global $DB, $CFG, $USER;
  3851. $itemid = $param->file;
  3852. $pathtemp = $CFG->dataroot . '/temp/';
  3853. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3854. //D echo "pathtemp=$pathtemp<br/>";
  3855. $contextuser = context_user::instance($USER->id);
  3856. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3857. $zip = new zip_packer();
  3858. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3859. $files_extract = null;
  3860. foreach ($files as $file) {
  3861. if (!$file->is_directory())
  3862. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3863. }
  3864. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3865. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  3866. $typec = strtolower($iassign_t->type);
  3867. require_once 'ilm_handlers/' . $typec . '.php';
  3868. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  3869. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  3870. } // static function copy_new_version_ilm($param)
  3871. //VER::
  3872. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  3873. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  3874. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  3875. /// Function for change visibility of iLM
  3876. // @param int $ilm_id Id of iLM
  3877. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  3878. static function visible_ilm ($ilm_id, $status) {
  3879. global $DB;
  3880. if ($status == 0)
  3881. $visible = 1;
  3882. else
  3883. $visible = 0;
  3884. $newentry = new stdClass();
  3885. $newentry->id = $ilm_id;
  3886. $newentry->enable = $visible;
  3887. if (!$DB->update_record("iassign_ilm", $newentry))
  3888. error(get_string('error_edit_ilm', 'iassign'));
  3889. }
  3890. /// Function for confirm change default iLM
  3891. // @param int $ilm_id Id of iLM
  3892. // @param int $ilm_parent Id of parent iLM
  3893. // @return string Return with an string for create default page confirmation
  3894. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  3895. global $OUTPUT, $DB;
  3896. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3897. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3898. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3899. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  3900. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  3901. return $return;
  3902. }
  3903. /// Function for change the default iLM
  3904. // @see settings_ilm.php
  3905. // @param int $ilm_id Id of iLM
  3906. // @return int Return Id of default iLM
  3907. static function default_ilm ($ilm_id) {
  3908. global $DB;
  3909. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  3910. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  3911. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  3912. $iassign_ilm_default->id = $iassign_ilm->id;
  3913. $iassign_ilm_default->parent = 0;
  3914. $iassign_ilm->parent = $iassign_ilm_default->id;
  3915. $iassign_ilm->id = 0;
  3916. $iassign_ilm_default->enable = 1;
  3917. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  3918. print_error('error_edit_ilm', 'iassign');
  3919. }
  3920. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  3921. if (!$inserted) {
  3922. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  3923. print_error($msg_error);
  3924. //xx print_error('error_add_ilm', 'iassign');
  3925. }
  3926. return $iassign_ilm_default->id;
  3927. } // static function default_ilm ($ilm_id)
  3928. /// Function for confirm delete iLM
  3929. // @param int $ilm_id Id of iLM
  3930. // @param int $ilm_parent Id of parent iLM
  3931. // @return string Return with an string for create delete page confirmation
  3932. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  3933. global $OUTPUT, $DB;
  3934. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3935. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3936. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3937. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  3938. }
  3939. /// Function for delete directory where the iLM is allocated.
  3940. // @param string $dirPath
  3941. // @throws InvalidArgumentException
  3942. public static function delete_dir ($dirPath) {
  3943. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  3944. $dirPath .= '/';
  3945. }
  3946. $files = glob($dirPath . '*', GLOB_MARK);
  3947. foreach ($files as $file) {
  3948. if (is_dir($file)) {
  3949. ilm_settings::delete_dir($file);
  3950. } else {
  3951. unlink($file);
  3952. }
  3953. }
  3954. rmdir($dirPath);
  3955. }
  3956. /// Function for delete iLM
  3957. // @param int $ilm_id Id of iLM
  3958. // @return int Return Id of parent iLM
  3959. static function delete_ilm ($ilm_id) {
  3960. global $DB;
  3961. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3962. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3963. $typec = strtolower($iassign_ilm->type);
  3964. require_once 'ilm_handlers/' . $typec . '.php';
  3965. $retorno = $typec::delete_ilm($ilm_id);
  3966. return $retorno;
  3967. }
  3968. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  3969. // @param int $ilm_id Id of iLM
  3970. static function export_ilm ($ilm_id) {
  3971. global $DB;
  3972. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3973. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3974. $typec = strtolower($iassign_ilm->type);
  3975. require_once 'ilm_handlers/' . $typec . '.php';
  3976. $typec::export_ilm($ilm_id);
  3977. } // static function export_ilm($ilm_id)
  3978. //TODO iLM_HTML5 :: //MOOC 2016
  3979. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  3980. // @param int $ilm_id Id of iLM
  3981. static function export_update_ilm ($ilm_id) {
  3982. global $DB, $CFG;
  3983. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3984. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  3985. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  3986. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  3987. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  3988. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  3989. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  3990. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  3991. $upgrade_descriptor .= '</upgrade>' . "\n";
  3992. file_put_contents($xml_filename, $upgrade_descriptor);
  3993. header("Pragma: public");
  3994. header("Expires: 0");
  3995. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  3996. header("Cache-Control: private", false);
  3997. header('Content-Type: application/xml; charset=utf-8');
  3998. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  3999. header("Content-Length: " . @filesize($xml_filename));
  4000. set_time_limit(0);
  4001. @readfile("$xml_filename") || die("File not found.");
  4002. unlink($xml_filename);
  4003. exit;
  4004. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4005. /// Function for save iLM from XML descriptor
  4006. // @param array $application_xml Data of XML descriptor
  4007. // @param array $files_extract Filenames of extract files
  4008. // @return array Return an array content id of JAR files
  4009. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4010. global $CFG, $USER;
  4011. // Tratamento diferenciado se for do tipo HTML5:
  4012. $source = "";
  4013. $diretorio = "";
  4014. if (strtolower($application_xml->type) == 'html5') {
  4015. $i = 0;
  4016. foreach ($files_extract as $key => $value) {
  4017. $file = $CFG->dataroot . '/temp/' . $key;
  4018. // Verifica se já existe a pasta no diretório dos iLM:
  4019. if ($i == 0) {
  4020. $source = $file;
  4021. if (file_exists("ilm/" . basename($file))) {
  4022. $j = 1;
  4023. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4024. $j ++;
  4025. }
  4026. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4027. // mkdir($diretorio, 0777, true);
  4028. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4029. }
  4030. else {
  4031. $diretorio = 'ilm/' . basename($file);
  4032. // mkdir($diretorio, 0777, true);
  4033. mkdir($diretorio, 0755, true);
  4034. }
  4035. break;
  4036. }
  4037. $i ++;
  4038. }
  4039. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4040. if ($item->isDir()) {
  4041. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4042. }
  4043. else {
  4044. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4045. }
  4046. }
  4047. ilm_settings::delete_dir($source);
  4048. return "./" . $diretorio;
  4049. }
  4050. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4051. $file_jar = array();
  4052. $files_ilm = explode(",", $application_xml->file_jar);
  4053. $contextsystem = context_system::instance();
  4054. foreach ($files_ilm as $value) {
  4055. $file_ilm = array(
  4056. 'userid' => $USER->id,
  4057. 'contextid' => $contextsystem->id,
  4058. 'component' => 'mod_iassign',
  4059. 'filearea' => 'ilm',
  4060. 'itemid' => rand(1, 999999999),
  4061. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4062. 'filename' => $value);
  4063. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4064. array_push($file_jar, $file_ilm->get_id());
  4065. }
  4066. foreach ($files_extract as $key => $value) {
  4067. $file = $CFG->dataroot . '/temp/' . $key;
  4068. if (file_exists($file))
  4069. unlink($file);
  4070. }
  4071. return $file_jar;
  4072. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4073. /// Function for import the iLM from an package
  4074. // @param int $itemid Itemid of zip file
  4075. static function import_ilm ($itemid) {
  4076. global $CFG, $USER, $OUTPUT;
  4077. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4078. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4079. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4080. }
  4081. $pathtemp = $CFG->dataroot . '/temp/';
  4082. $contextuser = context_user::instance($USER->id);
  4083. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4084. $zip = new zip_packer();
  4085. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4086. foreach ($files as $file) {
  4087. if (!$file->is_directory())
  4088. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4089. }
  4090. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4091. // Verifica se o pacote possui o XML
  4092. if (!$application_xml) {
  4093. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4094. return;
  4095. } else {
  4096. $missing = "";
  4097. if (!isset($application_xml->name)) {
  4098. $missing .= "name";
  4099. }
  4100. if (!isset($application_xml->version)) {
  4101. $missing .= ", version";
  4102. }
  4103. if (!isset($application_xml->type)) {
  4104. $missing .= ", type";
  4105. }
  4106. if (!isset($application_xml->extension)) {
  4107. $missing .= ", extension";
  4108. }
  4109. if (!isset($application_xml->file_jar)) {
  4110. $missing .= ", file_jar";
  4111. }
  4112. if (!isset($application_xml->file_class)) {
  4113. $missing .= ", file_class";
  4114. }
  4115. if (!isset($application_xml->width)) {
  4116. $missing .= ", width";
  4117. }
  4118. if (!isset($application_xml->height)) {
  4119. $missing .= ", height";
  4120. }
  4121. if (!isset($application_xml->evaluate)) {
  4122. $missing .= ", evaluate";
  4123. }
  4124. if (strlen($missing) > 2) {
  4125. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4126. return;
  4127. }
  4128. }
  4129. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4130. $typec = strtolower($application_xml->type);
  4131. require_once 'ilm_handlers/' . $typec . '.php';
  4132. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4133. } // static function import_ilm($itemid)
  4134. /// Function for list iLM defaults
  4135. // @return string Return an string with a table of iLM
  4136. static function list_ilm () {
  4137. global $DB, $OUTPUT;
  4138. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4139. $str = '';
  4140. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4141. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4142. if ($iassign_ilm) {
  4143. foreach ($iassign_ilm as $ilm) {
  4144. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4145. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4146. $str .= '<tr><td>';
  4147. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4148. $str .= '<tr>';
  4149. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4150. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4151. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4152. $str .= '</tr>';
  4153. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4154. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4155. $str .= '</table>';
  4156. $str .= '</td></tr>';
  4157. }
  4158. }
  4159. $str .= '</table>';
  4160. return $str;
  4161. }
  4162. /// Function for download and install an upgrade of an iLM
  4163. // @param int $ilm_id Id of iLM
  4164. static function upgrade_ilm ($ilm_id) {
  4165. global $DB, $CFG, $USER;
  4166. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4167. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4168. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4169. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4170. if (!$result)
  4171. print_error('error_upgrade_ilm', 'iassign');
  4172. else {
  4173. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4174. $extension = explode(".", $zip_filename);
  4175. if ($extension[count($extension) - 1] != 'ipz') {
  4176. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4177. die;
  4178. }
  4179. $zip = new zip_packer();
  4180. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4181. $contextuser = context_user::instance($USER->id);
  4182. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4183. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4184. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4185. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4186. if (file_exists($zip_filename))
  4187. unlink($zip_filename);
  4188. if (empty($file_jar)) {
  4189. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4190. print_error($msg_error);
  4191. //xx print_error('error_add_ilm', 'iassign');
  4192. }
  4193. else {
  4194. $newentry = new stdClass();
  4195. $newentry->name = (String) $application_xml->name;
  4196. $newentry->version = (String) $application_xml->version;
  4197. $newentry->url = (String) $application_xml->url;
  4198. $newentry->description = $description_str;
  4199. $newentry->extension = strtolower((String) $application_xml->extension);
  4200. $newentry->file_jar = implode(",", $file_jar);
  4201. $newentry->file_class = (String) $application_xml->file_class;
  4202. $newentry->width = (String) $application_xml->width;
  4203. $newentry->height = (String) $application_xml->height;
  4204. $newentry->enable = 0;
  4205. $newentry->timemodified = time();
  4206. $newentry->author = $USER->id;
  4207. $newentry->timecreated = time();
  4208. $newentry->evaluate = (String) $application_xml->evaluate;
  4209. $newentry->parent = $ilm_id;
  4210. }
  4211. }
  4212. return $iassign_ilm->id;
  4213. } // static function upgrade_ilm($ilm_id)
  4214. //MOOC2014 -- inicio
  4215. //TODO: REVIEW
  4216. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4217. // static function move_iassign($ilm_id)
  4218. //MOOC2014 -- final
  4219. /// Function for list iLM versions with all informations
  4220. // @return string Return an string with a table of iLM
  4221. static function view_ilm ($ilmid, $from) {
  4222. global $DB;
  4223. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4224. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4225. $typec = strtolower($iassign_ilm->type);
  4226. require_once 'ilm_handlers/' . $typec . '.php';
  4227. $retorno = $typec::view_ilm($ilmid, $from);
  4228. return $retorno;
  4229. }
  4230. /// Function for get form variables for add, edit, or copy iLM params
  4231. // @param int $ilm_param_id Id of iLM param
  4232. // @param string $action String with the action
  4233. // @return object Return an object with forms variables
  4234. static function add_edit_copy_param ($ilm_param_id, $action) {
  4235. global $DB;
  4236. require_once('params_form.php');
  4237. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4238. $param = new stdClass();
  4239. $param->action = $action;
  4240. $param->ilm_param_id = $ilm_param_id;
  4241. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4242. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4243. $type = $iassign_ilm_config->param_type;
  4244. if ($action == 'add') {
  4245. $param->title = get_string('add_ilm', 'iassign');
  4246. $param->iassign_ilmid = $ilm_param_id;
  4247. $param->param_name = "";
  4248. $param->param_value = "";
  4249. $param->description = "";
  4250. $param->visible = 1;
  4251. }
  4252. elseif ($action == 'edit') {
  4253. if ($iassign_ilm_config) {
  4254. $param->title = get_string('edit_ilm', 'iassign');
  4255. $param->id = $iassign_ilm_config->id;
  4256. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4257. $param->param_type = $type; //MOOC2014
  4258. $param->param_name = $iassign_ilm_config->param_name;
  4259. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4260. $param->param_value = $iassign_ilm_config->param_value;
  4261. else //MOOC2014
  4262. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4263. $param->param_value = $iassign_ilm_config->param_value;
  4264. $param->description = $iassign_ilm_config->description;
  4265. $param->visible = $iassign_ilm_config->visible;
  4266. }
  4267. }
  4268. elseif ($action == 'copy') {
  4269. if ($iassign_ilm_config) {
  4270. $param->title = get_string('copy_ilm', 'iassign');
  4271. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4272. $param->param_type = $type; //MOOC2014
  4273. $param->param_name = $iassign_ilm_config->param_name;
  4274. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4275. $param->param_value = $iassign_ilm_config->param_value;
  4276. else //MOOC2014
  4277. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4278. $param->description = $iassign_ilm_config->description;
  4279. $param->visible = $iassign_ilm_config->visible;
  4280. }
  4281. }
  4282. return $param;
  4283. } // static function add_edit_copy_param($ilm_param_id, $action)
  4284. /// Function for change visibility of iLM param
  4285. // @param int $ilm_param_id Id of iLM param
  4286. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4287. static function visible_param ($ilm_param_id, $status) {
  4288. global $DB, $CFG;
  4289. if ($status == 0)
  4290. $visible = 1;
  4291. else
  4292. $visible = 0;
  4293. $newentry = new stdClass();
  4294. $newentry->id = $ilm_param_id;
  4295. $newentry->visible = $visible;
  4296. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4297. error(get_string('error_edit_param', 'iassign'));
  4298. }
  4299. /// Function for save in database an new iLM param
  4300. // @param object $param An object with iLM params
  4301. static function add_param ($param) {
  4302. global $DB;
  4303. $newentry = new stdClass();
  4304. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4305. //MOOC2014 $newentry->param_name = $param->param_name;
  4306. $newentry->param_type = $param->param_type; //MOOC2014
  4307. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4308. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4309. $newentry->param_value = $param->param_value;
  4310. else //MOOC2014
  4311. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4312. $newentry->description = $param->description;
  4313. $newentry->visible = $param->visible;
  4314. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4315. if (!$newentry->id) {
  4316. print_error('error_add_param', 'iassign');
  4317. }
  4318. }
  4319. /// Function for save in database a iLM param edit
  4320. // @param object $param An object with iLM params
  4321. static function edit_param ($param) {
  4322. global $DB;
  4323. $updentry = new stdClass();
  4324. $updentry->id = $param->id;
  4325. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4326. $updentry->param_type = $param->param_type; //MOOC2014
  4327. // $updentry->param_name = $param->param_name;
  4328. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4329. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4330. $updentry->param_value = $param->param_value;
  4331. else //MOOC2014
  4332. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4333. $updentry->description = $param->description;
  4334. $updentry->visible = $param->visible;
  4335. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4336. error(get_string('error_edit_param', 'iassign'));
  4337. }
  4338. }
  4339. /// Function for save in database a iLM param copy
  4340. // @param object $param An object with iLM params
  4341. static function copy_param ($param) {
  4342. global $DB;
  4343. $newentry = new stdClass();
  4344. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4345. //$newentry->param_name = $param->param_name;
  4346. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4347. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4348. $newentry->param_value = $param->param_value;
  4349. else //MOOC2014
  4350. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4351. $newentry->description = $param->description;
  4352. $newentry->visible = $param->visible;
  4353. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4354. if (!$newentry->id) {
  4355. print_error('error_add_param', 'iassign');
  4356. }
  4357. }
  4358. /// Function for delete iLM param of database
  4359. // @param int $param_id Id of iLM param
  4360. static function delete_param ($param_id) {
  4361. global $DB;
  4362. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4363. print_error('error_delete_param', 'iassign');
  4364. }
  4365. }
  4366. } // class ilm_settings
  4367. /// Class for manage iLM files (editor).
  4368. class ilm_manager {
  4369. var $id; // course id
  4370. var $url;
  4371. var $from;
  4372. /// Constructor for the base ilm_manager class
  4373. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4374. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4375. function __construct ($id, $url, $from) {
  4376. $this->id = $id; // course id
  4377. $this->url = $url;
  4378. $this->from = $from;
  4379. }
  4380. /// Function to get iAssign content file in Moodle data (exercise)
  4381. // @calledby x function preview_ilm($iassign_ilm) :
  4382. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4383. function get_file_ilm () {
  4384. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4385. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4386. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4387. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4388. $md_file = $fs->get_file_by_id($fileid);
  4389. $ilm_content_file = $md_file->get_content();
  4390. return $ilm_content_file;
  4391. }
  4392. /// Function for creating a new file from the iLM online editor
  4393. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4394. function ilm_editor_new () {
  4395. global $CFG, $DB, $OUTPUT, $PAGE;
  4396. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4397. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4398. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4399. $context = context_course::instance($this->id);
  4400. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4401. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4402. if (!$iassign) {
  4403. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4404. die();
  4405. }
  4406. $temp = explode(",", $iassign->extension);
  4407. $extension = $temp[0]; // default extension for this iLM
  4408. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4409. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4410. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4411. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4412. if ($stringArchiveContent != NULL) {
  4413. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4414. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4415. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4416. $filename = optional_param('filename', NULL, PARAM_RAW);
  4417. //Leo $filename = iassign_utils::format_filename($filename); //
  4418. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4419. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4420. //2019/02 $arrayfilename = explode(".", $filename);
  4421. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4422. //2019/02 $count_dots = count($arrayfilename);
  4423. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4424. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4425. //2019/02 if ($last_name != $extension)
  4426. //2019/02 $filename = $filename . '.' . $extension;
  4427. //2019/02 }
  4428. //2019/02 else { // no extension...
  4429. //2019/02 $filename = $filename . '.' . $extension;
  4430. //2019/02 }
  4431. // Store the name of recent created file
  4432. $_SESSION['file_name'] = $filename;
  4433. //$this->write_file_iassign($string, $filename);
  4434. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4435. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4436. die();
  4437. }
  4438. else { // if ($stringArchiveContent != NULL)
  4439. // iLM On-line editor
  4440. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4441. $str_get_iLM = "window.frames.iLM";
  4442. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4443. }
  4444. else { // otherwise it is JAR named 'iLM'
  4445. $str_get_iLM = "document.iLM";
  4446. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4447. }
  4448. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4449. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4450. $files_array = '';
  4451. foreach ($files as $value) {
  4452. if ($value->get_filename() != ".")
  4453. $files_array .= "'" . $value->get_filename() . "',";
  4454. }
  4455. $files_array .= "''";
  4456. $file = null;
  4457. $ia_content = "";
  4458. $filename = "";
  4459. $error_files_exists = get_string('error_file_exists', 'iassign');
  4460. $output = "<script type='text/javascript'>
  4461. //<![CDATA[
  4462. //D alert('locallib.php: ilm_editor_new');
  4463. function submit_iLM_Answer () {
  4464. var docFormOnLineEditor = document.formEnvio;
  4465. var resposta_exerc = new Array(3);
  4466. var valor_resposta = new Array(3);
  4467. var sessao = new Array(3);
  4468. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4469. resposta_exerc[0] = doc_iLM.getAnswer();
  4470. valor_resposta[0] = doc_iLM.getEvaluation();
  4471. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4472. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4473. var files = new Array(" . $files_array . ");
  4474. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4475. if (docFormOnLineEditor.filename.value=='') {
  4476. // ERROR: the file name is empty
  4477. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4478. return false;
  4479. }
  4480. // }
  4481. for (i=0; i<files.length; i++) {
  4482. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4483. alert('" . $error_files_exists . "');
  4484. return false;
  4485. }
  4486. }
  4487. docFormOnLineEditor.submit();
  4488. return true;
  4489. }
  4490. //]]>
  4491. </script>\n";
  4492. $output .= "
  4493. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4494. $output .= $OUTPUT->box_start();
  4495. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4496. $output .= "
  4497. <table width='100%' cellpadding='20'>
  4498. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4499. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4500. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4501. </tr>
  4502. </table>\n";
  4503. $output .= $OUTPUT->box_end();
  4504. $output .= "<center>\n";
  4505. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4506. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4507. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4508. $output .= $output_ilm;
  4509. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4510. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4511. </center>
  4512. </form>\n";
  4513. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4514. $PAGE->navbar->add($title);
  4515. $PAGE->set_title($title);
  4516. $PAGE->set_heading($title); // insert title above the navigation bar
  4517. print $OUTPUT->header();
  4518. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4519. print $output;
  4520. print $OUTPUT->footer();
  4521. }
  4522. die();
  4523. } // function ilm_editor_new()
  4524. /// Function for editing an file in online editor
  4525. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  4526. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  4527. global $CFG, $DB, $OUTPUT, $PAGE;
  4528. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4529. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4530. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4531. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4532. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4533. // If iLM is not registered, error!
  4534. if (!$iassign) {
  4535. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  4536. die;
  4537. }
  4538. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  4539. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  4540. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  4541. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  4542. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4543. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4544. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  4545. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  4546. if ($stringArchiveContent != NULL) {
  4547. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  4548. die();
  4549. } else { // if ($stringArchiveContent != NULL)
  4550. $end_file = '';
  4551. if ($content_file) {
  4552. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  4553. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  4554. }
  4555. $temp = explode(",", $iassign->extension);
  4556. $extension = $temp[0]; // default extension for this iLM
  4557. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  4558. $str_get_iLM = "window.frames.iLM";
  4559. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4560. } else { // otherwise it is JAR named 'iLM'
  4561. $str_get_iLM = "document.iLM";
  4562. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4563. }
  4564. $output = "<script type='text/javascript'>
  4565. //<![CDATA[
  4566. function submit_iLM_Answer () {
  4567. var docFormEditor = document.formEnvio;
  4568. var activityAnswer; // to get activity answer (text)
  4569. var activityValue; // to get activity answer value (float)
  4570. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4571. //activityAnswer = doc_iLM.getAnswer();
  4572. //activityValue = doc_iLM.getEvaluation();
  4573. activityAnswer = " . $str_get_iLM . ".getAnswer();
  4574. activityValue = " . $str_get_iLM . ".getEvaluation();
  4575. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  4576. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  4577. docFormEditor.submit();
  4578. return true;
  4579. }
  4580. //]]>
  4581. </script>\n";
  4582. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4583. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  4584. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4585. // return true;
  4586. // }
  4587. $output .= "
  4588. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4589. $output .= $OUTPUT->box_start();
  4590. $output .= "
  4591. <table width='100%' cellpadding='20'>
  4592. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  4593. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  4594. <input type='hidden' name='filename' value='$filename'/></td>
  4595. <td>
  4596. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4597. </tr>
  4598. </table>\n";
  4599. $output .= $OUTPUT->box_end();
  4600. $output .= " <center>\n";
  4601. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  4602. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  4603. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  4604. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  4605. </center>
  4606. </form>\n";
  4607. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4608. $PAGE->navbar->add($title);
  4609. $PAGE->set_title($title);
  4610. $PAGE->set_heading($title); // insert title above the navigation bar
  4611. print $OUTPUT->header();
  4612. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4613. print $output;
  4614. print $OUTPUT->footer();
  4615. } // else if ($stringArchiveContent != NULL)
  4616. die();
  4617. } // function ilm_editor_update()
  4618. /// Function for write iAssign file in Moodle data (exercise)
  4619. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  4620. // @param string $stringArchiveContent Content of iassign file
  4621. // @param string $filename Filename of iassign file
  4622. function write_file_iassign ($stringArchiveContent, $filename) {
  4623. global $USER;
  4624. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4625. $context = context_course::instance($this->id);
  4626. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4627. $dirid = $this->get_dir_ilm('dirid');
  4628. $dir = $fs->get_file_by_id($dirid);
  4629. $fileinfo = array('contextid' => $context->id, // ID of course
  4630. 'component' => 'mod_iassign', // usually = table name
  4631. 'filearea' => 'activity', // usually = table name
  4632. 'itemid' => 0, // usually = ID of row in table
  4633. 'filepath' => $dir->get_filepath(), // any path beginning and ending whith '/'
  4634. 'userid' => $USER->id,
  4635. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4636. 'filename' => $filename); // any filename
  4637. // Create file containing text. '$stringArchiveContent'
  4638. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4639. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  4640. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  4641. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  4642. // 'Activité interactive enregistrée avec succès sous le nom:';
  4643. // 'Atividade interativa gravada com sucesso sob o nome:'
  4644. $output = "
  4645. <script type='text/javascript'>
  4646. //<![CDATA[
  4647. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  4648. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4649. //]]>
  4650. </script>";
  4651. print $output;
  4652. die();
  4653. }
  4654. /// Function for write iAssign file in Moodle data (exercise)
  4655. // @param string $stringArchiveContent Content of iassign file
  4656. // @param string $filename Filename of iassign file
  4657. // @param int $itemid Itemid of iassign file
  4658. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  4659. global $OUTPUT, $USER;
  4660. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4661. $context = context_course::instance($this->id);
  4662. $dirid = $this->get_dir_ilm('dirid');
  4663. if ($stringArchiveContent != (-1)) {
  4664. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4665. $file = $fs->get_file_by_id($fileid);
  4666. if (!$file) {
  4667. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  4668. die;
  4669. }
  4670. $fileinfo = array('contextid' => $context->id, // ID of context
  4671. 'component' => 'mod_iassign', // usually = table name
  4672. 'filearea' => 'activity', // usually = table name
  4673. 'itemid' => 0, // usually = ID of row in table
  4674. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  4675. 'userid' => $USER->id,
  4676. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4677. 'license' => 'allrightsreserved', // allrightsreserved
  4678. 'timecreated' => $file->get_timecreated(),
  4679. 'filename' => $file->get_filename()); // any filename
  4680. $file->delete();
  4681. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4682. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  4683. }
  4684. $output = "<script type='text/javascript'>
  4685. //<![CDATA[
  4686. alert('" . get_string('sucess_update', 'iassign') . "');\n
  4687. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4688. //]]>
  4689. </script>";
  4690. print $output;
  4691. die();
  4692. }
  4693. /// Function for create an tag for iAssign filter
  4694. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  4695. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4696. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  4697. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4698. // @param int $fileid Id of file
  4699. // @return string Return an string with an tag of iassign filter
  4700. function tag_ilm ($fileid) {
  4701. global $DB;
  4702. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4703. $width = '600';
  4704. $height = '400';
  4705. $file = $fs->get_file_by_id($fileid);
  4706. $filetype = explode(".", $file->get_filename());
  4707. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  4708. foreach ($iassign_ilm as $value) {
  4709. $extensions = explode(",", $value->extension);
  4710. if (in_array($filetype[1], $extensions)) {
  4711. $width = $value->width;
  4712. $height = $value->height;
  4713. }
  4714. }
  4715. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  4716. }
  4717. /// Function for delete iAssign file in Moodle data (exercise)
  4718. function delete_file_ilm () {
  4719. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4720. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4721. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  4722. $file = $fs->get_file_by_id($fileid);
  4723. if ($file)
  4724. $file->delete();
  4725. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4726. die();
  4727. }
  4728. /// Function for delete selected iAssign file in Moodle data (exercise)
  4729. function delete_selected_ilm () {
  4730. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4731. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4732. $context = context_course::instance($this->id);
  4733. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4734. $dirid = $this->get_dir_ilm('dirid');
  4735. foreach ($files_id as $file_id) {
  4736. $file = $fs->get_file_by_id($file_id);
  4737. if ($file) {
  4738. if (!$file->is_directory())
  4739. $file->delete();
  4740. else {
  4741. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4742. foreach ($files_delete as $value)
  4743. $value->delete();
  4744. $file->delete();
  4745. }
  4746. }
  4747. }
  4748. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4749. die();
  4750. }
  4751. /// Function for duplicate iAssign file from "online" edition
  4752. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  4753. function duplicate_file_ilm () {
  4754. global $USER, $COURSE;
  4755. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4756. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4757. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4758. $filename = optional_param('filename', NULL, PARAM_RAW);
  4759. $file = $fs->get_file_by_id($fileid);
  4760. $context = context_course::instance($this->id);
  4761. $fileinfo = array(
  4762. 'contextid' => $context->id, // ID of context
  4763. 'component' => 'mod_iassign', // usually = table name
  4764. 'filearea' => 'activity', // usually = table name
  4765. 'itemid' => 0, // usually = ID of row in table
  4766. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  4767. 'userid' => $USER->id,
  4768. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4769. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  4770. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  4771. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  4772. die();
  4773. }
  4774. /// Function for rename iAssign file
  4775. function rename_file_ilm () {
  4776. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4777. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4778. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4779. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4780. $file = $fs->get_file_by_id($fileid);
  4781. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  4782. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  4783. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4784. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  4785. die();
  4786. }
  4787. /// Function for get iassign file for iassign form
  4788. function add_ilm () {
  4789. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4790. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4791. $output = "
  4792. <script type='text/javascript'>
  4793. //<![CDATA[
  4794. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  4795. iassign_file_link.innerHTML = '$filename';
  4796. window.opener.document.forms['mform1'].file.value='$fileid';
  4797. window.opener.document.forms['mform1'].filename.value='$filename';
  4798. window.close();
  4799. //]]>
  4800. </script>";
  4801. print $output;
  4802. die();
  4803. }
  4804. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  4805. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  4806. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  4807. function preview_ilm ($courseid, $iassign_ilm) {
  4808. global $OUTPUT, $CFG, $USER;
  4809. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4810. $title = get_string('modulename', 'iassign'); // iAssign
  4811. print $OUTPUT->header();
  4812. print $OUTPUT->box_start();
  4813. $javascript = "
  4814. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  4815. <script type='text/javascript'>
  4816. //<![CDATA[
  4817. function submit_close () {
  4818. window.opener.location.reload();
  4819. window.close();
  4820. }
  4821. //]]>
  4822. </script>\n";
  4823. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  4824. // to the complete "applet" tag
  4825. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  4826. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  4827. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  4828. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  4829. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  4830. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  4831. if ($ilm_name != "ivprog") {
  4832. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  4833. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  4834. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  4835. } else {
  4836. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  4837. $content_or_id_from_ilm_security = $this->get_file_ilm();
  4838. $timecreated = time();
  4839. $token = md5($timecreated);
  4840. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  4841. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  4842. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  4843. $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)
  4844. }
  4845. $html = "
  4846. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4847. <table border='1'>
  4848. <tr><td>
  4849. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  4850. <!-- iLM calls : end -->
  4851. </td></tr>
  4852. </table>
  4853. <table>
  4854. <tr>
  4855. <td align='center'>
  4856. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  4857. </td></tr>
  4858. </table>
  4859. </form>\n";
  4860. print $javascript . $html;
  4861. print $OUTPUT->box_end();
  4862. //NAO echo format_string($html); // Moodle 3.X
  4863. die();
  4864. } // function preview_ilm($courseid, $iassign_ilm)
  4865. //r_ function preview_ilm ($iassign_ilm)
  4866. //r_ /// Function for preview iassign file from iassign filter.
  4867. //r_ function preview_ilm() {
  4868. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4869. //r_ $tag_filter = $this->tag_ilm($fileid);
  4870. //r_ $javascript = "<script type='text/javascript'>
  4871. //r_ //<![CDATA[
  4872. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  4873. //r_ //]]>
  4874. //r_ </script>";
  4875. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4876. //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>
  4877. //r_ </table></form></body></html>";
  4878. //r_ echo $javascript . format_text($html);
  4879. //r_ die;
  4880. //r_ }
  4881. /// Function for export an package (zip) of iassign files
  4882. function export_files_ilm () {
  4883. global $CFG;
  4884. $context = context_course::instance($this->id);
  4885. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4886. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  4887. $zip = new zip_archive();
  4888. $zip->open($zip_filename);
  4889. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4890. foreach ($files_id as $file_id) {
  4891. $file = $fs->get_file_by_id($file_id);
  4892. if (!$file->is_directory())
  4893. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  4894. else {
  4895. $zip->add_directory($file->get_filepath());
  4896. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4897. foreach ($files_zip as $value) {
  4898. if (!$value->is_directory())
  4899. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  4900. else
  4901. $zip->add_directory($value->get_filepath());
  4902. }
  4903. }
  4904. }
  4905. $zip->close();
  4906. header("Pragma: public");
  4907. header("Expires: 0");
  4908. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4909. header("Cache-Control: private", false);
  4910. header("Content-Type: application/zip");
  4911. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  4912. header("Content-Transfer-Encoding: binary");
  4913. header("Content-Length: " . @filesize($zip_filename));
  4914. set_time_limit(0);
  4915. @readfile("$zip_filename") || die("File not found.");
  4916. unlink($zip_filename);
  4917. exit;
  4918. }
  4919. /// Function of execute a command in button editor tinymce
  4920. // @param int $fileid Id of file
  4921. function tinymce_ilm ($fileid) {
  4922. $tag_filter = $this->tag_ilm($fileid);
  4923. $output = "<script type='text/javascript'>
  4924. //<![CDATA[
  4925. var tag_filter = '$tag_filter';
  4926. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  4927. // all right, insert it
  4928. } else {
  4929. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  4930. }
  4931. // window.close();
  4932. //]]>
  4933. </script>\n";
  4934. print $output;
  4935. die();
  4936. }
  4937. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  4938. /// Function to add content to the Editor Window
  4939. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  4940. // @param int $fileid Id of file
  4941. function editor_ilm ($fileid, $editor) {
  4942. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  4943. $output1 = "<script type='text/javascript'>
  4944. //<![CDATA[
  4945. var tag_filter = '$tag_filter';\n";
  4946. if ($editor == 'atto') {
  4947. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  4948. } elseif ($editor == 'tinyMCE') {
  4949. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  4950. } else
  4951. $output2 = "";
  4952. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  4953. window.close();
  4954. //]]>
  4955. </script>\n";
  4956. //D var_dump($output);
  4957. print $output1 . $output2 . $output3;
  4958. die();
  4959. }
  4960. /// Function to add content to the Atto Editor Window
  4961. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  4962. // @param int $fileid Id of file
  4963. function atto_ilm ($fileid) {
  4964. global $CFG, $DB;
  4965. $tag_filter = $this->tag_ilm($fileid);
  4966. $output = "<script type='text/javascript'>
  4967. //<![CDATA[
  4968. var tag_filter = '$tag_filter';
  4969. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  4970. // all right, insert iLM tag to this editor
  4971. } else {
  4972. // error trying to insert
  4973. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  4974. }
  4975. //window.close();
  4976. //]]>
  4977. </script>\n";
  4978. print $output;
  4979. die();
  4980. }
  4981. /// Function for get path and infos of dirs: dirid, dir_base, dir_parent, dir_home
  4982. // @param string $key Key for return information
  4983. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  4984. function get_dir_ilm ($key) {
  4985. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4986. $context = context_course::instance($this->id);
  4987. $dirid = optional_param('dirid', 0, PARAM_INT);
  4988. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  4989. if ($dirid == 0) {
  4990. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  4991. $dirid = $dir->get_id();
  4992. } else {
  4993. $dir = $fs->get_file_by_id($dirid);
  4994. $dir_base = $dir->get_filepath();
  4995. }
  4996. $dir_parent = $dir->get_parent_directory();
  4997. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  4998. return $data[$key];
  4999. }
  5000. /// Function for create an new dir
  5001. function new_dir_ilm () {
  5002. global $USER;
  5003. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5004. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5005. $dir_base = $this->get_dir_ilm('dir_base');
  5006. $context = context_course::instance($this->id);
  5007. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5008. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5009. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5010. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5011. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5012. }
  5013. /// Function for delete an dir
  5014. function delete_dir_ilm () { //
  5015. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5016. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5017. $context = context_course::instance($this->id);
  5018. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5019. $dir_parent = $this->get_dir_ilm('dir_parent');
  5020. if ($dir) {
  5021. if ($dir->is_directory()) {
  5022. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5023. foreach ($files_delete as $value)
  5024. $value->delete();
  5025. $dir->delete();
  5026. }
  5027. }
  5028. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5029. die();
  5030. }
  5031. /// Function for rename an dir
  5032. function rename_dir_ilm () {
  5033. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5034. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5035. $context = context_course::instance($this->id);
  5036. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5037. $dir_parent = $this->get_dir_ilm('dir_parent');
  5038. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5039. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5040. if ($dir->is_directory()) {
  5041. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5042. foreach ($files_rename_path as $value)
  5043. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5044. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5045. }
  5046. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5047. die();
  5048. }
  5049. /// Function for move an dir and your content for other dir
  5050. function selected_move_ilm () {
  5051. global $PAGE, $OUTPUT, $CFG;
  5052. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5053. $context = context_course::instance($this->id);
  5054. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5055. $dirid = $this->get_dir_ilm('dirid');
  5056. $dir_base = $this->get_dir_ilm('dir_base');
  5057. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5058. $code_javascript_ilm = "
  5059. <script type='text/javascript'>
  5060. //<![CDATA[
  5061. function getRadiobutton () {
  5062. var radioButtons = document.getElementsByTagName('input');
  5063. var param = '';
  5064. for (var counter=0; counter < radioButtons.length; counter++) {
  5065. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5066. param = radioButtons[counter].value;
  5067. }
  5068. return param;
  5069. }
  5070. function move_selected_ilm () {
  5071. var msgAnswer;
  5072. if (getRadiobutton() != '') {
  5073. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5074. if (msgAnswer)
  5075. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5076. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5077. }
  5078. else
  5079. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5080. }
  5081. function cancel_selected_ilm () {
  5082. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5083. }
  5084. //]]>
  5085. </script>\n";
  5086. $title = get_string('move_files', 'iassign');
  5087. $PAGE->set_title($title);
  5088. $PAGE->set_pagelayout('base');
  5089. print $OUTPUT->header();
  5090. print $OUTPUT->heading($title);
  5091. $dir_paths = array();
  5092. print $OUTPUT->box_start();
  5093. print "<center>";
  5094. foreach ($files_id as $file_id) {
  5095. $file = $fs->get_file_by_id($file_id);
  5096. if ($file) {
  5097. if (!$file->is_directory())
  5098. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5099. else {
  5100. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5101. array_push($dir_paths, $file->get_filepath());
  5102. }
  5103. }
  5104. }
  5105. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5106. if ($dir_base != '/') {
  5107. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5108. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5109. }
  5110. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5111. foreach ($files_tree as $file) {
  5112. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5113. $is_parent = false;
  5114. foreach ($dir_paths as $dir) {
  5115. $path = explode("/", $dir);
  5116. array_pop($path);
  5117. $path[count($path) - 1] = '';
  5118. $path = implode("/", $path);
  5119. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5120. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5121. }
  5122. if ($is_parent == false) {
  5123. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5124. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5125. }
  5126. }
  5127. }
  5128. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5129. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5130. print "</center>";
  5131. print $OUTPUT->box_end();
  5132. print $OUTPUT->footer();
  5133. print $code_javascript_ilm;
  5134. die;
  5135. }
  5136. /// Function for move files for an dir
  5137. function move_files_ilm () {
  5138. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5139. $context = context_course::instance($this->id);
  5140. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5141. $dirid = $this->get_dir_ilm('dirid');
  5142. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5143. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5144. foreach ($files_id as $file_id) {
  5145. $file = $fs->get_file_by_id($file_id);
  5146. if ($file) {
  5147. if ($file->is_directory()) {
  5148. $pathname = explode("/", $file->get_filepath());
  5149. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5150. foreach ($files_move_path as $value) {
  5151. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5152. $value->rename($path_move, $value->get_filename());
  5153. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5154. }
  5155. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5156. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5157. $file->rename($path_move, $file->get_filename());
  5158. } else {
  5159. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5160. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5161. }
  5162. }
  5163. }
  5164. //die;
  5165. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5166. die();
  5167. } // function move_files_ilm()
  5168. /// Function for recover files in use on all activities of a course
  5169. function recover_files_ilm () {
  5170. global $DB, $USER;
  5171. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5172. $courseid = optional_param('id', NULL, PARAM_INT);
  5173. $dirid = $this->get_dir_ilm('dirid');
  5174. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5175. $contextfile = context_course::instance($this->id);
  5176. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5177. foreach ($iassigns as $iassign) {
  5178. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5179. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5180. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5181. $context = context_module::instance($cm->id);
  5182. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5183. if ($files) {
  5184. foreach ($files as $value) {
  5185. $extension = explode(".", $value->get_filename());
  5186. if (!$value->is_directory()) {
  5187. $fileinfo = array('contextid' => $contextfile->id,
  5188. 'component' => 'mod_iassign',
  5189. 'filearea' => 'activity',
  5190. 'itemid' => 0,
  5191. 'filepath' => $this->get_dir_ilm('dir_base'),
  5192. 'userid' => $USER->id,
  5193. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5194. 'license' => 'allrightsreserved',
  5195. 'timecreated' => time(),
  5196. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5197. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5198. }
  5199. }
  5200. } // if ($files)
  5201. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5202. } // foreach ($iassigns as $iassign)
  5203. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5204. die();
  5205. } // function recover_files_ilm()
  5206. /// Auxiliary function the get all files in a given context
  5207. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5208. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5209. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5210. function get_files_in_context (&$allfiles, $contextid, $extension, $userid) {
  5211. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5212. // (NAO s_iassign_statement.file = s_files.id)
  5213. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5214. $dir_base = $this->get_dir_ilm('dir_base');
  5215. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5216. $countf = 0;
  5217. $array_files_id = array(); // all files from this context
  5218. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5219. //$filename = $item_fc->get_filename();
  5220. //$filepath = $item_fc->get_filepath();
  5221. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5222. //$fileuserid = $item_fc->get_userid(); // get user.id of the author
  5223. // $array_files_aux[] = $item_fc;
  5224. $itemid = $item_fc->get_id();
  5225. if (!in_array($itemid, $array_files_id)) {
  5226. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5227. $allfiles[] = $item_fc;
  5228. $array_files_id[] = $itemid;
  5229. $countf++;
  5230. }
  5231. }
  5232. return $countf;
  5233. }
  5234. /// List iassign files from course directory
  5235. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5236. function view_files_ilm ($iassign_ilm_class, $extension) {
  5237. global $CFG, $DB, $USER, $OUTPUT;
  5238. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5239. $context = context_course::instance($this->id); // $this->id = ID of the current course
  5240. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5241. $dirid = $this->get_dir_ilm('dirid');
  5242. $dir_base = $this->get_dir_ilm('dir_base');
  5243. // Get all files in module iAssign
  5244. // -- start
  5245. $array_all_files = array(); // all files from all context.id (in data decreasing order)
  5246. $array_contextid_files = array(); // context.id in data decreasing order
  5247. $array_contextid_files_aux = array(); // all context.id in data creasing order
  5248. // Get all files from table '*_files': id ; contenthash ; pathnamehash ; contextid ; component ;... filename ; userid ...
  5249. // $DB is 'mysqli_native_moodle_database' object
  5250. if (!has_capability("moodle/site:config", $context, $USER->id, true)) // *_capabilities="moodle/site:config" : greatest one
  5251. $array_query = array('component' => 'mod_iassign');
  5252. else
  5253. $array_query = array('component' => 'mod_iassign', 'userid' => $USER->id);
  5254. $files_iassign = $DB->get_records('files', $array_query); // extensions for all iLM...
  5255. $count_all_files = 0;
  5256. $count_files_with_ext = 0;
  5257. $count_thisauthor_contextid = 0;
  5258. $count_otherauthors_contextid = 0;
  5259. foreach ($files_iassign as $item_files_iassign) {
  5260. $extensionF = explode(".", $item_files_iassign->filename); // $item_files_iassign->get_filename()
  5261. $lastitem = sizeof($extensionF);
  5262. if ($lastitem>0) $lastitem--;
  5263. else // error: it must have extension (after ".")
  5264. continue;
  5265. $str_extension = $extensionF[$lastitem];
  5266. $count_files_with_ext++;
  5267. if ($extension == $str_extension) {
  5268. $contextid = $item_files_iassign->contextid;
  5269. if (!in_array($contextid, $array_contextid_files_aux)) { // not yet in array of context with this extension
  5270. $total_in_context = $this->get_files_in_context($array_all_files, $contextid, $extension, $USER->id); // $array_all_files by reference
  5271. $count_all_files += $total_in_context;
  5272. }
  5273. }
  5274. }
  5275. //TODO Deste modo vem: se ADMIN => todos os arquivos de extensao compativel; senao todos os arquivos do usuario
  5276. //TODO Implementar: se NAO ADMIN => pegar TODOS os arquivos do curso
  5277. //TODO Tabela pegar todos '*_files.contextid' tais que '*_files.component=="mod_iassign"'
  5278. $array_files_course = array();
  5279. for ($ii=$count_all_files-1; $ii>0; $ii--) {
  5280. //$contextid = $array_contextid_files[$ii];
  5281. //$files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5282. //$array_files_course[] = $files_course;
  5283. $files_course = $array_all_files[$ii];
  5284. $files_array = '';
  5285. $files_array .= "''";
  5286. $error_files_exists = get_string('error_file_exists', 'iassign');
  5287. $dirs_array = '';
  5288. foreach ($files_course as $one_file) {
  5289. if (!$one_file->is_directory())
  5290. $files_array .= "'" . $one_file->get_filename() . "',";
  5291. else { //if ($one_file->is_directory())
  5292. $pathname = explode("/", substr($one_file->get_filepath(), 0, strlen($one_file->get_filepath()) - 1));
  5293. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5294. }
  5295. } // foreach ($files_course as $one_file)
  5296. } // for ($ii=0; $ii<$num_contexts; $ii++)
  5297. print "#" . $count_all_files . "<br/>";
  5298. // -- end
  5299. $dirs_array .= "''";
  5300. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5301. //TODO Rever o 'preview' pois soh poder deixar ver uma vez
  5302. $code_javascript_ilm = "
  5303. <script type='text/javascript'>
  5304. //<![CDATA[
  5305. function preview_ilm (fileid, ilmid) { //JavaScript function
  5306. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5307. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5308. }
  5309. function update_ilm (ilmid, fileid) { //JavaScript function
  5310. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5311. }
  5312. function delete_ilm (ilmid, fileid) { //JavaScript function
  5313. var msgAnswer;
  5314. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5315. if (msgAnswer) {
  5316. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5317. }
  5318. }
  5319. function delete_selected_ilm () { //JavaScript function
  5320. var msgAnswer;
  5321. var param = getCheckbox();
  5322. if (param.join() != '') {
  5323. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5324. if (msgAnswer)
  5325. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5326. }
  5327. else
  5328. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5329. }
  5330. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5331. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5332. }
  5333. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5334. var filenamecopy;
  5335. var i;
  5336. var files = new Array($files_array);
  5337. do {
  5338. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5339. } while (filenamecopy == '');
  5340. if (filenamecopy == null)
  5341. return false;\n
  5342. else {
  5343. for (i=0;i<files.length;i++) {
  5344. if (files[i]==filenamecopy) {
  5345. alert('$error_files_exists');
  5346. return false;\n
  5347. }
  5348. }\n" .
  5349. // @see: function 'duplicate_file_ilm()' above
  5350. "
  5351. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5352. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5353. } // else
  5354. }
  5355. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5356. var filenamecopy;
  5357. var i;
  5358. var files = new Array($files_array);
  5359. do {
  5360. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5361. } while (filenamecopy == '');
  5362. if (filenamecopy == null)
  5363. return false;
  5364. else {
  5365. for (i=0;i<files.length;i++) {
  5366. if (files[i]==filenamecopy) {
  5367. alert('$error_files_exists');
  5368. return false;
  5369. }
  5370. }
  5371. 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;
  5372. }
  5373. }
  5374. function export_files_ilm () { //JavaScript function
  5375. var param = getCheckbox();
  5376. if (param.join() != '')
  5377. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5378. else
  5379. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5380. }
  5381. function select_all_ilm () { //JavaScript function
  5382. var checkBoxes = document.getElementsByTagName('input');
  5383. var selectAll = document.getElementById('select_all');
  5384. for (var counter=0; counter < checkBoxes.length; counter++) {
  5385. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5386. checkBoxes[counter].checked = selectAll.checked;
  5387. }
  5388. }
  5389. function getCheckbox () { //JavaScript function
  5390. var checkBoxes = document.getElementsByTagName('input');
  5391. var param = new Array();
  5392. for (var counter=0; counter < checkBoxes.length; counter++) {
  5393. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5394. param.push(checkBoxes[counter].value);
  5395. }
  5396. return param;
  5397. }
  5398. function new_dir_ilm () { //JavaScript function
  5399. var dirname = '';
  5400. var i;
  5401. var dirs = new Array($dirs_array);
  5402. do {
  5403. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5404. } while (dirname == '');
  5405. if (dirname == null)
  5406. return false;\n
  5407. else {
  5408. for (i=0;i<dirs.length;i++) {
  5409. if (dirs[i]==dirname) {
  5410. alert('$error_dir_exists');
  5411. return false;\n
  5412. }
  5413. }
  5414. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5415. }
  5416. }
  5417. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5418. var msgAnswer;
  5419. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5420. if (msgAnswer) {
  5421. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5422. }
  5423. }
  5424. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5425. var dirnamecopy;
  5426. var i;
  5427. var dirs = new Array($dirs_array);
  5428. do {
  5429. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5430. } while (dirnamecopy == '');
  5431. if (dirnamecopy == null)
  5432. return false;\n
  5433. else {
  5434. for (i=0;i<dirs.length;i++) {
  5435. if (dirs[i]==dirnamecopy) {
  5436. alert('$error_dir_exists');
  5437. return false;\n
  5438. }
  5439. }
  5440. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5441. }
  5442. }
  5443. function move_selected_ilm (ilmid) { //JavaScript function
  5444. var param = getCheckbox();
  5445. if (param.join() != '')
  5446. 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();
  5447. else
  5448. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5449. }
  5450. function recover_files_ilm () { //JavaScript function
  5451. var msgAnswer;
  5452. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5453. if (msgAnswer) {
  5454. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5455. }
  5456. }
  5457. window.onload = function() { //JavaScript function
  5458. var xPosition = 0;
  5459. var yPosition = 0;
  5460. element=document.getElementById('new_file');
  5461. while(element) {
  5462. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5463. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5464. element = element.offsetParent;
  5465. }
  5466. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5467. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5468. location.hash = '#new_file';
  5469. };
  5470. //]]>
  5471. </script>\n"; // end of $code_javascript_ilm
  5472. $output = "";
  5473. $select_all = "";
  5474. $count_files = 0;
  5475. $extensions_allow = array();
  5476. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  5477. foreach ($iassign_ilm as $item_iassign_ilm)
  5478. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  5479. //Estava foreach ($files_course as $one_file)
  5480. for ($ii=$count_all_files-1; $ii>0; $ii--) { // function view_files_ilm ($iassign_ilm_class, $extension)
  5481. //$contextid = $array_contextid_files[$ii]; // Notice: Undefined offset: 2257 in /var/www/html/saw/mod/iassign/locallib.php on line 6333
  5482. //$files_course = $array_files_course[$ii];
  5483. $one_file = $array_all_files[$ii];
  5484. $filename = $one_file->get_filename();
  5485. $filepath = $one_file->get_filepath();
  5486. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  5487. $pathname = $pathname[count($pathname) - 1];
  5488. $fileid = $one_file->get_id();
  5489. $tmp = explode(".", $filename);
  5490. if (is_array($tmp)) { // define file type
  5491. if (sizeof($tmp)>1)
  5492. $filetype = $tmp[1];
  5493. else
  5494. $filetype = $extension;
  5495. }
  5496. else
  5497. $filetype = $extension;
  5498. $author = $one_file->get_author();
  5499. $timemodified = date("d/m/Y H:i:s", $one_file->get_timemodified());
  5500. $timecreated = date("d/m/Y H:i:s", $one_file->get_timecreated());
  5501. $extensions = explode(",", $extension);
  5502. if (in_array(strtolower($filetype), $extensions) || $one_file->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  5503. $count_files ++;
  5504. // buscar fileid nas tabelas do iassign
  5505. $list_filein_use = "";
  5506. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5507. if ($iassign_statement_activity_list) {
  5508. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5509. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  5510. }
  5511. }
  5512. $array_iassign_ilm = $DB->get_records("iassign_ilm", array('extension' => $filetype, 'parent' => '0', 'enable' => '1'));
  5513. foreach ($array_iassign_ilm as $iassign_ilm) { // get files from all iLM equivalent
  5514. if (!$iassign_ilm) {
  5515. $iassign_ilm = new stdClass();
  5516. $iassign_ilm->id = $ilmid;
  5517. }
  5518. // Do not use $var inside "..." - problem with some "unusual" operational system
  5519. $url = $CFG->wwwroot . "/pluginfile.php/" . $one_file->get_contextid() . "/mod_iassign/activity";
  5520. $fileurl = $url . '/' . $one_file->get_itemid() . $filepath . $filename;
  5521. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  5522. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  5523. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5524. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5525. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5526. $check_select = "";
  5527. $link_rename = "";
  5528. $link_delete = "";
  5529. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5530. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5531. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5532. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  5533. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5534. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5535. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5536. if ($one_file->get_userid() == $USER->id) {
  5537. if ($iassign_statement_activity_list) {
  5538. $check_select = "";
  5539. $link_edit = iassign_icons::insert('edit_iassign_disable');
  5540. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  5541. $link_rename = "";
  5542. }
  5543. else {
  5544. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  5545. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  5546. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  5547. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  5548. }
  5549. } // if ($one_file->get_userid() == $USER->id)
  5550. if (!in_array($filetype, $extensions_allow)) {
  5551. $link_edit = "";
  5552. $link_add_ilm_iassign = "";
  5553. $link_add_ilm_tinymce = "";
  5554. $link_add_ilm_atto = "";
  5555. $link_filter = "";
  5556. }
  5557. if ($one_file->is_directory()) {
  5558. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  5559. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  5560. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  5561. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  5562. <td><center>$author</center></td>
  5563. <td><center>$timecreated</center></td>
  5564. <td><center>$timemodified</center></td></tr>\n";
  5565. }
  5566. else if ($this->from == 'iassign') {
  5567. $new_id = "";
  5568. $new_class = "";
  5569. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  5570. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  5571. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  5572. }
  5573. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  5574. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5575. <td><center>$author</center></td>
  5576. <td><center>$timecreated</center></td>
  5577. <td><center>$timemodified</center></td></tr>\n";
  5578. }
  5579. else if ($this->from == 'block') {
  5580. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  5581. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5582. <td><center>$author</center></td>
  5583. <td><center>$timecreated</center></td>
  5584. <td><center>$timemodified</center></td></tr>\n";
  5585. }
  5586. else if ($this->from == 'tinymce') {
  5587. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  5588. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5589. <td><center>$author</center></td>
  5590. <td><center>$timecreated</center></td>
  5591. <td><center>$timemodified</center></td></tr>\n";
  5592. }
  5593. else if ($this->from == 'atto') {
  5594. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  5595. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5596. <td><center>$author</center></td>
  5597. <td><center>$timecreated</center></td>
  5598. <td><center>$timemodified</center></td></tr>\n";
  5599. }
  5600. } // foreach ($array_iassign_ilm as $iassign_ilm)
  5601. } // if (in_array(strtolower($filetype), $extensions) || $one_file->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto')
  5602. } // for ($ii=$count_all_files-1; $ii>0; $ii--) // for ($ii=0; $ii<$num_contexts; $ii++)
  5603. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  5604. $dir_base = "";
  5605. $header = "";
  5606. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  5607. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  5608. foreach ($basename as $value) {
  5609. $dir_base .= $value . "/";
  5610. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  5611. if ($dir_id) {
  5612. if ($value == "") {
  5613. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5614. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  5615. } else {
  5616. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5617. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  5618. }
  5619. }
  5620. } // foreach ($basename as $value)
  5621. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  5622. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  5623. $html .= "
  5624. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  5625. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  5626. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  5627. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  5628. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  5629. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  5630. </table>\n";
  5631. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  5632. $html .= "<table width='100%'><tr>\n";
  5633. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  5634. if ($count_files != 0) {
  5635. $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";
  5636. $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";
  5637. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  5638. }
  5639. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  5640. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  5641. $html .= "</form>\n";
  5642. print $code_javascript_ilm;
  5643. print $html;
  5644. } // function view_files_ilm($extension)
  5645. } // class ilm_manager
  5646. /// Class to insert of icons
  5647. class iassign_icons {
  5648. static function insert ($icon) {
  5649. global $CFG;
  5650. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  5651. return $string;
  5652. }
  5653. }
  5654. /// Class with util functions for plugin manage
  5655. class iassign_utils {
  5656. /// Function to return the filename extension
  5657. // @param string The $filename as an string
  5658. // @return string Return an string (last group after '.')
  5659. static function filename_extension ($filename) {
  5660. if ($filename == null || $filename == '') {
  5661. return null;
  5662. }
  5663. $itens = explode('.', $filename);
  5664. $num = count($itens);
  5665. if ($num < 2) {
  5666. return null;
  5667. }
  5668. return $itens[$num - 1];
  5669. }
  5670. /// Use the PHP class/package ZipArchive to create a Zip file
  5671. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  5672. // 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
  5673. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  5674. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  5675. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  5676. $zip = new zip_archive(); //2
  5677. $res = $zip->open($full_path_zip_filename);
  5678. $total_vet = count($vet_student_filename);
  5679. for ($ii=0; $ii<$total_vet; $ii++) {
  5680. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  5681. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  5682. }
  5683. $ret = $zip->close();
  5684. iassign_utils::download_file($full_path_zip_filename);
  5685. $filenameZip = $zip->filename;
  5686. return array($ret, $zip);
  5687. }
  5688. static function download_file ($zip_filename) {
  5689. header("Pragma: public");
  5690. header("Expires: 0");
  5691. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5692. header("Cache-Control: private", false);
  5693. header("Content-Type: application/zip");
  5694. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5695. header("Content-Transfer-Encoding: binary");
  5696. header("Content-Length: " . @filesize($zip_filename));
  5697. set_time_limit(0);
  5698. @readfile("$zip_filename") || die("File not found.");
  5699. unlink($zip_filename);
  5700. }
  5701. /// Function for format filename remove special caracters
  5702. // @param string $text String for clean
  5703. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  5704. // @return string Return an string in clean format
  5705. static function format_filename ($text) {
  5706. if ($text != '.') {
  5707. //D $text = htmlspecialchars(urldecode($text));
  5708. //D echo "locallib.php: format_filename: $text<br/>";
  5709. if (is_object($text)) // with iAssign did not filtered text from JSON format
  5710. $text = json_decode($text)->{current_language()};
  5711. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  5712. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  5713. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  5714. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  5715. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  5716. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  5717. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  5718. // E.g. text = "exerc_midpoint.course.geo"
  5719. // 0123456789012345678901234
  5720. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  5721. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  5722. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  5723. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  5724. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  5725. //$ext = strrpos($text, ".");
  5726. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  5727. //$text = str_replace($array1, $array2, $text);
  5728. }
  5729. return $text;
  5730. }
  5731. /// Function to filter characters to the file name to iLM content
  5732. // @param string $text String for clean
  5733. // @param string $ext String ot the extension of the iLM
  5734. // @return string Return an string in clean format
  5735. static function filter_filename_extension ($filename, $ext) {
  5736. if ($filename != '.') {
  5737. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  5738. $arrTo = array("_","","","","","","","","","","","","");
  5739. $filename = str_replace($arrFrom, $arrTo, $filename);
  5740. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  5741. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  5742. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  5743. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  5744. $index_lastposition = strlen($filenameF);
  5745. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  5746. $text = str_replace(".", "_", $text); // erase all other "."
  5747. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  5748. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  5749. }
  5750. else
  5751. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  5752. return $filenameF;
  5753. }
  5754. /// Function for format pathname remove special caracters
  5755. // @param string $text String for clean
  5756. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5757. // @return string Return an string in clean format
  5758. static function format_pathname ($text, $is_lowercase = true) {
  5759. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5760. $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", "-", "_", "", "", "");
  5761. $text = str_replace($array1, $array2, $text);
  5762. if ($is_lowercase)
  5763. $text = strtolower($text);
  5764. return $text;
  5765. }
  5766. /// Function for format file name from iLM original name
  5767. // @param string $text String to build the file neam
  5768. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5769. // @return string Return an string in clean format
  5770. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  5771. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5772. $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", "-", "_", "", "", "");
  5773. $index_firstposition_blank = strpos($ilm_name, " ");
  5774. if ($index_firstposition_blank) { // truncate the name!
  5775. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  5776. }
  5777. $index_firstposition_dots = strpos($ilm_name, ":");
  5778. if ($index_firstposition_dots) { // truncate the name!
  5779. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  5780. }
  5781. $namefiltered = str_replace($array1, $array2, $ilm_name);
  5782. if ($is_lowercase)
  5783. $namefiltered = strtolower($namefiltered);
  5784. return $namefiltered;
  5785. }
  5786. /// Function for insert version in the filename
  5787. // @param string $filename Name of file
  5788. // @return string Return the filename with version
  5789. static function version_filename ($filename) {
  5790. $array_filename = explode('.', $filename);
  5791. if (count($array_filename) > 1)
  5792. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  5793. else
  5794. $filename = $array_filename[0] . '-' . date("Ymd-His");
  5795. return $filename;
  5796. }
  5797. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  5798. static function remove_code_message ($string) {
  5799. $array = explode("&lt;ia_uc&gt;", $string);
  5800. return $array[0];
  5801. }
  5802. }
  5803. // class iassign_utils
  5804. /// Class with language functions for plugin manage
  5805. class iassign_language {
  5806. /// Function for return text in language or get default language (en)
  5807. // @param string $lang Code of language
  5808. // @param string $description JSON text content all languages
  5809. // @return string Return an string in the language selected
  5810. static function get_description_lang ($lang, $descriptions) {
  5811. $description_lang = "";
  5812. $description = json_decode($descriptions);
  5813. if ($description == null) {
  5814. $description_lang = $descriptions;
  5815. }
  5816. else {
  5817. if (isset($description->{$lang}))
  5818. $description_lang = $description->{$lang};
  5819. else
  5820. if (isset($description->en)) //MOOC2014
  5821. $description_lang = $description->en;
  5822. else //MOOC2014
  5823. $description_lang = "en"; //MOOC2014
  5824. }
  5825. return $description_lang;
  5826. }
  5827. /// Function for return all language supported by iLM
  5828. // @param string $descriptions JSON text content all languages
  5829. // @return string Return as string with all languages
  5830. static function get_all_lang ($descriptions) {
  5831. $langs = "";
  5832. $description = json_decode($descriptions);
  5833. if ($description) {
  5834. foreach ($description as $key => $value) {
  5835. $langs .= $key . " ; ";
  5836. }
  5837. $langs = substr($langs, 0, strlen($langs) - 3);
  5838. }
  5839. return $langs;
  5840. }
  5841. /// Function for convert json in xml //MOOC2014
  5842. // @param string $json JSON text
  5843. // @return string Return as string with xml tags
  5844. static function json_to_xml ($json) {
  5845. $xml = "";
  5846. $json = json_decode($json);
  5847. foreach ($json as $key => $value) {
  5848. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  5849. }
  5850. return $xml;
  5851. }
  5852. }
  5853. // class iassign_language
  5854. /// Class with log functions for plugin manage.
  5855. class iassign_log {
  5856. /// Function for insert log event
  5857. // @param string $action Code action of event
  5858. // @param string $information Text for describe action of event
  5859. // @param int $cmid Id of context module
  5860. // @param int $ilmid Id of iLM
  5861. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  5862. global $COURSE, $CFG, $USER, $DB;
  5863. $newentry = new stdClass();
  5864. $newentry->time = time();
  5865. $newentry->userid = $USER->id;
  5866. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  5867. $newentry->course = $COURSE->id;
  5868. $newentry->cmid = $cmid;
  5869. $newentry->ilmid = $ilmid;
  5870. $newentry->action = $action;
  5871. $newentry->info = $information;
  5872. $newentry->language = current_language();
  5873. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  5874. if (ini_get("browscap") && function_exists('get_browse')) {
  5875. $browser = get_browse(null, true);
  5876. $newentry->javascript = $browser['javascript'];
  5877. $newentry->java = $browser['javaapplets'];
  5878. }
  5879. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  5880. print_error('error_add_log', 'iassign');
  5881. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  5882. } // class iassign_log