locallib.php 318 KB

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