locallib.php 331 KB

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